wslib quarks optimization
Closed this issue · 3 comments
Why is it so long to generate a midi File from data with the wslib quark. I did a big try with
22,000 notes for an AI project and after 1 hour I am still waiting !!! it's more time then training a Neural Network for 2, 3 epochs.
Something wrong, not optimized, it's a sorting data problem...
(
m = SimpleMIDIFile( "~/Desktop/LondonMidi_10dec_4track_T60.mid") ;
m.init1(5, 60, "4/4" ); // 4 tracks
m.addNote(72, 2, 2.45, 0.12, 127, track: 1 ) ;
m.addNote(80, 2, 2.65, 0.25, 127, track: 1 ) ;
m.addNote(73, 2, 2.76, 0.19, 127, track: 1 ) ;
m.addNote(50, 2, 3.17, 0.36, 127, track: 1 ) ;
m.addNote(43, 2, 4.18, 0.55, 127, track: 1 ) ;
(...)
It's seem ok just for very small project ( 100 to 1000 midi notes) .
Or maybe the default setting in the interpreter cannot handle too much data...
Best Regards
transferring to the wslib quark repo directly so that project's maintainer can manage it
Hi @qcmv22,
sorry for the late reply, I didn't notice the issues here on Github before as I barely come here. But as lockdown now results in homework I finally have time to do it :-). The issue is in fact not optimization, SimpleMIDIFile is as optimized as SuperCollider can be (which is unfortunately with large array operations not very optimized..), but the problem here is a little thing that should be in the documentation (well, it's still lockdown, so who knows..). The last argument of .addNote (and some other methods) is: sort. Default is true, which will make sure that the newly added note is placed on the correct spot in the midiEvents array, by sorting the whole array by event start-times. If you add multiple notes, you only need to sort once (i.e. after the last added note). This can easily be done by setting the sort arg to false in all earlier addNotes. I.e.:
(
m = SimpleMIDIFile( "~/Desktop/LondonMidi_10dec_4track_T60.mid") ;
m.init1(5, 60, "4/4" ); // 4 tracks
m.addNote(72, 2, 2.45, 0.12, 127, track: 1, sort: false ) ;
m.addNote(80, 2, 2.65, 0.25, 127, track: 1, sort: false ) ;
m.addNote(73, 2, 2.76, 0.19, 127, track: 1, sort: false ) ;
m.addNote(50, 2, 3.17, 0.36, 127, track: 1, sort: false ) ;
(....)
m.addNote(43, 2, 4.18, 0.55, 127, track: 1 ) ; /// last added event, sort = true
// or call separately:
m.sortMIDIEvents;
As you can probably imagine this will massively speed up the process with large numbers of added notes..
Hope that helps!
Cheers,
Wouter
Ok, Thanks...