«SimpleMIDIFile help» by Wingel Pérez Mendoza

on 23 May'19 23:37 in

Dear friends, I am trying to manipulate different aspects in a midi file, so far, I am having problems with 2 particular aspects. I want to control my midi file with a slider, but I don´t know why is not working, another problem is that my code doesn´t play the rhythm, could you help me, please???

Greetings,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(
m = SimpleMIDIFile.read("C:/Users/WM/Documents/Peter code/Midi/Croatia.mid");
m.timeMode_('seconds'); // convert ticks to seconds
);
(
MIDIClient.init; // check list for available devices
MIDIClient.destinations;
a = MIDIOut(2); //Midi number of destination
);
(
~cont = 0;
~tiempo = 0.2;
~transpose = 12;
t = Task({
	e = m.noteSustainEvents(nil, nil); // get notes from track 1
e.do{arg event;
        a.noteOn(1, e[~cont][4] + ~transpose, e[~cont][5]);
        e[~cont][6]*~tiempo.wait; // durations, you can scale this number to change the durations
        a.noteOff(1, e[~cont][4] + ~transpose, e[~cont][5]);
        ~cont=~cont+1;
        ~cont.postln;
};
});
);
//Gui

(
var window, button, fader;
window = Window("Peter´s Code", Rect(100, 100, 400, 500)).front;
button = Button(window, Rect(30, 380, 150, 100));
fader = Slider(window,  Rect(30, 40, 50, 320));
fader.action_({|obj|
	var tr;
	tr = obj.value.linlin(0,1,-12,12).postln;
	tr + ~transpose;
	{a.allNotesOff};
});
button.states = [["Off", Color.white, Color.black], ["On", Color.black, Color.red]];
button.action = {|val| if(val.value == 1, {t.play; "Task On".postln}, {t.stop; "Task Off".postln})};
);
raw 1210 chars (focus & ctrl+a+c to copy)
reception
comments