Hello again.

In my previous excitement, I forgot one little detail: scripts need to
check & set Mixxx control values. The attached patch addresses this
concern. (It also removes an extra slash in the script path names and
adds a no-op function to the default script. (To avoid a syntax error on
load when there's no code.))

Moral: Don't call anything "final" until it's released. :)

Sean
"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 2435)
+++ src/script/midiscriptengine.h	(working copy)
@@ -42,6 +42,9 @@
     
     bool checkException();
     
+    Q_INVOKABLE double getValue(QString group, QString name);
+    Q_INVOKABLE void setValue(QString group, QString name, double newValue);
+    
 private:
     QScriptEngine m_engine;
     QScriptValue m_result;
Index: src/script/midiscriptengine.cpp
===================================================================
--- src/script/midiscriptengine.cpp	(revision 2435)
+++ src/script/midiscriptengine.cpp	(working copy)
@@ -17,6 +17,7 @@
  ***************************************************************************/
 
 #include "midiscriptengine.h"
+#include "../controlobject.h"
 
 /* -------- ------------------------------------------------------
    Purpose: Open script file, read into QString
@@ -188,3 +189,41 @@
 
     return functionList;
 }
+
+/* -------- ------------------------------------------------------
+   Purpose: Returns the current value of a Mixxx control (for scripts)
+   Input:   Control group (e.g. [Channel1]), Key name (e.g. [filterHigh])
+   Output:  The value
+   -------- ------------------------------------------------------ */
+double MidiScriptEngine::getValue(QString group, QString name) {
+    
+    QByteArray ba = group.toUtf8();
+    const char *grp = ba.data();
+    
+    ba = name.toUtf8();
+    const char *nam = ba.data();
+
+    ControlObject *pot = ControlObject::getControl(ConfigKey(grp, nam));
+    if (pot == NULL) {
+        qDebug("MidiScriptEngine: Unknown control %s:%s", grp, nam);
+        return 0.0;
+    }
+    return pot->get();
+}
+
+/* -------- ------------------------------------------------------
+   Purpose: Sets new value of a Mixxx control (for scripts)
+   Input:   Control group, Key name, new value
+   Output:  -
+   -------- ------------------------------------------------------ */
+void MidiScriptEngine::setValue(QString group, QString name, double newValue) {
+
+    QByteArray ba = group.toUtf8();
+    const char *grp = ba.data();
+    
+    ba = name.toUtf8();
+    const char *nam = ba.data();
+    
+    ControlObject *pot = ControlObject::getControl(ConfigKey(grp, nam));
+    pot->queueFromThread(newValue);
+}
\ No newline at end of file
Index: src/midiobject.cpp
===================================================================
--- src/midiobject.cpp	(revision 2435)
+++ src/midiobject.cpp	(working copy)
@@ -44,19 +44,19 @@
     m_pScriptEngine->engineGlobalObject.setProperty("midi", m_pScriptEngine->getEngine()->newQObject(this));
 
     ConfigObject<ConfigValue> *m_pConfig = new ConfigObject<ConfigValue>(QDir::homePath().append("/").append(SETTINGS_FILE));
-    m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("/midi/midi-mappings-scripts.js"));
+    m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("midi/midi-mappings-scripts.js"));
 // FIXME: this hack below has to be replaced with something better... even *.js is preferrable to a hard coded string switch statement.
 //     switch (m_device) {
 //         case "SCS.3d MIDI *":
-//             m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("/midi/Stanton-SCS3d-scripts.js"));
+//             m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("midi/Stanton-SCS3d-scripts.js"));
 //             break;
 //         case "Hercules MK2 *":
-//             m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("/midi/Hercules-MK2-scripts.js"));
+//             m_pScriptEngine->loadScript(m_pConfig->getConfigPath().append("midi/Hercules-MK2-scripts.js"));
 //             break;
 //     }
     qDebug() << "MidiObject: Evaluating all script code";
     m_pScriptEngine->evaluateScript();
-    if (!m_pScriptEngine->checkException()) qDebug() << "MidiObject: Script code evaluated successfully";
+    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
     QScriptValue scriptFunction = m_pScriptEngine->execute("init");
@@ -218,7 +218,10 @@
     if (((ConfigValueMidi *)c->val)->midioption==MIDI_OPT_SCRIPT) {
 //         qDebug() << "MidiObject: Calling script function" << pConfigKey->item;
         QScriptValue scriptFunction = m_pScriptEngine->execute(pConfigKey->item);
-        if (!scriptFunction.isFunction()) qDebug() << "MidiObject: Invalid Function";
+        if (!scriptFunction.isFunction()) {
+            qDebug() << "MidiObject: Invalid function" << pConfigKey->item;
+            return;
+        }
         else {
 //             ScriptMidiMsg *tempMidiMsg = new ScriptMidiMsg(channel, control, value, device);
 //             QScriptValue msg = m_pScriptEngine->getEngine().newQObject(tempMidiMsg);
@@ -382,4 +385,4 @@
 MidiScriptEngine * MidiObject::getMidiScriptEngine() {
     return m_pScriptEngine;
 }
-#endif
+#endif
\ No newline at end of file
Index: src/midi/midi-mappings-scripts.js
===================================================================
--- src/midi/midi-mappings-scripts.js	(revision 2435)
+++ src/midi/midi-mappings-scripts.js	(working copy)
@@ -1,3 +1,5 @@
-// Scripts common to all controllers go in this file
-//
-// Note: All script files MUST end with a blank line or you will get an error!
+// Functions common to all controllers go in this file
+
+nop = function () {
+    // Only here so you don't get a syntax error on load
+}
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to