Patch looks like a decent start. There has to be a better way to resolve the function names other than regexing for them though. That's like writing your own language parser. :) I've been scouring the docs for an answer and I'll keep looking.
Note that functions written in QtScript are _objects_ according to the docs, so there's gotta be a way to do this. Also, probably useful info here: http://doc.trolltech.com/4.4/qtscript.html#function-objects-and-native-functions (I'm still reading though) Thanks, Albert On 14-Dec-08, at 12:55 AM, Sean M. Pappalardo wrote: > Hello all. > > Well, after a solid day's work and much help from Albert and Garth, we > have the attached patch and new source files. > > This patch along with the new files successfully reads in the default > "midi-mappings-scripts.js", pulls out the list of function names, > compares them to the <key> value when an XML file is read in (and > <script-binding> is specified,) and pops a warning dialog if there's > no > match. Basically items 1-3 at the bottom of the MIDI extension spec > wiki > page http://www.mixxx.org/wiki/doku.php/midi ) > > Please place the midiscriptengine* source files in the src/script > subdirectory as that's where they're expected to be, unless you think > they should be elsewhere. > > Please review the midiscriptengine.* files carefully as this is my > first > crack at writing new C++ code. (I had problems having the default > constructor call the overloaded one, so I commented it out. Perhaps > someone can tell me what I did wrong.) > > Thanks for your time. We're almost there! > > 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/midiobject.cpp > =================================================================== > --- src/midiobject.cpp (revision 2423) > +++ src/midiobject.cpp (working copy) > @@ -37,6 +37,8 @@ > requestStop = false; > midiLearn = false; > debug = false; > + > + ScriptEngine = new MidiScriptEngine(UNIX_SHARE_PATH "/midi/midi- > mappings-scripts.js"); > } > > /* -------- ------------------------------------------------------ > Index: src/midiobject.h > =================================================================== > --- src/midiobject.h (revision 2423) > +++ src/midiobject.h (working copy) > @@ -21,8 +21,8 @@ > #include <QtCore> > #include "defs.h" > #include "configobject.h" > +#include "script/midiscriptengine.h" > > - > class ControlObject; > class QWidget; > class DlgPrefMidiBindings; > @@ -61,6 +61,8 @@ > /** Returns a list of available configurations. Takes as input > the directory path > * containing the configuration files */ > QStringList *getConfigList(QString path); > + > + MidiScriptEngine *ScriptEngine; > > // Stuff for sending messages to control leds etc > void sendShortMsg(unsigned char status, unsigned char byte1, > unsigned char byte2, QString device); > Index: src/dlgprefmidibindings.cpp > =================================================================== > --- src/dlgprefmidibindings.cpp (revision 2423) > +++ src/dlgprefmidibindings.cpp (working copy) > @@ -19,6 +19,7 @@ > #include "dlgprefmidibindings.h" > #include "wwidget.h" > #include "configobject.h" > +#include "script/midiscriptengine.h" > > #define BINDINGS_PATH > QDir::homePath().append("/").append(".MixxxMIDIBindings.xml") > const QStringList options = (QStringList() << "Normal" << "Script- > Binding" << "Invert" << "Rot64" << "Rot64Inv" > @@ -61,7 +62,6 @@ > connect(btnRemoveOutputBinding, SIGNAL(clicked()), this, > SLOT(slotRemoveOutputBinding())); > connect(btnAddOutputBinding, SIGNAL(clicked()), this, > SLOT(slotAddOutputBinding())); > > - > // Try to read in the current XML bindings file, or create one if > nothing is available > loadPreset(BINDINGS_PATH); > applyPreset(); > @@ -95,6 +95,10 @@ > QString device = controller.attribute("id",""); > qDebug() << device << " settings found" << endl; > QDomElement control = > controller.firstChildElement("controls").firstChildElement("control"); > + bool scriptGood=m_pMidi->ScriptEngine->evaluateScript(); > + QStringList scriptFunctions; > + if (scriptGood) scriptFunctions = m_pMidi->ScriptEngine- > >getFunctionList(); > +// QStringList(m_pMidi->getOpenDevices()); > while (!control.isNull()) { > // For each control > QString group = WWidget::selectNodeQString(control, > "group"); > @@ -113,8 +117,14 @@ > } else { > option = "Normal"; > } > + > + // Verify script functions are loaded > + if (scriptGood && (option=="script-binding" || > option=="Script- > Binding") && scriptFunctions.indexOf(key)==-1) { > + QMessageBox::warning(this, "Warning: Script > function not > found", "Function "+key+" not found in script "+m_pMidi- > >ScriptEngine->getFilepath()+".\nThis control will be ignored."); > + } else { > // Construct row in table > addRow(device, group, key, controltype, miditype, > midino, > midichan, option); > + } > control = control.nextSiblingElement("control"); > } > > / > *************************************************************************** > midiscriptengine.h - description > ------------------- > begin : Fri Dec 12 2008 > copyright : (C) 2008 by Sean M. Pappalardo > "Holy crap, I wrote new code!" > email : [email protected] > ***************************************************************************/ > > / > *************************************************************************** > * * > * This program is free software; you can redistribute it and/or > modify * > * it under the terms of the GNU General Public License as > published by * > * the Free Software Foundation; either version 2 of the License, > or * > * (at your option) any later > version. * > * * > ***************************************************************************/ > > #include "midiscriptengine.h" > > /* -------- ------------------------------------------------------ > Purpose: Open default script file, read into QString, evaluate() it > Input: - > Output: - > -------- ------------------------------------------------------ */ > // MidiScriptEngine::MidiScriptEngine() { > // > // // Default common script file > // MidiScriptEngine(UNIX_SHARE_PATH "/midi/midi-mappings- > scripts.js"); > // } > > /* -------- ------------------------------------------------------ > Purpose: Open script file, read into QString, evaluate() it > Input: Path to script file > Output: - > -------- ------------------------------------------------------ */ > MidiScriptEngine::MidiScriptEngine(QString filepath) : m_engine() { > > m_filepath=filepath; > // qDebug() << "MidiScriptEngine: Path construction"; > > QScriptValue globalObject = m_engine.globalObject(); > globalObject.setProperty("Mixxx", m_engine.newQObject(this)); > > // Read in the script file > QFile input(m_filepath); > if (!input.open(QIODevice::ReadOnly)) { > qWarning() << "MidiScriptEngine: Problem opening the script > file: > " << m_filepath << ", error #" << input.error(); > return; > } > m_scriptCode = QString(input.readAll()); > input.close(); > } > > MidiScriptEngine::~MidiScriptEngine() { > } > > /* -------- ------------------------------------------------------ > Purpose: Validate script syntax, then evaluate() it so the > functions are registered & available for use. > Input: - > Output: m_result QString is set > -------- ------------------------------------------------------ */ > bool MidiScriptEngine::evaluateScript() { > if (!m_engine.canEvaluate(m_scriptCode)) { > qWarning() << "MidiScriptEngine: ?Syntax error in script file:" > << > m_filepath; > m_scriptCode.clear(); // Free up now-unneeded memory > return false; > } > m_result = m_engine.evaluate(m_scriptCode).toString(); > qDebug() << "MidiScriptEngine: Script" << m_filepath << "evaluated > successfully."; > // qDebug() << "m_scriptCode: " << m_scriptCode; > return true; > } > > /* -------- ------------------------------------------------------ > Purpose: Return the result of the last operation > Input: - > Output: m_result QString > -------- ------------------------------------------------------ */ > QString MidiScriptEngine::getResult() { > return m_result; > } > > /* -------- ------------------------------------------------------ > Purpose: Return the file path of the current script > Input: - > Output: m_result QString > -------- ------------------------------------------------------ */ > QString MidiScriptEngine::getFilepath() { > return m_filepath; > } > > /* -------- ------------------------------------------------------ > Purpose: Returns a list of functions available in the QtScript > code > Input: - > Output: functionList QStringList > -------- ------------------------------------------------------ */ > QStringList MidiScriptEngine::getFunctionList() { > > QStringList functionList; > QStringList codeLines=m_scriptCode.split("\n"); > > // qDebug() << "MidiScriptEngine: m_scriptCode=" << m_scriptCode; > > qDebug() << "MidiScriptEngine:" << codeLines.count() << "lines of > code being searched for functions"; > > // grep 'function' midi/midi-mappings-scripts.js|grep -i '(msg)'| > sed -e 's/function \(.*\)(msg).*/\1/i' -e 's/[= ]//g' > QRegExp rx("*function*(msg)*"); // Find all lines with function > names in them > rx.setPatternSyntax(QRegExp::Wildcard); > > int position = codeLines.indexOf(rx); > > while (position != -1) { // While there are more matches > > QString line = codeLines.takeAt(position); // Pull & > remove the > current match from the list. > > if (line.indexOf('#') != 0) { // ignore # hashed out comments > QStringList field = line.split(" "); > qDebug() << "MidiScriptEngine: Found function:" << > field[0] << > "at line" << position; > functionList.append(field[0]); > } > position = codeLines.indexOf(rx); > } > > return functionList; > } > / > *************************************************************************** > midiscriptengine.h - description > ------------------- > begin : Fri Dec 12 2008 > copyright : (C) 2008 by Sean M. Pappalardo > email : [email protected] > ***************************************************************************/ > > / > *************************************************************************** > * * > * This program is free software; you can redistribute it and/or > modify * > * it under the terms of the GNU General Public License as > published by * > * the Free Software Foundation; either version 2 of the License, > or * > * (at your option) any later > version. * > * * > ***************************************************************************/ > #ifndef MIDISCRIPTENGINE_H > #define MIDISCRIPTENGINE_H > > #include <QtScript> > > class MidiScriptEngine : public QObject { > > Q_OBJECT > > public: > MidiScriptEngine(); > MidiScriptEngine(QString); > ~MidiScriptEngine(); > > QString getResult(); > QString getFilepath(); > > bool evaluateScript(); > QStringList getFunctionList(); > > private: > QScriptEngine m_engine; > QString m_filepath; > QString m_scriptCode; > QString m_result; > }; > > #endif > > ------------------------------------------------------------------------------ > 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 ------------------------------------------------------------------------------ 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
