//============================================================================= // MuseScore // Music Score Editor // $Id:$ // // Export Notes plugin // // Copyright (C)2011 Charles Cave (charlesweb@optusnet.com.au) // // 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. //============================================================================= // 2011-10-03 Export Notes // The purpose of this plugin is to export all the note information to a // CSV format file for processing with other scripts. function init() { print("test script init"); } function run() { var cursor = new Cursor(curScore); var fName = QFileDialog.getSaveFileName("Dialog 1", "Select .csv file to create", pluginPath, "CSV file (*.csv)", 0); if(fName == null || fName == " ") return; var file = new QFile(fName); var crLf = "\r\n"; // for DOS output \n for Unix if( !file.open(QIODevice.ReadWrite) ) { QMessageBox.critical("Dialog1", "File Error", "Could not create " + fName); return; } var textStream = new QTextStream(file); // output score information textStream.writeString("Score Title," + curScore.title + crLf); textStream.writeString("Score Subtitle," + curScore.subtitle + crLf); textStream.writeString("Score Composer," + curScore.composer + crLf); textStream.writeString("Score Poet," + curScore.poet + crLf); textStream.writeString("Staves," + curScore.staves + crLf); textStream.writeString("Key Signature," + curScore.keysig + crLf); textStream.writeString("Measures," + curScore.measures + crLf); textStream.writeString("Measure Duration ticks," + crLf); var timeSignature = curScore.timesig; textStream.writeString("Time Signature," + timeSignature.type + crLf); textStream.writeString("MIDI ticks per quarter note," + division + crLf); // go through the score by staff and voice, exporting chord, note // and rest information for (var staff = 0; staff < curScore.staves; ++staff) { textStream.writeString("Staff," + staff + crLf); cursor.staff = staff; for (var v = 0; v < 3; v++) { textStream.writeString("Voice," + v + crLf); cursor.voice = v; cursor.rewind(); while (!cursor.eos()) { if (cursor.isChord()) { var chord = cursor.chord(); var n = chord.notes; // Chord information has the note duration textStream.writeString("Chord," + cursor.tick() + "," + chord.tickLen + "," + chord.notes + "," + chord.type + crLf); // Output information about each note in the chord for (var i = 0; i < n; i++) { var note = chord.note(i); textStream.writeString("Note," + cursor.tick() + "," + note.name + "," + note.tied + "," + note.pitch + "," + note.tpc + "," + note.visible + "," + note.userAccidental + "," + note.velocity + "," + note.noteHead + crLf); } } if (cursor.isRest()) { var rest = cursor.rest(); textStream.writeString("Rest," + cursor.tick() + "," + rest.tickLen + crLf); } cursor.next(); } } } file.close(); } var mscorePlugin = { menu: 'Plugins.Notes.ExportNotes', init: init, run: run }; mscorePlugin; // Score Title,TEXT // Score Subtitle,TEXT // Score Composer,TEXT // Score Poet,TEXT // Staves,INT // Key Signature,INT -7 (flats) to +7 (sharps) // Measures,INT // Measure Duration ticks, Empty Currently Unavailable // needs to be added to the file before running this script // for example, 4/4 time is 4 * 480 = 1920 // Time Signature,INT // MIDI ticks per quarter note, INT // // Staff,INT // Voice,I INT // Chord (always followed by 1 or more notes) // cursortick, ticklen, number of notes, chordtype // Note // cursortick, name, tied, pitch, pitch class, visible, useraccidental, // velocity, notehead // Rest // cursortick, restduration // // Example: // // Chord,5280,480,3,0 // Note,5280,Bb,0,58,12,true,0,90,67 // Note,5280,D,0,62,16,true,0,90,67 // Note,5280,G,0,67,15,true,0,90,67 // Rest,29040,240 // Chord,29280,1440,1,0 // Note,29280,G,0,67,15,true,5,90,66