FileIO in MuseScore 3.0.5 plugin ?

• Mar 14, 2019 - 14:06

Hello

FileIo - to write text file - is not available in MuseScore 3 ?

In MuseScore-2 it was OK ( code sample hereafter)
In MuseScoe 3.0.5 it makes "module "FileIO" version 1.0 is not installed"
Thank you for your help

// Version MuseScore 3 NOT OK //
////////////////////////////////////

import QtQuick 2.2
import MuseScore 3.0
import FileIO 1.0
MuseScore {
      version:  "3.0"
      description: qsTr("test plugins musescore 3")
      menuPath: "Plugins.Notes.test"
      FileIO { // generates module "FileIO" version 1.0 is not installed
            id: outfile
            source: "pos.txt"
            onError: console.log(msg)
      }

// Version MuseScore 2 OK //
////////////////////////////////////

import QtQuick 2.0
import MuseScore 1.0 
import FileIO 1.0
 
MuseScore {
      version:  "1.0"
      description: "plugin scan position"
      menuPath: "Plugins.Notes.scan_position"
 
      // output file to save the positions of the notes
      FileIO {
            id: outfile
            source: "pos.txt" 
            onError: console.log(msg)
      }

Comments

In reply to by Frank Revolle

Example of code to write tick/pitches in a text file, for MuseScore3.
If it can help other users...

import QtQuick 2.2
import MuseScore 3.0
import FileIO 3.0
MuseScore {
  version:  "3.0"
  description: qsTr("test plugins musescore 3")
  menuPath: "Plugins.Notes.test"

  // output file to save the notes
  FileIO {
        id: outfile
        source: "/tmp/test.txt" // to be changed according your configuration
        onError: console.log(msg)
  }

  function listnotes() {
        var cursor = curScore.newCursor();
        cursor.rewind(1);
        var startStaff = 0;
        var endStaff = curScore.nstaves - 1;
        var mtext = ""
        for (var staff = startStaff; staff <= endStaff; staff++) {
              console.log("  listnotes staff=" + staff);
              for (var voice = 0; voice < 4; voice++) {
                    console.log("    listnotes voice=" + voice);
                    cursor.rewind(1); // sets voice to 0
                    cursor.voice = voice; //voice has to be set after goTo
                    cursor.staffIdx = staff;
                    cursor.rewind(Cursor.SCORE_START) // beginning of score
                    while (cursor.segment) {
                          var e = cursor.element;
                          if (e) {
                                console.log("type:", e.name, "at  tick:", e.tick, "color", e.color);
                                if (e.type == Element.REST) {
                                      console.log("rest!")
                                      }
                                if (e.type == Element.CHORD) {
                                      console.log("chord!")
                                      var notes = e.notes;
                                      if ( notes ) {
                                            for (var k = 0; k < notes.length; k++) {
                                                  var note = notes[k];
                                                  console.log("       listnotes note=" , k , " pitch=" , note.pitch);
                                                  mtext = mtext + "tick=" + e.tick + " pitch=" + note.pitch + "\n";
                                                  }
                                            }
                                      else {
                                            console.log("        listnotes zero note");
                                            }
                                      }
                          }
                          cursor.next();
                    }
              }
        }
        outfile.write(mtext);
  }

  onRun: {
        console.log("hello test plugins musescore 3");
        if (typeof curScore === 'undefined')
              Qt.quit();
        listnotes()
        Qt.quit();
     }
}

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