def play_micro_divisions(divs): """ Plays one octave of microtones quantized to 1/divs semitones. Parameters ---------- divs : int 1 to 16 A value of 1 produces 1/1 = 1 = 100 cents (standard semitonal tuning) a value of 2 produces 1/2 = .5 = 50 cents (quarter tone tuning) and so on. """ def playmicro(score, key, rhy, divs): inc = 1 / divs for i in range(12 * divs + 1): note = Note(time=score.now, duration=rhy, pitch=key) score.add(note) key += inc yield rhy # divs can be a value from 1 to 16 track0 = MidiFile.metatrack(microdivs=divs) track1 = Seq() score = Score(out=track1) score.compose(playmicro(score, 60, .5, divs)) file = MidiFile("microdivs.mid", [track0, track1]).write() print(f"Wrote '{file.pathname}'.")
def play_micro_pentatonic(): """ Plays a lovely microtonal pentatonic scale consisting of the prime numbered harmonics in the 5th octave of the harmonic series: Harmonic number: 17 19 23 29 31 34 Nearest pitch: C# D# F# A# B C# Cent adjustment: +5 -3 +28 +29 +45 +5 """ # the harmonic numbers harms = [17, 19, 23, 29, 31, 34] # convert into ascending intervals of a one octave pentatonic scale penta = deltas(temper(divide(harms, 17))) #penta = scale(5*4, 60, deltas(semis)) # It's good practice to add any metadata such as tempo, midi instrument # assignments, micro tuning, etc. to track 0 in your midi file. track0 = MidiFile.metatrack(ins={i: Vibraphone for i in range(16)}, microdivs=8) # Track 1 will hold the composition. track1 = Seq() # Create a score and give it tr1 to hold the score event data. score = Score(out=track1) def playpenta(score, num, dur, amp, keys): pat = jumble(keys) for _ in range(num): k = next(pat) n = Note(time=score.now, duration=dur * 2, pitch=k, amplitude=amp) score.add(n) yield odds(.2, 0, dur) top = playpenta(score, 90, .3, .4, scale(72 + 12, 10, *penta)) bot = playpenta(score, 45, .6, .5, scale(48, 10, *penta)) low = playpenta(score, 23, 1.2, .8, scale(24, 10, *penta)) score.compose([top, [.3 * 4, bot], [.3 * 12, low]]) # Write a midi file with our track data. file = MidiFile("micropenta.mid", [track0, track1]).write() print(f"Wrote '{file.pathname}'.")
prefers motive2 over motive1. """ for i in range(numtimes): if odds(qtime(i, numtimes, 1.0, 0.0, .01)): score.compose(motive1(score, between(lowoctave, highoctave), limit, chan)) else: score.compose(motive2(score, between(lowoctave, highoctave), limit, chan)) yield qtime(i, numtimes, hiwait, lowwait, .2) if __name__ == '__main__': # It's good practice to add any metadata such as tempo, midi instrument # assignments, micro tuning, etc. to track 0 in your midi file. track0 = MidiFile.metatrack(ins={0: AcousticGrandPiano, 1: Marimba, 2: OrchestralHarp}) # Track 1 will hold the composition. track1 = Seq() # Create a score and give it tr1 to hold the score event data. score = Score(out=track1) #play = motive1(q, 5, 4, 0) #play = motive2(q, 5,5,1) #play = gesture1(q, 10, .5, 0) #play = gesture2(q, 10, .5, 5, 0) #play = gesture3(q, 20, .5, 5, 0, 3, .2) #play = gesture4(q, 30, 2, 7, 11, 0, 1.6,.2) # The gesture to play play = [gesture4(score, 60, 2, 7, 11, 0, 1.0, .2), gesture4(score, 40, 5, 7, 11, 1, 1.6, .2), gesture4(score, 34, 3, 6, 11, 2, 2.0, .2)] # Create the composition.