Append Score

Hi,

we are trying to append two different quantized scores in one. Any idea?

Thank you!

PS
We did something like this:

performance1 = s.stop_transcribing()
perf1=performance1.to_score(quant1,title=“Looking at My Forks”, composer=“Michele Forchetta”)

wait(1.5)
s.start_transcribing()
s.fork(pianofrase, args=([90, 32, 58, 93], 0.8, 3))
s.fork(pianoaccordi)
s.fork(frase2, args=([59, 68, 65, 71], forte_piano_crescendo, 1.99))
s.wait_for_children_to_finish()

performance2 = s.stop_transcribing()
perf2=performance2.to_score(quant2,title=“Looking at My Forks”, composer=“Michele Forchetta”)
perf1.append(perf2)
perf1.show()

This isn’t that simple to do, unfortunately. I guess the reason is that it’s never been a priority to make simple, since for the most part that kind of thing would be done after exporting to abjad, or to music_xml.

What’s your motivation for wanting to do it? Maybe if I understand that, I can look into making it easier to do. For instance, is the goal a PDF made with LilyPond?

Thank you Marc,

yes, the idea is to merge more scores in a unique one in a .pdf, for instance. I tried.

Okay, so there’s a couple things. Using SCAMP, you can combine scores like this:

for part1, part2 in zip(score1.parts, score2.parts):
    # # Uncomment this line to avoid a duplicate time signature
    # part2.measures[0].show_time_signature = False
    part1.measures.extend(part2.measures)

…at which point the measures of the second score have been tacked on to the end of the first. That’s probably not what you want, though, since there’s no real division between the scores.

My guess is what you want to do is do it with abjad, which is the underlying library that SCAMP uses to render the LilyPond, and then the PDF. You could do something like this, assuming you have SCAMP score objects score1 and score2:

score1_block = abjad.Block(name="score1")
score1_block.items.append(score1.to_abjad(wrap_as_file=False))

score2_block = abjad.Block(name="score2")
score2_block.items.append(score2.to_abjad(wrap_as_file=False))

lilypond_file = abjad.LilyPondFile(items=[score1_block, score2_block])
abjad.show(lilypond_file)

I suspect that’s what you want. You can surely add movement title, composer, movement headers via abjad as well (take a look into the abjad documentation for details).

For reference, here’s the whole script I was using to test this:

import abjad
from scamp import *
import random

# one way of setting an initial tempo
s = Session(tempo=100)
oboe = s.new_part("oboe")
bassoon = s.new_part("bassoon")


# define a function for the oboe part
def oboe_part():
    # play random notes until we have
    # passed beat 7 in the session
    end_beat = s.beat() + 8
    while s.beat() < end_beat - 1:
        pitch = int(random.uniform(67, 79))
        volume = random.uniform(0.5, 1)
        length = random.uniform(0.25, 1)
        oboe.play_note(pitch, volume, length)
    # end with a note of exactly the right
    # length to take us to the end of beat 8
    oboe.play_note(80, 1.0, end_beat - s.beat())


# define a function for the bassoon part
def bassoon_part():
    # simply play quarter notes on random
    # pitches for 8 beats
    end_beat = s.beat() + 8
    while s.beat() < end_beat:
        bassoon.play_note(
            random.randint(52, 59), 1, 1
        )


print("FIRST SCORE")
s.start_transcribing()
# start the oboe and bassoon parts as two parallel child processes
s.fork(oboe_part)
s.fork(bassoon_part)
# have the session wait for the child processes to finish (return)
s.wait_for_children_to_finish()
performance = s.stop_transcribing()
score1 = performance.to_score()

print("SECOND SCORE")
performance2 = s.start_transcribing()
# start the oboe and bassoon parts as two parallel child processes
s.fork(oboe_part)
s.fork(bassoon_part)
# have the session wait for the child processes to finish (return)
s.wait_for_children_to_finish()
s.stop_transcribing()
score2 = performance2.to_score()

score1_block = abjad.Block(name="score")
score1_block.items.append(score1.to_abjad(wrap_as_file=False))

score2_block = abjad.Block(name="score")
score2_block.items.append(score2.to_abjad(wrap_as_file=False))

lilypond_file = abjad.LilyPondFile(items=[score1_block, score2_block])
# open up a PDF
abjad.show(lilypond_file)
# ...or export it to a file
abjad.persist.as_pdf(lilypond_file, "doublescore.pdf")

Thank you!