Smart way to connect QML GUI objects to C++ audio processing chain?
-
Okay, I am wracked with indecision!
I'm building an audio synthesis application with a minimal "patcher" style interface, in the vein of languages like Max and Pd. A QML scroll area represents the C++ audio processing tree. Drag and drop QML items represent any single C++ audio processing unit in that tree.
Right now, when a QML audio unit is created in the patcher window by the user, the QML item calls a Q_INVOKE method on the C++ audio processing tree. The tree instantiates an equivalent C++ audio class and passes it a pointer to the QML item. The C++ instance is connected to its QML representation via signals and slots. For example:
//QML is created and invokes C++ method to //create equivalent audio processor, passes itself //for signal/slot connection function create() { created = true graph.createItem(this, type) } //C++ synthesis tree creates the proper instance and //sets the pointer to QML GUI item void SynthGraph::createItem(QObject* gui, int type) { switch (type){ case OSCILLATOR: { SynthItem* item = new Oscillator(); item->setMyGui(gui); break; } default: break; } } //C++ class connects signals and slot for communicating //to its GUI representation void SynthItem::connectGui() { QObject::connect(myGui, SIGNAL(destroyed(QObject*)), this, SLOT(requestDelete())); QObject::connect(myGui, SIGNAL(testSignal(QString)), this, SLOT(testSlot(QString))); }
But like I said, I'm freaking out! The more documentation I read, the more doubts I have. Is this sensible from a code readability and performance point of view? Should I be making the audio processing classes instantiable from QML instead? Embedding the C++ object into the corresponding QML item? Does it even matter how I do this!? :)