Hello again.
Forging ahead despite the inability to directly connect signals to
script functions within script code, attached is a patch that adds a
function called connectControl() to MidiScriptEngine to do this. It can
be called from script code to make and break connections with
ControlObject valueChanged() signals.
I will add info to the Wiki on how to use this shortly.
The only weird thing I've been seeing with this is the function causes a
segfault when called multiple times in rapid succession (for multiple
signals) while waveform down-sampling is occurring and occasionally
during normal playback. So take a look and see if I missed something, or
if this is another thing that will be fixed with the MIDI redesign.
Sincerely,
Sean M. Pappalardo
"D.J. Pegasus"
<<--------------------------------------------------------------------------------->>
This E-Mail message has been scanned for viruses
and cleared by >>SmartMail<< from Smarter Technology, Inc.
<<--------------------------------------------------------------------------------->>
Index: src/script/midiscriptengine.h
===================================================================
--- src/script/midiscriptengine.h (revision 2449)
+++ src/script/midiscriptengine.h (working copy)
@@ -44,6 +44,7 @@
Q_INVOKABLE double getValue(QString group, QString name);
Q_INVOKABLE void setValue(QString group, QString name, double newValue);
+ Q_INVOKABLE bool connectControl(QString group, QString name, QString
function, bool disconnect = false);
private:
QScriptEngine m_engine;
Index: src/script/midiscriptengine.cpp
===================================================================
--- src/script/midiscriptengine.cpp (revision 2449)
+++ src/script/midiscriptengine.cpp (working copy)
@@ -1,5 +1,5 @@
/***************************************************************************
- midiscriptengine.h - description
+ midiscriptengine.cpp - description
-------------------
begin : Fri Dec 12 2008
copyright : (C) 2008 by Sean M. Pappalardo
@@ -28,9 +28,9 @@
engineGlobalObject = m_engine.globalObject();
engineGlobalObject.setProperty("engine", m_engine.newQObject(this));
-// QObject *someObject = new MidiObject;
-// QScriptValue objectValue = m_engine.newQObject(someObject);
-// engineGlobalObject.setProperty("midi", objectValue);
+// ControlObject* m_cobj;
+// m_cobj = ControlObject::getControl(ConfigKey("[Channel1]","back"));
+// engineGlobalObject.setProperty("revers", m_engine.newQObject(m_cobj));
}
MidiScriptEngine::~MidiScriptEngine() {
@@ -48,7 +48,7 @@
// Read in the script file
QFile input(m_lastFilepath);
if (!input.open(QIODevice::ReadOnly)) {
- qWarning() << "MidiScriptEngine: Problem opening the script file: " <<
m_lastFilepath << ", error #" << input.error();
+ qCritical() << "MidiScriptEngine: Problem opening the script file: "
<< m_lastFilepath << ", error #" << input.error();
return false;
}
m_scriptCode.append(input.readAll());
@@ -84,7 +84,7 @@
-------- ------------------------------------------------------ */
void MidiScriptEngine::evaluateScript() {
if (!m_engine.canEvaluate(m_scriptCode)) {
- qWarning() << "MidiScriptEngine: ?Syntax error in script file:" <<
m_lastFilepath;
+ qCritical() << "MidiScriptEngine: ?Syntax error in script file:" <<
m_lastFilepath;
m_scriptCode.clear(); // Free up now-unneeded memory
m_scriptGood=false;
return;
@@ -103,7 +103,7 @@
-------- ------------------------------------------------------ */
QScriptValue MidiScriptEngine::execute(QString function) {
if (!m_engine.canEvaluate(function)) {
- qWarning() << "MidiScriptEngine: ?Syntax error in function " <<
function;
+ qCritical() << "MidiScriptEngine: ?Syntax error in function " <<
function;
return QScriptValue();
}
m_result = m_engine.evaluate(function);
@@ -120,8 +120,8 @@
bool MidiScriptEngine::checkException() {
if (m_engine.hasUncaughtException()) {
int line = m_engine.uncaughtExceptionLineNumber();
-// qDebug() << "MidiScriptEngine: uncaught exception" <<
m_engine.uncaughtException().toString() << "\nBacktrace:\n" <<
m_engine.uncaughtExceptionBacktrace();
- qDebug() << "MidiScriptEngine: uncaught exception" <<
m_engine.uncaughtException().toString() << "at line" << line;
+// qCritical() << "MidiScriptEngine: uncaught exception" <<
m_engine.uncaughtException().toString() << "\nBacktrace:\n" <<
m_engine.uncaughtExceptionBacktrace();
+ qCritical() << "MidiScriptEngine: uncaught exception" <<
m_engine.uncaughtException().toString() << "at line" << line;
return true;
}
return false;
@@ -198,7 +198,7 @@
double MidiScriptEngine::getValue(QString group, QString name) {
ControlObject *pot = ControlObject::getControl(ConfigKey(group, name));
if (pot == NULL) {
- qDebug("MidiScriptEngine: Unknown control %s:%s", group, name);
+ qDebug() << "MidiScriptEngine: Unknown control" << group << name;
return 0.0;
}
return pot->get();
@@ -213,3 +213,34 @@
ControlObject *pot = ControlObject::getControl(ConfigKey(group, name));
pot->queueFromThread(newValue);
}
+
+/* -------- ------------------------------------------------------
+ Purpose: (Dis)connects a ControlObject valueChanged() signal to/from a
script function
+ Input: Control group (e.g. [Channel1]), Key name (e.g. [filterHigh]),
+ script function name, true if you want to disconnect
+ Output: true if successful
+ -------- ------------------------------------------------------ */
+bool MidiScriptEngine::connectControl(QString group, QString name, QString
function, bool disconnect) {
+ ControlObject* m_cobj = ControlObject::getControl(ConfigKey(group,name));
+
+ QScriptValue slot = execute(function);
+ if (!checkException() && slot.isFunction()) { // If no problems,
+ // Do the deed
+ if (disconnect) {
+ qScriptDisconnect(m_cobj, SIGNAL(valueChanged(double)),
QScriptValue(), slot);
+ qScriptDisconnect(m_cobj, SIGNAL(valueChangedFromEngine(double)),
QScriptValue(), slot);
+ qDebug() << "MidiScriptEngine:" << group << name << "disconnected
from" << function;
+ }
+ else {
+ qScriptConnect(m_cobj, SIGNAL(valueChanged(double)),
QScriptValue(), slot);
+ qScriptConnect(m_cobj, SIGNAL(valueChangedFromEngine(double)),
QScriptValue(), slot);
+ qDebug() << "MidiScriptEngine:" << group << name << "connected to"
<< function;
+ }
+
+ return true;
+
+ } else {
+ qWarning() << "MidiScriptEngine:" << group << name << "didn't
connect/disconnect to/from" << function;
+ return false;
+ }
+}
\ No newline at end of file
Index: src/midiobject.cpp
===================================================================
--- src/midiobject.cpp (revision 2449)
+++ src/midiobject.cpp (working copy)
@@ -39,6 +39,7 @@
requestStop = false;
midiLearn = false;
debug = false;
+
#ifdef __SCRIPT__
m_pScriptEngine = new MidiScriptEngine();
m_pScriptEngine->engineGlobalObject.setProperty("midi",
m_pScriptEngine->getEngine()->newQObject(this));
@@ -55,10 +56,11 @@
// break;
// }
qDebug() << "MidiObject: Evaluating all script code";
+
m_pScriptEngine->evaluateScript();
if (!m_pScriptEngine->checkException() && m_pScriptEngine->isGood())
qDebug() << "MidiObject: Script code evaluated successfully";
-/* // Call script's init function if it exists - First need m_channel and
m_device in this object
+/* // Call script's init function if it exists - First need deviceChannel
and deviceName in this object
QScriptValue scriptFunction = m_pScriptEngine->execute("init");
if (!scriptFunction.isFunction()) qDebug() << "MidiObject: No init
function in script";
else {
@@ -233,6 +235,7 @@
// -----
args << QScriptValue(m_pScriptEngine->getEngine(), control);
args << QScriptValue(m_pScriptEngine->getEngine(), value);
+ args << QScriptValue(m_pScriptEngine->getEngine(), category);
scriptFunction.call(QScriptValue(),args);
m_pScriptEngine->checkException();
@@ -385,4 +388,4 @@
MidiScriptEngine * MidiObject::getMidiScriptEngine() {
return m_pScriptEngine;
}
-#endif
+#endif
\ No newline at end of file
------------------------------------------------------------------------------
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel