Rainbow-Dreamer / musicpy

Musicpy is a music programming language in Python designed to write music in very handy syntax through music theory and algorithms.
https://musicpy.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
1.27k stars 124 forks source link

Drum parts will show up as piano if it starts earlier than piano during piece. #72

Closed neldivad closed 2 months ago

neldivad commented 2 months ago

Current fix is to change drum instrument so it doesn't have collision with piano (but your exported midi will not play sound in DAW), or to use different piano instrument and reserve instrument 1 for drums.

# p = piano 
# b = bass 
# s = string 
# d = drum

intro = mp.piece(
    tracks=[
        intro_p,
        intro_b,
        mp.chord(''), # empty insturment channel
        intro_d,
    ],
    instruments=[
        1, 
        35,
        41,
        1
    ],
    start_times=[
        0, # piano starts first
        8,
        24,
        8, # drum starts later
    ],
    channels=[1, 2, 3, 9], # channel 9 is drum channel
    bpm=180
)

verse = mp.piece(
    tracks=[
        verse_p,
        verse_b,
        verse_s,
        verse_d,
    ],
    instruments=[
        1, 
        35,
        41,
        1 # export bug with drum if piano starts later than drum
    ],
    start_times=[
        16, # piano starts later
        0,
        0,
        0
    ],
    channels=[1,2,3,9],
    bpm=180
)

chorus = mp.piece(
    tracks=[
        ch_p,
        ch_b,
        ch_s,
        ch_d,
    ],
    instruments=[
        1, 
        35,
        41,
        1
    ],
    start_times=[
        0, # simultaneous start also share the same issue
        0,
        0,
        0
    ],
    channels=[1,2,3,9],
    bpm=180
)

song = (intro | verse | chorus)

2024-08-03 06_01_06-● rolling_girl_demo ipynb - mido-proj - Visual Studio Code

Rainbow-Dreamer commented 2 months ago

Thanks for the feedback, I reproduced this bug with the newest version, and find how to fix this bug, when concatenating pieces it uses the method "merge_track" of piece class, there is a parameter called "ind_mode" which decides how to find the track of piece B to append to the track of piece A, the default value is 0, which uses the instrument number to match the track, I changed it to 1, which uses the current track number to match, and this solves the issue, when you try it again, the drum part will appear in the correct track. You can download the latest code from github, later I will update a new version.