Calling an external c++ application

• Dec 1, 2010 - 10:20

Hi,

I have a c++ program that generates a musicXML file and I want to try to put this into a plugin. So that when you click the plugin menu, the musicxml opens in MuseScore.

I looked at the abc plugin, as Thomas suggested. This uses a google apps webservice:

var http = new QHttp();
http.setHost("abc2xml.appspot.com", 80);
http.requestFinished.connect(outFile,finished);
reqId = http.get(url,outFile);

Unfortunately, c++ is not supported by the GAE.

So my first idea was just to try this out locally and just call the program. How would I do this in javascript?

A better suggestion would be to find an alternative to GAE that supports c++. Any suggestions here?

Many thanks!

Dorien


Comments

It all depends what you want to do.
For testing purpose, you could make a command line version of your C++ program and call it from the plugin using QProcess. If you want to distribute the plugin, it might be difficult to make it cross platform etc...

Something like :

var process= new QProcess();
var args = new Array();
args[0]= "";
args[1]= "";
args[2]= "";
args[3]= "";

process.start("PATH TO YOUR COMMAND LINE", args );
process.waitForStarted();
process.waitForFinished();

So for distribution purpose, you could setup a webserver, and some PHP (or any other language) to call expose a webservice that call your command line utility on the server. The plugin will just communicate with this webservice, and you could have access to data to test your utility further.

We can discuss further on #musescore IRC on freenode.net if necessary.

In reply to by [DELETED] 5

Thanks a lot! That really helps. I can't seem to be able to access the irc from the uni. I'll try again this evening.

I've been reading the docs for Qprocess at http://doc.qt.nokia.com/4.3/qprocess.html and I think I can just use

process.start("PATH TO YOUR COMMAND LINE" );

if I have no arguments (currently args are in an input textfile... again this is just for the testing phase, I just want to get a basic example up and running).

So far I have a very basic skeleton, but the optimuse program does not seem to run:

function init()
{
//opening a QMessageBox here works on startup -> great
}

function finished(id ,error){
print("finished");
}

function run()
{
//call the local program
var process= new QProcess();
process.start("/home/dorien/C++/optimuse1-build-desktop/optimuse");
process.waitForStarted();
process.waitForFinished();
}

//display the menu entry
var mscorePlugin = {
menu: 'Plugins.Optimuse-Cantus Firmus',
init: init,
run: run
};

Any ideas why this does not work. It seems simple enough. The program should generate an xml file (that I would then later add using score.load), but it does not run. Could it be because of the arguments that the Qprocess does not work?

Also another thing, I was wondering where the print messages display, in a log somewhere perhaps?

Many thanks!
Dorien

In reply to by [DELETED] 5

Thanks,

The debugger acts like everything is fine. I tried adding an argument, also to my main() function in the program.

If I run optimuse from command line, it works perfectly and creates the end.xml file.

If I run the following plugin, the end.xml file is loaded in musescore, but it is still the old one (no refreshing does not help). So it would seem that optimuse has not run. I have been messing around with Qprocess.execute, but I am new at Qt and javascript, so I could use some advise ;-)


//run optimuse
var process= new QProcess();
var args = new Array();
args[0]= "1";

process.start("/home/dorien/C++/optimuse1-build-desktop/optimuse", args);
process.waitForStarted();
process.waitForFinished();

//load the end.xml file into musescore (works great)
outFile = new QTemporaryFile("/home/dorien/C++/optimuse1-build-desktop/end.xml");
var score = new Score();
score.load(outFile.fileName());

Sorry for bothering you so much, your efforts are much appreciated!

Dorien

In reply to by dorien

Hi,

Just wanted to keep you updated. Seems like there is progress. Using:

process.setStandardOutputFile("/home/dorien/stdout.txt");
process.setStandardErrorFile("/home/dorien/stderr.txt");

I found that optimuse could not locate its input file. I guess changing the way the program is executed changes the relative paths. I think I can figure out a way of passing the correct path

:-)

In reply to by dorien

Attached a plugin that worked for me on Windows with MuseScore 0.9.6.3. It opens the default text editor on windows.
Rename as textcm.js, edit to launch your program, and copy to your MuseScore plugins directory, restart MuseScore and click Plugin-> Test Command Line.

Attachment Size
textcm.txt 2.16 KB

Do you still have an unanswered question? Please log in first to post your question.