fbpx
Skip to main content

MIDI Forum

Same instrument, sa...
 
Notifications
Clear all

Same instrument, same channel, different tracks?

7 Posts
3 Users
0 Reactions
8,772 Views
Jason
Posts: 433
Honorable Member
Topic starter
 

Is it common to have a single instrument for a single channel split over multiple tracks? What kind of issues might this potentially cause?

I have run in to one particular file from Warcraft 2 that is bunging up my program, and after pulling my hair out for nearly all of yesterday, I finally figured out that the problem (in my case) stems from the fact that there is a bank select/program change for the "pad sweep" at the end of track 3 for channel 3, but also a bank select/program change for pad sweep on channel 3 at the beginning of track 4.

Because of the way I group instruments together, when I insert a BANK LSB to go with the MSB that's present, track 3 is getting its length extended by 4 extra bytes, while track 4 loses 4 bytes, which corrupts the midi file.

I can probably fix it by adding an additional check to only group them if they are on the same track, but I wonder how common it is for this to happen.

 
Posted : 05/07/2021 6:41 am
Bavi_H
Posts: 267
Reputable Member
 

(Note: Your description of extending one track by 4 bytes and shortening another track by 4 bytes causing a corrupt MIDI file sounds like a bug in the way you handle track length values in the track headers. Having a discussion about the potential issues of having a channel on multiple tracks doesn't seem like it will be related to fixing a bug in handling track length values.)

The reasons I'd be interested in putting a channel on multiple tracks are when there's a single instrument sound that could be considered as multiple "parts" you might want to view on a separate staff notation. For example, the left and right hand parts of a piano part. Or if you want to show different drum sounds on their own staff. In those cases, you could put these parts on different tracks, but use the same channel. I have sometimes seen MIDI files with channel 10 drum notes split onto different tracks like this.

When a channel is on multiple tracks, you have to watch out for the tracks containing conflicting channel messages, for example, different volume or pitch bend. If there are conflicting messages, the only problem this causes is that the file might not play the same way in different MIDI players, or the file not play as the composer intended in all situations:

• If the conflicting messages have the same time position, some MIDI players might send the messages in increasing track order (the message on the last track wins because it was sent last), some MIDI players might send the messages in decreasing track order (the message on the first track wins because it was sent last), and some MIDI players might send them in an unpredictable order.

• If you put notes for a channel on multiple tracks, but you only put control messages for the channel on one of the tracks thinking that would be enough, then what happens if a MIDI player has that track muted? It might not send the control messages from the muted track and the notes of the other track won't play like you intended in that case.

• If you change the play position by fast forwarding or rewinding through the file, then restart playback, MIDI players will usually search backward to find control messages to send to make sure the output device is updated correctly. If there are conflicting messages for the same channel that are on different tracks, different MIDI players might find a different one of the conflicting messages first.

The thread SMF Format 1 Tracks and Channels discusses a track with multiple channels and a channel on multiple tracks.

In that thread, I gave an example of a file I made that inadvertently had a note start and a note end for the same channel, pitch, and time position on different tracks. In that example, I was a little too eager to reuse channels by putting the the main singer and backup singer parts on the same channel, and I ended up with that weird note glitch. If I made something like that again, I'd avoid using the same channel for different vocal parts unless I was completely out of channels.

The ideas I gave above (splitting a piano part into left and right hands, or splitting channel 10 drum sounds into different tracks) are more realistic use cases for putting the same channel on multiple tracks.

 
Posted : 05/07/2021 8:44 am
Jason
Posts: 433
Honorable Member
Topic starter
 

(Note: Your description of extending one track by 4 bytes and shortening another track by 4 bytes causing a corrupt MIDI file sounds like a bug in the way you handle track length values in the track headers. Having a discussion about the potential issues of having a channel on multiple tracks doesn't seem like it will be related to fixing a bug in handling track length values.)

Hmm, interesting. My main concern was the same instrument, same channel, different tracks. It sound like this is common, though not necessarily in the files I would normally play (mostly video game music from old DOS games, or files that are some form of video game music translations or covers). However, this one file IS from a video game, and I wonder if it was a mistake when they were making it. The bank select and program change at the end of track 3 have no notes afterwards. All notes, including a bank select/program change are in track 4.

[code type=markup]
[12885] 94460: b2 00 00 -- Bank Select MSB
[12889] 94460: b2 20 00 -- Bank Select LSB
[12893] 94460: c2 5f -- Program Change
[12896] 94460: b2 0a 36 -- Pan MSB
[12900] 94460: b2 5d 64 -- Effects 3 Depth
[12904] 94460: b2 5b 50 -- Effects 1 Depth
[12908] 94464: ff2f -- End of Track
[12911] MTrk:
[12920] 0: ff03 -- Sequence Name: Sweep pad
[12933] 0: b2 00 00 -- Bank Select MSB
[12937] 0: b2 20 00 -- Bank Select LSB
[12941] 0: b2 5b 50 -- Effects 1 Depth
[12945] 0: b2 5d 64 -- Effects 3 Depth
[12949] 0: b2 0a 36 -- Pan MSB
[12953] 0: c2 5f -- Program Change
[12956] 0: b2 07 7f -- Channel Volume MSB
[12961] 384: 92 3c 50 -- Note On
[12965] 384: b2 07 7f -- Channel Volume MSB
[12969] 384: 92 30 7f -- Note On
[12973] 480: b2 07 7d -- Channel Volume MSB
[/code]

I wanted to understand it so I can compensate appropriately. It was fairly easy for me to sort out once I understood what was going on (after HOURS of trying to figure out why inserting a bank LSB was messing up the file, even though it is identical to my MSB code. The LSB code was just a red herring, not actually the cause of the problem). In my file parser, I create an "instrument manipulator" for each instrument that appears in the file. I group by channel, program number, bank msb, and bank lsb. Until I loaded this particular file, that was "good enough". I didn't think about a single instrument appearing on multiple tracks. So now I also make sure they are on the same track as well for grouping purposes.

The track length problem occurred when I saved the file, even when making no real edits. When saving a file, I insert any "missing" program changes and bank selects, because I allow changing them all. When I do the inserts, I update the track length for the track the instrument is on. Because the instrument appears in both track 3 and 4, but I was grouping them without checking track number, I saw it as only being on track 3. So the two bank select LSBs (one at the end of track 3, and one at the beginning of track 4, byte offset 12889 and 12937 above) both increased the track length of track 3. Therefore, the marked track length for track 3 ended up 4 bytes too long, and track 4 (which should have been incremented by 4 bytes) ended up 4 bytes too short.

It's thankfully all sorted out now. I think :p Good news is that I made a few improvements to the code while trying to figure out the issue.

 
Posted : 05/07/2021 9:26 am
Jason
Posts: 433
Honorable Member
Topic starter
 

The thread SMF Format 1 Tracks and Channels discusses a track with multiple channels and a channel on multiple tracks.

The file linked to in that thread from
https://www.midi.org/forum/1670
is actually a perfect test of what I was experiencing. Half the instruments in this file wc2-48 are referenced in 2-3 tracks each. You can see in the screenshot every instrument displayed with multiples on the same channel is in several tracks, but the same channel. The number to the left of the colored square is the channel number.

I think it also just helped me realize issues I was seeing with percussion as well, because changing drum kits was not changing all of the related percussion I expected it to. Now I see that the percussion is also referenced across multiple tracks.

I just tried saving it, and it worked! No issues. I'm pretty sure if I did that yesterday, all the track lengths would be a disaster.

 
Posted : 05/07/2021 9:49 am
Jason
Posts: 433
Honorable Member
Topic starter
 

Hrm, I don't think I'm going to like the answer to this question, as it will add even more complexity for me...

Bank selects are per-channel, correct?

So if two tracks reference the same channel at the roughly the same time, and one channel issues a bank select, this will then affect both tracks?

So, say, track 1 instrument A and track 2 instrument A (or B) both play notes on channel 6. Halfway through, track 1 has a bank select to Variation Z. Does this mean track 2 instrument A (or B) are also switched to Variation Z? I have a feeling the answer is yes, and I'm going to need to deal with it properly.

 
Posted : 05/07/2021 8:40 pm
JohnG
Posts: 225
Estimable Member
 

Quite right, Bank Selects and Program changes are per channnel.

So, if a bank select is issued, whatever track it is issued on (it doesn't matter), any track using the same channel must use the new selection.
But my understanding of the specification is that NO CHANGE is made until the Program Change command is issued.

So you could have Bank Select MSB then LSB on one track but the Program Change on another track using the same channel.

It's not unusual, for instance, to split the left and right hand of piano onto seperate tracks but use the one channel.
Also, I've seen many files where the percussion is seperated into individual tracks, one per 'instrument', all pointing to channel 10.

JohnG.

 
Posted : 06/07/2021 1:03 am
Jason
Posts: 433
Honorable Member
Topic starter
 

Figured as much. So my old method of dealing with inserting bank selects was mostly correct, and worked perfectly for any file with a single track per channel. My new method takes tracks in to account, but I guess is being "too selective" and giving each track its own bank selects when that is not necessary. So now I will need to revert some of my changes, and combine the best of both methods.

If only I would test fewer midi files, I wouldn't run in to these sorts of problems 😉

 
Posted : 06/07/2021 8:18 am
Share: