1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
//=============================================================================
// MuseScore
// Linux Music Score Editor
// $Id:$
//
// Abc 2 xml calls a webservice at http://abc2xml.appspot.com to convert
// an abc tune to MusicXML and open it with MuseScore for further editing
//
// Copyright (C)2008 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
//
// This is ECMAScript code (ECMA-262 aka "Java Script")
//
//---------------------------------------------------------
// init
// this function will be called on startup of mscore
//---------------------------------------------------------
function init()
{
// print("test script init");
}
//-------------------------------------------------------------------
// run
// this function will be called when activating the
// plugin menu entry
//
// global Variables:
// pluginPath - contains the plugin path; file separator is "/"
//-------------------------------------------------------------------
var outFile;
var reqId;
var defaultOpenDir = QDir.homePath();
function run()
{
var filename = QFileDialog.getOpenFileName(this, "MuseScore: Load ABC File", defaultOpenDir, "ABC file (*.abc)");
if(filename){
//read abc file
var file = new QFile(filename);
var line;
if ( file.open(QIODevice.ReadOnly) ) {
// file opened successfully
var t = new QTextStream( file ); // use a text stream
var content ="";
do {
line = t.readLine(); // line of text excluding '\n'
// do something with the line
content +=line;
content +='\n'; // add the missing '\n'
} while (line);
// Close the file
file.close();
}
//print(content);
//encode file content for url
var encodedContent = QUrl.toPercentEncoding(content).toString();
var url = "/abcrenderer?abc=" + encodedContent;
//print(url);
//call the webservice and save to temporary file
outFile = new QTemporaryFile(QDir.tempPath()+"/abc_XXXXXX.xml");
outFile.open();
var http = new QHttp();
http.setHost("abc2xml.appspot.com", 80);
http.requestFinished.connect(outFile,finished);
reqId = http.get(url,outFile);
}
}
//---------------------------------------------------------
// display a message box with error message
//---------------------------------------------------------
function errorMessage(){
mb = new QMessageBox();
mb.setWindowTitle("Error: abc2xml conversion");
mb.text = "An error occured during the conversion.<br />Try it manually at: <a href=\"http://abc2xml.appspot.com\">http://abc2xml.appspot.com</a>";
mb.exec();
}
//---------------------------------------------------------
// get finished handler
//---------------------------------------------------------
function finished(id ,error){
print("finished");
print(id);
if (error){
errorMessage();
return;
}
if (id == reqId){
outFile.flush();
outFile.close();
if(outFile.size() > 200){
var score = new Score();
score.load(outFile.fileName());
}else{
errorMessage();
}
}
}
QByteArray.prototype.toString = function()
{
ts = new QTextStream( this, QIODevice.ReadOnly );
return ts.readAll();
}
//---------------------------------------------------------
// menu: defines were the function will be placed
// in the MuseScore menu structure
//---------------------------------------------------------
var mscorePlugin = {
menu: 'Plugins.ABC Import',
init: init,
run: run
};
mscorePlugin;
|