Advertisement
Guest User

Untitled

a guest
Sep 15th, 2013
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // this plugin subdivides all notes into 256ths
  2.  
  3. function init() {
  4. };
  5.  
  6. var duration = 240;
  7.  
  8.  
  9.  
  10.  
  11. function run() {
  12.     if (typeof curScore === 'undefined')
  13.             return;
  14.  
  15.       var cursor     = new Cursor(curScore);
  16.       var c2 = new Cursor(curScore);
  17.       cursor.goToSelectionStart();
  18.       c2.goToSelectionStart();
  19.       var startStaff  = cursor.staff;
  20.       cursor.goToSelectionEnd();
  21.       c2.goToSelectionEnd();
  22.       var endStaff   = cursor.staff;
  23.       var endTick    = cursor.tick() // if no selection, end of score
  24.  
  25.       if (cursor.eos()) { // no selection
  26.             startStaff = 0; // start with 1st staff
  27.             endStaff = curScore.staves; // and end with last
  28.       }
  29.  
  30.       for (var staff = startStaff; staff < endStaff; ++staff) {
  31.             for (var voice = 0; voice < 4; voice++) {          
  32.                   cursor.goToSelectionStart(); // sets voice to 0
  33.                   c2.goToSelectionStart();
  34.                   cursor.voice = voice; //voice has to be set after goTo
  35.                   c2.voice = voice;
  36.                   cursor.staff = staff;
  37.                   c2.staff = staff;
  38.                   if (cursor.eos()) {
  39.                           cursor.rewind() // if no selection, beginning of score
  40.                           c2.rewind();
  41.                   }
  42.                   while (cursor.tick() < endTick) {
  43.                         if (cursor.isChord()) {
  44.                               var chord = cursor.chord();
  45.                               var rest = new Rest(curScore);
  46.                               rest.tickLen = chord.tickLen;
  47.                               var it = chord.tickLen / duration;
  48.                               chord.tickLen = duration;                              
  49.                               c2.add(rest);
  50.                               for (var i = 0; i < it; i++) {
  51.                                       cursor.add(chord);
  52.                                       //cursor.next();
  53.                               }
  54.                         } else {
  55.                             c2.next();
  56.                             cursor.next();
  57.                         }
  58.                   }
  59.             }
  60.       }
  61. };
  62.  
  63. var mscorePlugin = {
  64.     menu: 'Plugins.Subdivide.8ths',
  65.     init: init,
  66.     run: run
  67. };
  68. mscorePlugin;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement