Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Last active October 13, 2017 08:35
Show Gist options
  • Save bzamecnik/1a4be667d7258b6e34941b38a6649773 to your computer and use it in GitHub Desktop.
Save bzamecnik/1a4be667d7258b6e34941b38a6649773 to your computer and use it in GitHub Desktop.
MuseScore plugin - QtScript snippets
// list properties on an object - poor man's reflection
for (var prop in curScore) {
console.log(prop)
}
//// properties of Ms:Score:
// addText
// appendMeasures
// appendPart
// composer
// cropPage
// doLayout
// duration
// endCmd
// endCmd
// excerpts
// extractLyrics
// firstMeasure
// firstMeasureMM
// firstSegment
// firstSegment
// harmonyCount
// hasHarmonies
// hasLyrics
// keysig
// lastMeasure
// lastMeasureMM
// lastSegment
// lyricCount
// metaTag
// name
// newCursor
// nmeasures
// npages
// nstaves
// ntracks
// objectName
// objectNameChanged
// pageFormat
// parts
// playlistChanged
// poet
// posChanged
// setMetaTag
// startCmd
// subtitle
// title
// updateRepeatList
// docs: https://musescore.org/en/plugin-development/score-object (outdated)
// https://github.com/musescore/MuseScore/blob/master/libmscore/score.h
// properties of a C++ class visible from QtScript are marked with Q_PROPERTY or Q_INVOKABLE
// https://stackoverflow.com/questions/5547692/qtscript-introspection-reflection
// Loads a MusicXML file via an HTTP request and opens it as a new score.
//
// You can generate a random score and save it as random.xml
//
// The backend this XML file can be as easy as:
//
// $ python -m http.server
//
// You can test if it works with:
//
// $ curl http://localhost:8000/random.xml
import QtQuick 2.0
import MuseScore 1.0
import FileIO 1.0
MuseScore {
menuPath: "Plugins.loadMidiViaAjax"
FileIO {
id: loadedFile
source: tempPath() + "/loadedScore.xml"
onError: console.log(msg)
}
onRun: {
var request = new XMLHttpRequest()
request.open("GET", "http://localhost:8000/random.xml", /*async*/ true)
request.onreadystatechange = function() {
if (request.readyState == XMLHttpRequest.DONE) {
loadedFile.write(request.responseText)
readScore(loadedFile.source, "xml")
}
}
request.send()
Qt.quit();
}
}
import QtQuick 2.0
import MuseScore 1.0
import FileIO 1.0
MuseScore {
menuPath: "Plugins.printMusicXml"
FileIO {
id: scoreFile
source: tempPath() + "/score.xml"
onError: console.log(msg)
}
onRun: {
writeScore(curScore, scoreFile.source, "xml")
var scoreXml = scoreFile.read()
console.log(scoreXml)
Qt.quit()
}
}
writeScore(curScore, "/tmp/foo.xml", "xml")
readScore("/tmp/foo.xml", "xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment