pd-externals / midifile

Read and write MIDI files (.mid) with Pd
Other
0 stars 0 forks source link

changing the "track" when writing, resets it. #8

Open umlaeute opened 6 days ago

umlaeute commented 6 days ago

it seems that writing tracks is seriously broken.

most importantly, https://github.com/pd-externals/midifile/blob/95354384c269ae2c849fe710c0c13570de5c1656/midifile.c#L1420-L1424 will always be true (because x->track_chunk[x->track].track_data is nowhere used when writing data), and thus the tempfiles are cleared whenever a track message is sent (during writing).

i'm not a frequent user of [midifile], so i might miss something. otherwise i have a simple fix at hand

afaict, this might be related to one of the subitems of #3

umlaeute commented 6 days ago

btw, my expectation would have been that i could freely switch the tracks while writing, in order to e.g. record drums and piano simultaneously (into different tracks)

danomatika commented 6 days ago

Without looking at the code, I think it's a state mechanism:

  1. set track to write to
  2. send message
  3. repeat for a different track

I would think only allowing one track at a time would be severely limiting. Ideally, I could write multiple tracks per tick.

umlaeute commented 6 days ago

well, yes; that's what i expect as well.

it seems like it doesn't work like this though.

my fix would be:

diff --git a/midifile.c b/midifile.c
index 65a427d..bbb84e2 100644
--- a/midifile.c
+++ b/midifile.c
@@ -1417,7 +1417,7 @@ static void midifile_set_track(t_midifile *x, t_floatarg track)
         else
         {
             x->track = track; // possibly update x->header_chunk.chunk_ntrks
-            if (x->track_chunk[x->track].track_data == NULL)
+            if (x->tmpFP[x->track] == NULL)
             {
                 /* this track is being used for the first time */
                 post("this track (%d) is being used for the first time", x->track);

(but otoh, i would really like to get rid of these tempfiles altogether (see #7))

danomatika commented 6 days ago

Yeah, we don't need temp files. MIDI data is so compact, I can't imagine memory pressure being an issue.