Skip to content

Commit

Permalink
Reinstate device editing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 7, 2015
1 parent ec27f48 commit a538ea7
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 21 deletions.
2 changes: 1 addition & 1 deletion API
Submodule API updated from 4c77d9 to eb69b8
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class DeviceInterface : public QObject
explicit DeviceInterface(const iscore::DeviceSettings& s);
const iscore::DeviceSettings& settings() const;

virtual void updateSettings(const iscore::DeviceSettings&) = 0;

// Asks, and returns all the new addresses if the device can refresh itself Minuit-like.
// The addresses are not applied to the device, they have to be via a command!
virtual bool canRefresh() const { return false; }
Expand All @@ -38,6 +40,6 @@ class DeviceInterface : public QObject
// In case the whole namespace changed?
void namespaceUpdated();

private:
protected:
iscore::DeviceSettings m_settings;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ UpdateDeviceSettings::UpdateDeviceSettings(
auto it = std::find_if(devplug.rootNode().begin(),
devplug.rootNode().end(),
[&] (const iscore::Node& n)
{ return n.get<AddressSettings>().name == name; });
{ return n.get<DeviceSettings>().name == name; });

ISCORE_ASSERT(it != devplug.rootNode().end());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,22 @@ void NodeUpdateProxy::loadDevice(const iscore::Node& node)

void NodeUpdateProxy::updateDevice(
const QString &name,
const iscore::DeviceSettings &dev)
const iscore::DeviceSettings& dev)
{
ISCORE_TODO;
m_devModel.list().device(name).updateSettings(dev);

if(m_deviceExplorer)
{
m_deviceExplorer->updateDevice(name, dev);
}
else
{
auto it = std::find_if(m_devModel.rootNode().begin(), m_devModel.rootNode().end(),
[&] (const iscore::Node& n) { return n.get<iscore::DeviceSettings>().name == name; });

ISCORE_ASSERT(it != m_devModel.rootNode().end());
it->set(dev);
}
}

void NodeUpdateProxy::removeDevice(const iscore::DeviceSettings& dev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ DeviceExplorerModel::getColumns() const
return HEADERS.values();
}

int DeviceExplorerModel::addDevice(Node* deviceNode)
int DeviceExplorerModel::addDevice(
Node* deviceNode)
{
int row = m_rootNode.childCount();
QModelIndex parent; //invalid
Expand All @@ -120,6 +121,28 @@ int DeviceExplorerModel::addDevice(Node* deviceNode)
return row;
}

void DeviceExplorerModel::updateDevice(
const QString& name,
const DeviceSettings& dev)
{
for(int i = 0; i < m_rootNode.childCount(); i++)
{
auto n = &m_rootNode.childAt(i);
if(n->get<iscore::DeviceSettings>().name == name)
{
QModelIndex index = createIndex(i, 0, n->parent());

QModelIndex changedTopLeft = index;
QModelIndex changedBottomRight = index;

n->set(dev);

emit dataChanged(changedTopLeft, changedBottomRight);
return;
}
}
}

Node* DeviceExplorerModel::addAddress(
Node* parentNode,
const iscore::AddressSettings &addressSettings)
Expand All @@ -144,7 +167,10 @@ Node* DeviceExplorerModel::addAddress(
return node;
}

void DeviceExplorerModel::addAddress(Node *parentNode, Node *node, int row)
void DeviceExplorerModel::addAddress(
Node *parentNode,
Node *node,
int row)
{
ISCORE_ASSERT(parentNode);
ISCORE_ASSERT(parentNode != &m_rootNode);
Expand All @@ -166,7 +192,9 @@ void DeviceExplorerModel::addAddress(Node *parentNode, Node *node, int row)
endInsertRows();
}

void DeviceExplorerModel::updateAddress(Node *node, const AddressSettings &addressSettings)
void DeviceExplorerModel::updateAddress(
Node *node,
const AddressSettings &addressSettings)
{
ISCORE_ASSERT(node);
ISCORE_ASSERT(node != &m_rootNode);
Expand All @@ -181,7 +209,8 @@ void DeviceExplorerModel::updateAddress(Node *node, const AddressSettings &addre
createIndex(nodeIndex.row(), HEADERS.count(), node->parent()));
}

void DeviceExplorerModel::removeNode(Node* node)
void DeviceExplorerModel::removeNode(
Node* node)
{
ISCORE_ASSERT(node);
ISCORE_ASSERT(node != &m_rootNode);
Expand All @@ -202,7 +231,8 @@ void DeviceExplorerModel::removeNode(Node* node)
delete node;
}

bool DeviceExplorerModel::checkDeviceInstantiatable(iscore::DeviceSettings& n)
bool DeviceExplorerModel::checkDeviceInstantiatable(
iscore::DeviceSettings& n)
{
// Request from the protocol factory the protocol to see
// if it is compatible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class DeviceExplorerModel : public QAbstractItemModel

// Returns the row (useful for undo)
int addDevice(iscore::Node* deviceNode);
void updateDevice(
const QString &name,
const iscore::DeviceSettings& dev);

iscore::Node* addAddress(
iscore::Node * parentNode,
const iscore::AddressSettings& addressSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ void DeviceExplorerWidget::edit()
iscore::Node* select = model()->nodeFromModelIndex(m_ntView->selectedIndex());
if (select->is<iscore::DeviceSettings>())
{
ISCORE_TODO;
return;
/*
if(! m_deviceDialog)
{
m_deviceDialog = new DeviceEditDialog(this);
Expand All @@ -435,12 +432,15 @@ void DeviceExplorerWidget::edit()

if(code == QDialog::Accepted)
{
auto deviceSettings = m_deviceDialog->getSettings();
select->setDeviceSettings(deviceSettings);
auto cmd = new DeviceExplorer::Command::UpdateDeviceSettings{
iscore::IDocument::path(model()->deviceModel()),
set.name,
m_deviceDialog->getSettings()};

m_cmdDispatcher->submitCommand(cmd);
}

updateActions();
*/
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ AddressEditDialog::AddressEditDialog(
QWidget* parent):
AddressEditDialog{makeDefaultSettings(), parent}
{
m_nameEdit->setEnabled(true);
}

AddressEditDialog::AddressEditDialog(
Expand All @@ -26,7 +25,6 @@ AddressEditDialog::AddressEditDialog(

// Name
m_nameEdit = new QLineEdit(this);
m_nameEdit->setEnabled(false); // TODO update when we can do it in the API
m_layout->addRow(tr("Name"), m_nameEdit);

setNodeSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ MIDIDevice::MIDIDevice(const iscore::DeviceSettings &settings):

m_dev = Device::create(parameters, settings.name.toStdString());
}


void MIDIDevice::updateSettings(const iscore::DeviceSettings&)
{
ISCORE_TODO;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class MIDIDevice : public OSSIADevice
public:
MIDIDevice(const iscore::DeviceSettings& settings);


void updateSettings(const iscore::DeviceSettings&) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ MinuitDevice::MinuitDevice(const iscore::DeviceSettings &settings):
m_dev = Device::create(m_minuitSettings, settings.name.toStdString());
}

void MinuitDevice::updateSettings(const iscore::DeviceSettings& settings)
{
m_settings = settings;
auto stgs = settings.deviceSpecificSettings.value<MinuitSpecificSettings>();

// TODO m_dev->setName(m_settings.name.toStdString());

auto prot = dynamic_cast<OSSIA::Minuit*>(m_dev->getProtocol().get());
prot->setInPort(stgs.inPort);
prot->setOutPort(stgs.outPort);
prot->setIp(stgs.host.toStdString());
}

bool MinuitDevice::canRefresh() const
{
return true;
Expand All @@ -38,7 +51,6 @@ iscore::Node MinuitDevice::refresh()
// First make the node corresponding to the root node.

device_node.set(settings());
//device_node.setAddressSettings(ToAddressSettings(*m_dev.get()));

// Recurse on the children
for(const auto& node : m_dev->children())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class MinuitDevice : public OSSIADevice
{
public:
MinuitDevice(const iscore::DeviceSettings& settings);

void updateSettings(const iscore::DeviceSettings&) override;

bool canRefresh() const override;
iscore::Node refresh() override; // throws std::runtime_error
iscore::Value refresh(const iscore::Address&) override;
Expand Down
19 changes: 18 additions & 1 deletion base/plugins/iscore-plugin-ossia/Protocols/OSC/OSCDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
#include "OSCDevice.hpp"
#include <API/Headers/Network/Protocol/OSC.h>
#include <API/Headers/Network/Device.h>

OSCDevice::OSCDevice(const iscore::DeviceSettings &stngs):
OSSIADevice{stngs}
{
using namespace OSSIA;

auto settings = stngs.deviceSpecificSettings.value<OSCSpecificSettings>();
auto oscDeviceParameter = OSSIA::OSC::create(settings.host.toStdString(), settings.inputPort, settings.outputPort);
auto oscDeviceParameter = OSSIA::OSC::create(
settings.host.toStdString(),
settings.inputPort,
settings.outputPort);
m_dev = OSSIA::Device::create(oscDeviceParameter, stngs.name.toStdString());
}

void OSCDevice::updateSettings(const iscore::DeviceSettings& settings)
{
m_settings = settings;
auto stgs = settings.deviceSpecificSettings.value<OSCSpecificSettings>();

m_dev->setName(m_settings.name.toStdString());

auto prot = dynamic_cast<OSSIA::OSC*>(m_dev->getProtocol().get());
prot->setInPort(stgs.inputPort);
prot->setOutPort(stgs.outputPort);
prot->setIp(stgs.host.toStdString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class OSCDevice : public OSSIADevice
{
public:
OSCDevice(const iscore::DeviceSettings& stngs);
void updateSettings(const iscore::DeviceSettings& settings) override;
};
3 changes: 3 additions & 0 deletions base/plugins/iscore-plugin-ossia/Protocols/OSSIADevice.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "OSSIADevice.hpp"
#include <QDebug>
#include <boost/range/algorithm.hpp>
#include <Network/Node.h>

#include "iscore2OSSIA.hpp"
#include "OSSIA2iscore.hpp"
using namespace iscore::convert;
using namespace OSSIA::convert;


void OSSIADevice::addAddress(const iscore::FullAddressSettings &settings)
{
using namespace OSSIA;
Expand All @@ -24,6 +26,7 @@ void OSSIADevice::updateAddress(const iscore::FullAddressSettings &settings)
using namespace OSSIA;

OSSIA::Node* node = getNodeFromPath(settings.address.path, m_dev.get());
node->setName(settings.address.path.last().toStdString());

if(settings.ioType == iscore::IOType::Invalid)
removeOSSIAAddress(node);
Expand Down

0 comments on commit a538ea7

Please sign in to comment.