{
   "name" : "Import midinote, dur, amp and sustain from midi file using SimpleMIDIFile",
   "author" : "grirgz",
   "description" : "There is the .p method (see http://sccode.org/1-5aT) but here is also a way to retrieve the values directly",
   "ancestor_list" : [],
   "labels" : [
      "pattern",
      "midi",
      "file",
      "mid",
      "import"
   ],
   "is_private" : null,
   "id" : "1-5fz",
   "code" : "m = SimpleMIDIFile.read( \"~/Téléchargements/Super Mario Bros 2 - Mario Dreams.mid\" ); \r\n(\r\n    TempoClock.default.tempo = m.tempo/60;\r\n    Pdef(\\bla, \r\n        Pbind(\r\n            \\instrument, \\default,\r\n            [\\midinote, \\dur, \\sustain, \\amp], Prout({ arg ev;\r\n                var timescale = 1/16/60;\r\n                var prevev;\r\n                m.noteSustainEvents.collect({ arg item, idx;\r\n                    // [track, absTime, \\noteOn, channel, note, velo, dur, upVelo]\r\n                    if(idx == 0) {\r\n                        prevev = [item[4], item[1], item[6] * timescale, item[5]/127]\r\n                    } {\r\n                        prevev[1] = item[1] - prevev[1] * timescale;\r\n                        ev = prevev.yield;\r\n                        prevev = [item[4], item[1], item[6] * timescale, item[5]/127];\r\n                    };\r\n                });\r\n                prevev[1] = prevev[2];\r\n                ev = prevev.yield;\r\n            }),\r\n        )\r\n    ).play\r\n)"
}
