!apt update
!apt install musescore -y
!pip install arvo
from music21 import * # import everything from music21
from arvo import tools, isorhythm, minimalism, tintinnabuli
environment.set("musescoreDirectPNGPath", "/usr/bin/musescore") # tell music21 where MuseScore is installed
solfege = stream.Stream([
note.Note("C4"), note.Note("D4"), note.Note("E4"), note.Note("F4"),
note.Note("G4"), note.Note("A4"), note.Note("B4"), note.Note("C5"),
])
solfege.show()
solfege.show('midi')
isor_example1 = isorhythm.create_isorhythm(
["C4", "D4", "E4", "F4", "G4", "A4", "B4", "C5"], # 8 items
[1, 0.5, 0.5, 2] # 4 items, sums to 4 to fit with a 4/4 time signature
)
isor_example1.show()
isor_example2 = isorhythm.create_isorhythm(
["C4", "D4", "E4", "F4", "G4", "A4", "B4"], # 7 items
[1, 0.5, 0.5, 2] # same as example 1
)
isor_example2.show()
track1a_n = ["E4", "C4", "G4", "F4", "B4", "A4"] # _n for notes, 6 items in C major
track1a_d = [1, 0.5, 0.25, 0.5, 1, 0.75, 0.5, 0.5, 1, 2] # _d for durations, 10 items, sums to 8
track1a_m = isorhythm.create_isorhythm( # _m for melody
track1a_n,
track1a_d
)
track1a_m.show()
track1a_m.show('midi')
solfege.show()
solfege_addf = minimalism.additive_process(
solfege,
repetitions = [1],
direction = minimalism.Direction.FORWARD, # FORWARD, BACKWARD, INWARD, OUTWARD
)
solfege_addf.show()
solfege_addb = minimalism.additive_process(
solfege,
repetitions = [1],
direction = minimalism.Direction.BACKWARD,
)
solfege_addb.show()
solfege_subf = minimalism.subtractive_process(
solfege,
repetitions = [1],
direction = minimalism.Direction.FORWARD,
)
solfege_subf.show()
solfege_subb = minimalism.subtractive_process(
solfege,
repetitions = [1],
direction = minimalism.Direction.BACKWARD,
)
solfege_subb.show()
track1b_base = isorhythm.create_isorhythm(
["G4", "C4", "Ab5", "A4", "Bb5", "Ab5", "G5", "Eb4"],
[1.5, 0.25, 2.25, 1, 0.25, 0.25, 0.5, 2]
)
track1b_base.show()
track1b_base.show('midi')
track1b_m = minimalism.additive_process(
track1b_base,
repetitions = [1],
direction = minimalism.Direction.FORWARD,
)
track1b_m.append(minimalism.subtractive_process(
track1b_base,
repetitions = [1],
direction = minimalism.Direction.BACKWARD,
))
track1b_m.show()
track1b_m.show('midi')
import random
random.seed(75634928)
solfege_shuffle = [n.nameWithOctave for n in solfege.notes] # iterates the stream and extract note names
random.shuffle(solfege_shuffle)
solfege_shuffle = tools.notes_to_stream(solfege_shuffle)
solfege_shuffle.show()
import copy
import random
random.seed(475386)
track1c_n = track1a_n.copy() # copy to avoid overwriting with shuffled lists
random.shuffle(track1c_n) # shuffling the notes in place
track1c_m = isorhythm.create_isorhythm(
track1c_n, # shufffled notes...
track1a_d # ... with the same durations to keep the beat
)
track1c_m.show()
track1c_m.show('midi')
m_voice = stream.Stream([
note.Note("C4"), note.Note("D4"), note.Note("E4"), note.Note("F4"),
note.Note("G4"), note.Note("A4"), note.Note("B4"), note.Note("C5")
])
t_voice = tintinnabuli.create_t_voice(
m_voice = m_voice,
t_chord = ["C", "E", "G"],
position = 2,
direction = tintinnabuli.Direction.UP
)
tin_score = stream.Score()
tin_score.insert(m_voice)
tin_score.insert(t_voice)
tin_score.show()
tin_score.show('midi')
track2a_m = tintinnabuli.create_t_voice(
m_voice = track1a_m,
t_chord = ["C", "E", "G"],
position = 1,
direction = tintinnabuli.Direction.UP
)
track2b_m = tintinnabuli.create_t_voice(
m_voice = track1b_m,
t_chord = ["C", "Eb", "G", "Bb"],
position = 1,
direction = tintinnabuli.Direction.DOWN
)
track2c_m = tintinnabuli.create_t_voice(
m_voice = track1c_m,
t_chord = ["C", "E", "G", "Bb"],
position = 2,
direction = tintinnabuli.Direction.UP_ALTERNATE
).transpose("P8")
# Track 1
track1 = stream.Stream()
track1.append(track1a_m)
track1.append(track1b_m)
track1.append(track1c_m)
# Track 2
track2 = stream.Stream()
track2.append(track2a_m)
track2.append(track2b_m)
track2.append(track2c_m)
# Assemblage
tracks = stream.Score()
tracks.insert(track1)
tracks.insert(track2)
tracks.show('midi')
# Offset track 2b
track2b_offset = stream.Stream(note.Rest(duration.Duration(1))) # a 1 quarter length rest
track2b_offset.append(track2b_m) # append the melody to the rest
track2b_offset = track2b_offset.splitAtQuarterLength(track2b_m.quarterLength)[0] # trim the extra lenght
# Rebuild track 2
track2 = stream.Stream()
track2.append(track2a_m)
track2.append(track2b_offset)
track2.append(track2c_m)
# Assemblage
tracks = stream.Score()
tracks.insert(track1)
tracks.insert(track2)
tracks.show('midi')
import copy
solfege_alterdur = copy.deepcopy(solfege)
solfege_alterdur = isorhythm.create_isorhythm(
solfege,
tools.durations_to_stream([1, 1.5, 1, 1.5, 1, 1, 0.5, 0.5])
)
solfege_alterdur.show()
import copy
def down_beat_note(x, step):
bn_s = stream.Stream()
split_at = 0.0 # first split
while split_at < x.quarterLength:
track_split = copy.deepcopy(x)
if split_at != 0.0:
track_split = track_split.splitAtQuarterLength(split_at)[1]
measure_note = track_split[0]
measure_note.duration = duration.Duration(step)
bn_s.append(track_split[0])
split_at += step
return(bn_s)
solfege_1st = down_beat_note(solfege_alterdur, step = 4)
solfege_1st.show()
solfege_chords = stream.Stream()
for n in solfege_1st.notes:
solfege_chords.append(chord.Chord([n, n.transpose("M3"), n.transpose("P5")]))
solfege_chords.show()
track3a_1st = down_beat_note(track1a_m.flatten(), step = 4)
track3a_chords = stream.Stream()
for n in track3a_1st.notes:
track3a_chords.append(chord.Chord([n, n.transpose("M3"), n.transpose("P5")]))
track3b_1st = down_beat_note(track1b_m.flatten(), step = 4)
track3b_chords = stream.Stream()
for n in track3b_1st.notes:
track3a_chords.append(chord.Chord([n, n.transpose("m3"), n.transpose("P5")])) # m3 for minor third
track3c_1st = down_beat_note(track1c_m.flatten(), step = 4)
track3c_chords = stream.Stream()
for n in track3c_1st.notes:
track3a_chords.append(chord.Chord([n, n.transpose("M3"), n.transpose("P5")]))
# Assembles tracks
track3 = stream.Stream()
track3.append(track3a_chords)
track3.append(track3b_chords)
track3.append(track3c_chords)
# Lower the pitch on one octave
track3 = track3.flatten().transpose("P-8")
track3.show()
tracks = stream.Score()
tracks.insert(track1)
tracks.insert(track2)
tracks.insert(track3)
tracks.show()
tracks.show('midi')
!mkdir music
track1.write("midi", fp = "music/track1.midi")
track2.write("midi", fp = "music/track2.midi")
track3.write("midi", fp = "music/track3.midi")