Jump to content

Exported MIDI file adds silence at the end


Lippeth

Recommended Posts

As you can see when uploading the file here https://g200kg.github.io/midi-dump/ Logic seems to add the End Of Track marker of the tempo track 20 seconds after the end of the last actual MIDI region at 76800 ticks (76800 divided by 480 equals 160 beats, which is 1:20 minutes at 120 bpm). I don't know why, but I also don't know if this can be considered a bug i.e. something Apple needs to fix. Did you check to uTrack24's documentation / get in touch with cymatic if you can somehow get the device to ignore the tempo tracks's end of track mark, or manually change the file's length on the device?

Edited by polanoid
  • Like 1
Link to comment
Share on other sites

The curious thing is that a few months ago it worked (so there was no 20 seconds). On the uTrack24 I have not made any updates. But I bought the new M1 iMac with Monterey 12.3.1. Unfortunately I did not check it to the day. But I have the feeling that since then the "error" occurs. Could this be related?

On the other hand, the user above describes the same problem already in 2020.

Link to comment
Share on other sites

BTW there's a lengthy discussion on this topic at midi.org, https://www.midi.org/midi/forum/4008-how-to-determine-the-length-of-a-standard-midi-file and someone also proposes a workaround - maybe that helps?

I also had the same problem and I solved it like this:
in logic, join and merge all tracks with all program changes and other controllers in one. When you export the midi file, the duration will be precise.:D
 
  • Like 1
Link to comment
Share on other sites

5 minutes ago, JT1312 said:

The curious thing is that a few months ago it worked (so there was no 20 seconds). On the uTrack24 I have not made any updates. But I bought the new M1 iMac with Monterey 12.3.1. Unfortunately I did not check it to the day. But I have the feeling that since then the "error" occurs. Could this be related?

No, from all I see here this is an old issue. Maybe you only exported single tracks before?

Edited by polanoid
  • Like 1
Link to comment
Share on other sites

1 minute ago, polanoid said:

BTW there's a lengthy discussion on this topic at midi.org, https://www.midi.org/midi/forum/4008-how-to-determine-the-length-of-a-standard-midi-file and someone also proposes a workaround - maybe that helps?

I also had the same problem and I solved it like this:
in logic, join and merge all tracks with all program changes and other controllers in one. When you export the midi file, the duration will be precise.:D
 

Yes, thank you. I had already tried that without success.

Link to comment
Share on other sites

9 minutes ago, JT1312 said:

Yes, thank you. I had already tried that without success.

Well I just checked, if I export a single region as MIDI file using „Export Selection as MIDI file“, it will not contain the marker 20 seconds after the region‘s end

Edited by polanoid
  • Like 1
Link to comment
Share on other sites

8 minutes ago, polanoid said:

Well I just checked, if I export a single region as MIDI file, it will not contain the marker 20 seconds after the region‘s end

I don't know if this works, but I put my test-logic-project as a public folder in my Google Drive. Can you do anything with it? Maybe our basic settings are indeed different.

https://drive.google.com/drive/folders/1Z5RhSZvYq1zKnisWGMdyrKOrkmXcCYpK?usp=sharing

This is exactly the project where 20 seconds are added to the midi file when I export it. Otherwise it is a completely empty and new Logic project.

Link to comment
Share on other sites

  • 4 weeks later...

There is now confirmation that this is a bug. A user in another forum writes: "I did the test now with the different export options on different Logic versions and indeed this is a bug! With Logic Pro X 10.3.1 on an old Macbook it still works correctly."

Link to comment
Share on other sites

If you think you have a reproducible bug, be sure to open an incident with Apple Support, describing exactly how to reproduce the problem and mentioning the earlier version where you think it worked properly.  That will make its way to the internal development team and give them what they need to find and fix it.

Edited by MikeRobinson
  • Like 1
Link to comment
Share on other sites

I have a couple possible work arounds to suggest.

One is to install and check out a command line tool called midicsv.  This can convert a midi file into a textual form.  The csv text form looks kind of like this:

#***********************************************************
#***************** CONVERT WITH csvmidi ********************
#***********************************************************
0, 0, Header, 0, 1, 1920
1, 0, Start_track
1, 0, Title_t, "LogicGenCsv"
1, 0, Tempo, 500000
1, 0, Time_signature, 4, 4, 24, 8
1, 604, Note_on_c, 0, 60, 80
1, 605, Note_on_c, 0, 64, 80
1, 606, Note_on_c, 0, 67, 80
1, 1084, Note_off_c, 0, 67, 64
1, 1085, Note_off_c, 0, 64, 64
1, 1086, Note_off_c, 0, 60, 64
#***************************************
1, 1086, End_track
0, 0, End_of_file

 

So you can edit this file, note the End_track line...I think that must be where the extra 20 seconds is getting added, but not entirely sure.  Anyway, when you install midicsv it also includes a companion command called csvmidi, which can be used to convert a csv back into midi again.  So in theory you can edit these error caused by potential bug in LogicPro and convert it back.

To install midicsv, you first need homebrew, which is installed like this:

https://brew.sh

Once you have homebrew installed, then you can install midicsv like this:

brew install midicsv

Then it will be available on the command line, you can read more about midicsv here:

https://www.fourmilab.ch/webtools/midicsv/

 

If you really want to get adventurous, I have a scripter script I made at some point which can generate midicsv during playback from within Scripter.  Then you just copy and paste the text output in the script window and use the csvmidi command to generate a midi file.  This works a lot like MidiFXFreeze.  The script can also export at 960 ppqn or any other resolution you want, LogicPro always exports at 480 FWIW.

MidiFxFreeze would be another option, its not expensive.  But I'm not sure how MidiFxFreeze determines the end of the midi file.  My Script uses the last midi event as the end of it...which also may not be correct, what you really want is for the end to line up with a bar boundary most likely....so...it may all come back to hand tweaking the CSV file.

Note to self, an interesting upgrade to my Scripter script would be an end of loop GUI item to specify where in time you want it to stop exporting midi and to set the end of midifile to that point in time, in order to get, for example, a perfect 4 bar midifile, regardless of where in time the last midi event is.

 

Edited by Dewdman42
Link to comment
Share on other sites

and by the way I can verify I am getting this same midi export too long result.  Here is the midicsv result from a simple 1 bar region of midi notes:

0, 0, Header, 0, 1, 480
1, 0, Start_track
1, 0, Channel_prefix, 0
1, 0, Title_t, "Inst 1"
1, 0, Instrument_name_t, "Untitled"
1, 0, Time_signature, 4, 2, 24, 8
1, 0, Key_signature, 0, "major"
1, 0, SMPTE_offset, 97, 0, 0, 0, 0
1, 0, Tempo, 500000
1, 151, Note_on_c, 0, 60, 80
1, 151, Note_on_c, 0, 64, 80
1, 151, Note_on_c, 0, 67, 80
1, 271, Note_off_c, 0, 60, 64
1, 271, Note_off_c, 0, 64, 64
1, 271, Note_off_c, 0, 67, 64
1, 360, Note_on_c, 0, 69, 80
1, 480, Note_off_c, 0, 69, 64
1, 600, Note_on_c, 0, 64, 80
1, 720, Note_off_c, 0, 64, 64
1, 720, Note_on_c, 0, 57, 80
1, 840, Note_off_c, 0, 57, 64
1, 960, Note_on_c, 0, 63, 80
1, 1080, Note_off_c, 0, 63, 64
1, 1200, Note_on_c, 0, 68, 80
1, 1320, Note_off_c, 0, 68, 64
1, 1440, Note_on_c, 0, 64, 80
1, 1560, Note_off_c, 0, 64, 64
1, 1680, Note_on_c, 0, 58, 80
1, 1800, Note_off_c, 0, 58, 64
1, 21120, End_track
0, 0, End_of_file

 

Note the End_track value of 21120.  At 480ppqn that is 44 beats, or the first beat of the 11th bar so to speak.  Why would LogicPro add 9 bars to an exported 1 bar midi region?  I'd call that a bug personally.

Edited by Dewdman42
Link to comment
Share on other sites

On 6/13/2022 at 3:43 AM, Dewdman42 said:

Why would LogicPro add 9 bars to an exported 1 bar midi region?  I'd call that a bug personally.

I bet this bug has something to do with the offset between  1 1 1 1 and the minimum possible song start of -8 1 1 1, 9 bars before 1 1 1 1. Coincidence? I think not ;) 

  • Like 1
Link to comment
Share on other sites

  • 11 months later...
6 hours ago, SpaceyBee said:

Did this bug get resolved? I am still having this problem. 20 secs added onto the end of every midi file exported from logic when the midi file is played back on the utrack24. Is there a workaround? 

Have you tried with 10.7.8 yet? Because if you did and

a) it still fails: No, the bug did not get resolved

b) it doesn't fail anymore: Yes, the bug did get resolved 

😉 

Link to comment
Share on other sites

You need to save a backup of your logicpro application bundle so that you can restore it of the new update is still broken or any other problem.  
 

Easiest way is to select the logicpro icon, right click and compress it into a zip file.  It probably not a bad idea to backup your preferences files also.

note you can manually fix the exported midi files using the midicsv tools I mentioned earlier but obviously that is time consuming and annoying as last resort.

Link to comment
Share on other sites

13 hours ago, SpaceyBee said:

if the bug still occurs is there a way to downgrade to a version where there was no bug? 

If you have a backup copy of Logic Pro 10.7.7 then you'll have the two apps installed on your Mac, 10.7.7 and 10.7.8 - and you can open either one at any moment. They're effectively two different apps. 

Link to comment
Share on other sites

Ok, I installed new Mac OS so I could upgrade Logic to the latest version and this problem still persists. I have downloaded HomeBrew and then midicsv but I don't understand how to load in a midi file for it to be edited? I have very little experience with using the terminal... 

Link to comment
Share on other sites

First export your midi file

Then use the Terminal cd to the folder where your midi file is located.

Then type the following command, substituting the name of your midi file:

midicsv test.mid

You should see something like this:

0, 0, Header, 0, 1, 480
1, 0, Start_track
1, 0, Channel_prefix, 0
1, 0, Title_t, "MIDI Region"
1, 0, Instrument_name_t, "Inst 1"
1, 0, Time_signature, 4, 2, 24, 8
1, 0, Key_signature, 0, "major"
1, 0, SMPTE_offset, 97, 0, 0, 0, 0
1, 0, Tempo, 500000
1, 360, Note_on_c, 0, 62, 80
1, 480, Note_off_c, 0, 62, 64
1, 600, Note_on_c, 0, 62, 80
1, 720, Note_off_c, 0, 62, 64
1, 960, Note_on_c, 0, 64, 80
1, 1080, Note_off_c, 0, 64, 64
1, 1080, Note_on_c, 0, 62, 80
1, 1200, Note_off_c, 0, 62, 64
1, 1200, Note_on_c, 0, 64, 80
1, 1200, Note_on_c, 0, 64, 80
1, 1320, Note_off_c, 0, 64, 64
1, 1320, Note_off_c, 0, 64, 64
1, 1320, Note_on_c, 0, 62, 80
1, 1440, Note_off_c, 0, 62, 64
1, 1560, Note_on_c, 0, 65, 80
1, 1680, Note_off_c, 0, 65, 64
1, 1680, Note_on_c, 0, 62, 80
1, 1800, Note_off_c, 0, 62, 64
1, 1920, End_track
0, 0, End_of_file

Fine, so you know it works.  Now do it again but this time we'll redirect the output into a text file

midicsv test.mid > test.out

Open the test.out file in your favorite text editor and c change the End_track line to whatever value you want so that its not too big.  Save the file.  Then execute the following command:

csvmidi test.out > test.mid

the above will overwrite your midi file with the new version where the end_track value has been change.

 

Link to comment
Share on other sites

11 hours ago, SpaceyBee said:

Ok, I installed new Mac OS so I could upgrade Logic to the latest version and this problem still persists. I have downloaded HomeBrew and then midicsv but I don't understand how to load in a midi file for it to be edited? I have very little experience with using the terminal... 

Argh you're right, this only seems to be fixed if you export a single MIDI track

Link to comment
Share on other sites

7 hours ago, Dewdman42 said:

First export your midi file

Then use the Terminal cd to the folder where your midi file is located.

Then type the following command, substituting the name of your midi file:

midicsv test.mid

You should see something like this:

0, 0, Header, 0, 1, 480
1, 0, Start_track
1, 0, Channel_prefix, 0
1, 0, Title_t, "MIDI Region"
1, 0, Instrument_name_t, "Inst 1"
1, 0, Time_signature, 4, 2, 24, 8
1, 0, Key_signature, 0, "major"
1, 0, SMPTE_offset, 97, 0, 0, 0, 0
1, 0, Tempo, 500000
1, 360, Note_on_c, 0, 62, 80
1, 480, Note_off_c, 0, 62, 64
1, 600, Note_on_c, 0, 62, 80
1, 720, Note_off_c, 0, 62, 64
1, 960, Note_on_c, 0, 64, 80
1, 1080, Note_off_c, 0, 64, 64
1, 1080, Note_on_c, 0, 62, 80
1, 1200, Note_off_c, 0, 62, 64
1, 1200, Note_on_c, 0, 64, 80
1, 1200, Note_on_c, 0, 64, 80
1, 1320, Note_off_c, 0, 64, 64
1, 1320, Note_off_c, 0, 64, 64
1, 1320, Note_on_c, 0, 62, 80
1, 1440, Note_off_c, 0, 62, 64
1, 1560, Note_on_c, 0, 65, 80
1, 1680, Note_off_c, 0, 65, 64
1, 1680, Note_on_c, 0, 62, 80
1, 1800, Note_off_c, 0, 62, 64
1, 1920, End_track
0, 0, End_of_file

Fine, so you know it works.  Now do it again but this time we'll redirect the output into a text file

midicsv test.mid > test.out

Open the test.out file in your favorite text editor and c change the End_track line to whatever value you want so that its not too big.  Save the file.  Then execute the following command:

csvmidi test.out > test.mid

the above will overwrite your midi file with the new version where the end_track value has been change.

If you do have midicsv running, and if your MIDI file only contains one constant tempo, you could even automatically replace the problematic line (which is always the end marker of the tempo track, which is always track 1) by using this command line

 

midicsv yourfile.mid | sed 's/1, .*, End_track/1, 100, End_track/' | csvmidi > yourfile_corrected.mid

This just sets the tempo track length to 100 ticks which is always OK when there are no tempo changes.

If there are tempo changes, you can replace the "100" by the desired length of the MIDI file (in ticks)

BTW @Dewdman42 your MIDI file example is format 0, and as I wrote above Logic 10.7.8 already exports these correctly (as can be seen in the example which is only 1920 ticks, i.e. 1 bar long)

Edited by polanoid
  • Love 1
Link to comment
Share on other sites

On 6/12/2022 at 7:48 PM, Dewdman42 said:

To install midicsv, you first need homebrew

You could also simply compile midicsv without installing it by cd'ing into the unpacked folder and simply type make in there, then start midicsv (csvmidi) from there as ./midicsv (./csvmidi).

This saves the step of installing homebrew

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...