Chris@2
|
1 /*
|
Chris@2
|
2 Copyright (C) 2001, 2006 by Simon Dixon
|
Chris@2
|
3
|
Chris@2
|
4 This program is free software; you can redistribute it and/or modify
|
Chris@2
|
5 it under the terms of the GNU General Public License as published by
|
Chris@2
|
6 the Free Software Foundation; either version 2 of the License, or
|
Chris@2
|
7 (at your option) any later version.
|
Chris@2
|
8
|
Chris@2
|
9 This program is distributed in the hope that it will be useful,
|
Chris@2
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@2
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@2
|
12 GNU General Public License for more details.
|
Chris@2
|
13
|
Chris@2
|
14 You should have received a copy of the GNU General Public License along
|
Chris@2
|
15 with this program (the file gpl.txt); if not, download it from
|
Chris@2
|
16 http://www.gnu.org/licenses/gpl.txt or write to the
|
Chris@2
|
17 Free Software Foundation, Inc.,
|
Chris@2
|
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Chris@2
|
19 */
|
Chris@2
|
20
|
Chris@2
|
21 package at.ofai.music.util;
|
Chris@2
|
22
|
Chris@2
|
23 import java.util.ListIterator;
|
Chris@2
|
24
|
Chris@2
|
25 class MIDI2Matlab {
|
Chris@2
|
26
|
Chris@2
|
27 public static void main(String[] args) {
|
Chris@2
|
28 EventList e = EventList.readMidiFile(args[0]);
|
Chris@2
|
29 Event[] events = e.toArray(0x90);
|
Chris@2
|
30 int len = events.length;
|
Chris@2
|
31 double[] pitch = new double[len];
|
Chris@2
|
32 double[] vel = new double[len];
|
Chris@2
|
33 double[] onset = new double[len];
|
Chris@2
|
34 double[] offset = new double[len];
|
Chris@2
|
35 for (int i=0; i<len; i++) {
|
Chris@2
|
36 pitch[i] = events[i].midiPitch;
|
Chris@2
|
37 vel[i] = events[i].midiVelocity;
|
Chris@2
|
38 onset[i] = events[i].keyDown;
|
Chris@2
|
39 offset[i] = events[i].keyUp;
|
Chris@2
|
40 }
|
Chris@2
|
41 Format.init(1,5,3,false);
|
Chris@2
|
42 System.out.println("notes = zeros(" + len + ",4);");
|
Chris@2
|
43 Format.matlab(onset, "notes(:,1)", System.out);
|
Chris@2
|
44 Format.matlab(offset, "notes(:,2)", System.out);
|
Chris@2
|
45 Format.matlab(pitch, "notes(:,3)", System.out);
|
Chris@2
|
46 Format.matlab(vel, "notes(:,4)", System.out);
|
Chris@2
|
47 // if (event.midiCommand == 0x90)
|
Chris@2
|
48 // count++;
|
Chris@2
|
49 // else
|
Chris@2
|
50 // System.out.println("*** Other command: " + event.midiCommand);
|
Chris@2
|
51 } // main()
|
Chris@2
|
52 }
|