Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change channel function #123

Open
CNelias opened this issue Jan 8, 2020 · 6 comments
Open

change channel function #123

CNelias opened this issue Jan 8, 2020 · 6 comments
Labels
enhancement good first issue Suitable issue for newcomer contributors up for grabs

Comments

@CNelias
Copy link
Member

CNelias commented Jan 8, 2020

Selecting the instrument of a track is usually done by adding a program change event to the track which describes when to change and what instrument to use.

This, however, is not the case when dealing with drums. The MIDI convention is that notes to be rendered as drums have to be on the channel 10.
I propose to add an internal attribute to the MIDITrack structure that describes the channel to be used when calling the addnotes! function. That way the notes would be directly send to the drum channel without having to modify them.

Then, the constructor of MIDITrack could be modified to accept an instrument argument in order to add the correct program change event or update the channel attribute of the track so that the instrument of the MIDI track is correct upon synthesis.

What do you think ?

@Datseris
Copy link
Member

Datseris commented Jan 8, 2020

We have programchange as a function implemented here, it is just untested. The first step is to test it and see how well it works, because of #96

The only difficulty I see here is that this field that you suggest adding to the MIDITrack should also be somehow recovered when reading a MIDI file from disk. How do you think this could be done?

@CNelias
Copy link
Member Author

CNelias commented Jan 14, 2020

programmchange should of course be used since it has already been written, the only issue is that the current implementation will not be applicable to drums since drums sounds works differently than other instruments in MIDI.

Concerning your second point : after thinking about it in more detail I don't think the modification I suggested is necessary. We can modify the programmchange function to treat the drum notes themselves directly by assigning them to the correct channel. I'll see if I can implement it myself soon.

@Datseris
Copy link
Member

The function is here : https://github.com/JuliaMusic/MIDI.jl/blob/master/src/miditrack.jl#L312-L317 (and it should also be changed to accept the channel as a standard UInt8, i.e. from 0 to 127 instead of 1 to 128).

But I wonder, isn't it easier to simply write the drum notes directly on channel 10? You can specify the channel of each note. This is how I do it when I create drums exercises for myself, as e.g. here https://juliamusic.github.io/JuliaMusic_documentation.jl/dev/blog/garibaldi_dragadiddle/

@CNelias
Copy link
Member Author

CNelias commented Jan 15, 2020

If you are creating a MIDI file from scratch you can directly assign the notes to channel 10 yes.
In some situations however, like when you extract a MIDI file from a project (cubase or reaper) the channel information gets lost. In those cases it would be nice if we could just do programmchange(REAPERnotes, instrument = "drums") or something equivalent.

@Datseris
Copy link
Member

Ah now I finally see. Okay, what you want is solved by defining a dictionary that maps instrument strings (e.g. "drums") to channel numbers. If the second argument of programmchange is Integer, just use that number. If second argument is string use the result of the dictionary (via multiple dispatch).

@Datseris
Copy link
Member

programmchange(REAPERnotes, instrument = "drums")

What is asked here is as simple as

CHANNEL = 9
newnotes = [Note(n.pos, n.vel, ..., CHANNEL) for n in oldnotes]

perhaps it can be added as a convenience function changechannel and changechannel!, but other than that, no reason to do anything more complicated.

@Datseris Datseris changed the title Add attribute representing channel to MIDITrack objects ? change channel function Apr 18, 2021
@Datseris Datseris added the good first issue Suitable issue for newcomer contributors label Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Suitable issue for newcomer contributors up for grabs
Projects
None yet
Development

No branches or pull requests

2 participants