bspaans / python-mingus

Mingus is a music package for Python
GNU General Public License v3.0
860 stars 167 forks source link

How to play different instruments at the same time using a composition? #90

Open epbonacina opened 2 years ago

epbonacina commented 2 years ago

I've been trying to play different tracks using different instruments, but all tracks play the same instrument. When I execute the example below, the only thing I can hear is the Acoustic Grand Piano playing both tracks.

    instrument = MidiInstrument("Acoustic Grand Piano")
    instrument2 = MidiInstrument("Oboe")

    track_container = Track(instrument)
    track_container_2 = Track(instrument2)
    track_container.add_notes(['C-6', 'E-6', 'G-6', 'B-6'])
    track_container_2.add_notes(['E-6', 'G#-6', 'B-6', 'D-6'])

    composition = Composition()
    composition.add_track(track_container)
    composition.add_track(track_container_2)

    fluidsynth.play_Composition(composition, bpm=60)

If I switch the composition.add_track methods, as in the example below, the Oboe becomes the only audible instrument.


    instrument = MidiInstrument("Acoustic Grand Piano")
    instrument2 = MidiInstrument("Oboe")

    track_container = Track(instrument)
    track_container_2 = Track(instrument2)
    track_container.add_notes(['C-6', 'E-6', 'G-6', 'B-6'])
    track_container_2.add_notes(['E-6', 'G#-6', 'B-6', 'D-6'])

    composition = Composition()
    composition.add_track(track_container_2)
    composition.add_track(track_container)

    fluidsynth.play_Composition(composition, bpm=60)

If I pass the channels parameter to the fluidsynth.play_Composition method, nothing changes.

What is wrong with my codes? A composition should be able to play multiple instruments, right?

epbonacina commented 2 years ago

I made another example, using only tracks.

    track_container = Track()
    track_container_2 = Track()

    track_container.add_notes(['C-6', 'E-6', 'G-6', 'B-6'])
    track_container_2.add_notes(['E-6', 'G#-6', 'B-6', 'D-6'])

    fluidsynth.set_instrument(1,127)
    fluidsynth.play_Track(track_container, 1)
    fluidsynth.play_Track(track_container_2, 2)

I set the gunshot sound to play on channel 1, but both channels are playing this sound. What am I doing wrong?

cwurld commented 2 years ago

Hi. This is a bug. Essentially, all output goes to channel 1 and a channel only allows one instrument. It's fixed in my fork (https://github.com/cwurld/python-mingus).

In fact I am making some major changes. I am not maintaining python 2 compatibility. I have changed how the sequencer works. I am working on percussion. Also there is some code structure that seems odd to me.

While I very much appreciate all the work others have done on this project, I am not sure they will even want my contributions merged. So my fork might turn into a separate project. We will see. python-mingus-big-band?

Chuck

epbonacina commented 2 years ago

Thanks, Chuck. I'm using your fork now, and things seem to be working. I hope they merge your contributions.

b8d241b26a27cbcf2c7345393 commented 2 years ago

Thanks @cwurld ! I spent hours trying to find the cause in the sequencer without success. Long life to you.