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

Support to merge piece object with missing instruments? #77

Open
neldivad opened this issue Aug 12, 2024 · 0 comments
Open

Support to merge piece object with missing instruments? #77

neldivad opened this issue Aug 12, 2024 · 0 comments

Comments

@neldivad
Copy link

a = mp.chord('A4, E4, G4, B4') % (1/16, 1/16)
b = mp.chord('B4, E4, G4, B4') % (1/4, 1/4)
c = mp.chord('C4, E4, G4, B4') % (1/2, 1/2) 

t1 = mp.track(a*8, instrument=1)
t2 = mp.track(b*2, instrument=6)
t3 = mp.track(c, instrument=7)

part1 = mp.build(
    [t1, t2, t3], bpm=30 # 3 track piece
)

part2 = mp.build(
    [t1, t2], bpm=30, # 2 track piece
)

Suppose I add 2 tracks

(part1 + part2).play() # ok 
(part2 + part1).play() # not ok

The issue is that part2 starts with 2 instruments, so the beginning of the next piece would introduce a new instrument that is not initialized, thus failing the join operator.

The solution is to add a dummy track

a = mp.chord('A4, E4, G4, B4') % (1/16, 1/16)
b = mp.chord('B4, E4, G4, B4') % (1/4, 1/4)
c = mp.chord('C4, E4, G4, B4') % (1/2, 1/2) 

t1 = mp.track(a*8, instrument=1)
t2 = mp.track(b*2, instrument=6)
t3 = mp.track(c, instrument=7)

t4 = mp.track(mp.chord(''), instrument=7) # empty track

part1 = mp.build(
    [t1, t2, t3], bpm=30
)

part2 = mp.build(
    [t1, t2, t4], bpm=30, 
)

(part2 + part1).play() # now ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant