:orphan: Double Score ============ *Example script* (scamp): `examples/Notation & engraving/Abjad & pymusicxml tweaks/double_score.py `__ *Download:* :download:`double_score.py ` Records two performances, turns them into scores, renders to abjad, and sticks them together! *Topics:* :doc:`Notation & engraving › Abjad & pymusicxml tweaks ` .. raw:: html
score
.. raw:: html
.. code-block:: python 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(title="Score 2") # Header for score 1 header1_block = abjad.Block(name="header") header1_block.items.append('piece = "First Piece"') score1_block = abjad.Block(name="score") score1_block.items.append(header1_block) score1_block.items.append(score1.to_abjad(wrap_as_file=False)) # Header for score 2 header2_block = abjad.Block(name="header") header2_block.items.append('piece = "Second Piece"') score2_block = abjad.Block(name="score") score2_block.items.append(header2_block) score2_block.items.append(score2.to_abjad(wrap_as_file=False)) lilypond_file = abjad.LilyPondFile(items=[score1_block, score2_block]) abjad.show(lilypond_file) # abjad.persist.as_pdf(lilypond_file, "doublescore.pdf")