Beispiel #1
0
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}'.")
Beispiel #2
0
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}'.")
Beispiel #3
0
    # random pattern of section lengths.
    pat = choose(seclens)
    # iterate all the min and max key numbers
    for low, high in zip(minkeys, maxkeys):
        # get the section's duration
        secdur = next(pat)
        # sprout the next section
        score.compose(register(score, rhy, secdur, low, high, .4))
        # wait till end of section
        yield secdur


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: Harpsichord})
    # 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)
    # Lower bound on keynum choices
    minkeys = [
        60, 59, 58, 57, 56, 55, 54, 53, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
        62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
        80, 82, 83, 84, 85, 86, 87, 88, 89, 89
    ]
    # Upper bound on keynum choices
    maxkeys = [
        62, 63, 64, 65, 66, 67, 68, 69, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
        70, 70, 70, 70, 70, 70, 70, 71, 72, 73, 74, 76, 79, 83, 86, 88, 89, 89,
        89, 89, 89, 89, 89, 89, 89, 89, 89, 89
Beispiel #4
0
    101.25, 16, 100, 15.5, 99.5, 16.5, 98.25, 15, 97.25, 16.5, 96.25, 17.25,
    95.25, 18, 94, 19.5, 93, 20.25, 92.5, 21, 91.5, 22, 90, 23, 89.5, 24, 88,
    25.25, 87.25, 26, 86, 27, 85.25, 28, 84, 29.5, 83, 30.5, 82.25, 31, 81,
    32.25, 80.25, 33, 79.25, 34.25, 78, 35.5, 77.25, 36, 76, 37.25, 75.5, 38,
    74.25, 39.25, 73, 40.5, 72.5, 41, 71.25, 42.5, 70, 43.25, 69, 44, 68.5, 45,
    67.5, 46, 66.25, 47, 65.5, 48, 64, 49.25, 63, 50, 62.5, 51, 61.25, 52, 60,
    53.5, 59.25, 54, 58, 55.25, 57, 56.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
]

arf = [0, 3, 7, 0, 3, 7, 0, 3, 7, 0, 3, 7, 0, 3, 7, 0]

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(microdivs=4)
    # Track 1 holds the composition.
    track1 = Seq()
    # Create a score and give it tr1 to hold the score event data.
    score = Score(out=track1)
    # Create the composition.
    score.compose([
        brush(score,
              length=1000,
              pitch=pphase,
              rhythm=1 / 16,
              duration=1,
              amplitude=0.75,
              instrument=9,
              microdivs=4),
        brush(score,
Beispiel #5
0
    for i in shape:
        k = tone + i
        # play current tone in melody
        n = Note(time=score.now, duration=dur, pitch=min(k,127), amplitude=amp, instrument=0)
        score.add(n)
        if (levels > 1):
            # sprout melody on tone at next level
            score.compose(sierpinski(score, (k + trans), shape,
                        trans, levels - 1, dur / num,  amp))
        yield dur
    

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()
    # Track 1 will hold the composition.
    track1 = Seq()
    # Create a scheduler and give it t1 as its output object.
    score = Score(out=track1)

    # Create the composition. Specify levels and melody length with care!
    # The number of events that are generateed is exponentially related to
    # the length of the melody and the number of levels. For example the
    # first compose() generates 120 events, the second 726, and the third 2728!
    score.compose(sierpinski(score, keynum('a0'), [0, 7, 5], 12, 4, 3, .5))
    #score.compose(sierpinski(score, keynum('a0'), [0, 7, 5], 8, 5, 7, .5))
    #score.compose(sierpinski(score, keynum('a0'), [0, -1, 2, 13], 12, 5, 24, .5))
 
    # Write the tracks to a midi file in the current directory.
    file = MidiFile("sierpinski.mid", [track0, track1]).write()
Beispiel #6
0
        midi = Note(time=score.now, duration=rhy + .2, pitch=melody, amplitude=amp, instrument=1)
        score.add(midi)
        # add decorations to the clarinet melody
        if high:
            score.compose([ahead, flute(score, melody, ahead)])
            score.compose([ahead * 2, harp(score, melody, rhy / 4)])
        elif (rhy == 3/4):
            score.compose([1/2, cello(score, melody)])
        yield rhy


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.
    inst = {0: Flute, 1: Clarinet, 2: Cello, 3: OrchestralHarp}
    track0 = MidiFile.metatrack(ins=inst)
    # 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)
    # Start our composer in the scheduler, this creates the composition.
    score.compose(ghosts(score))
    # Write a midi file with our track data.
    file = MidiFile("ghosts.mid", [track0, track1]).write()
    print(f"Wrote '{file.pathname}'.")

    # To automatially play demos use setmidiplayer() and playfile().
    # Example:
    #     setmidiplayer("fluidsynth -iq -g1 /usr/local/sf/MuseScore_General.sf2")
    #     playfile(file.pathname)
Beispiel #7
0
    # Stop playing when score time is >= end.
    while score.now < end:
        # Get the next key number.
        knum = next(pattern)
        # Create a midi note to play it.
        note = Note(time=score.now, duration=rate, pitch=knum, amplitude=.9)
        # Add the midi note to the score.
        score.add(note)
        # Return the amount of time until this composer runs again.
        yield rate


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()
    # 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)
    # Convert Reich's notes to a list of midi key numbers to phase.
    keys = keynum("e4 f# b c#5 d f#4 e c#5 b4 f# d5 c#")
    # Create two composer generators that run at slightly different
    # rates and cause the phase effect.
    pianos = [
        piano_phase(score, 20, keys, .167),
        piano_phase(score, 20, keys, .170)
    ]
    # Create the composition.
    score.compose(pianos)
    # Write the tracks to a midi file in the current directory.
Beispiel #8
0
        spect = rmspectrum([hertz(k) for k in keys1],
                           [hertz(k) for k in keys2])
        # convert to keynums
        keys3 = spect.keynums(quant=1, unique=True, minkey=21, maxkey=108)
        # sprout composers to play inputs and output
        playn = pick(3, 4, 5)
        score.compose(accompaniment(score, playn, dur, keys1, keys2))
        score.compose(melody(score, playn, dur,
                             keys3))  # do it again after composers finish
        yield (dur * playn * 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: Marimba, 1: Clarinet})
    # 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)
    # Musical material is the cycle of fourths.
    keys = scale(40, 12, 5)
    # Surface rhythm
    rhy = intempo(.25, 74)
    # Create the composition.
    score.compose(rmfunky(score, 24, rhy, keys))
    # Write the tracks to a midi file in the current directory.
    file = MidiFile("rm.mid", [track0, track1]).write()
    print(f"Wrote '{file.pathname}'.")

    # To automatially play demos use setmidiplayer() and playfile().
Beispiel #9
0
            k = keynum(next(melody)) + (shift * 12)
            r = intempo(r, 200)
            m = Note(time=score.now + n,
                     duration=r,
                     pitch=k,
                     amplitude=.5,
                     instrument=chan)
            score.add(m)
            n += r
        yield n


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: StringEnsemble1})
    # 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)
    # Compose a 4 voice texture with these octave transposition factors.
    voices = [-1, 0, 1, 2]
    composers = [composer_stephen_foster(score, 25, t) for t in voices]
    # Create the composition.
    score.compose(composers)
    # Write the seqs to a midi file in the current directory.
    file = MidiFile("foster.mid", [track0, track1]).write()
    print(f"Wrote '{file.pathname}'.")

    # To automatially play demos use setmidiplayer() and playfile().
    # Example:
Beispiel #10
0
    melody = [[36, 43.1, 46], [42.6, 50.2], [38.2, 48, 51.8], [39.8, 46, 54.6],
              [54.6, 62.2, 66.6], [57.3, 66.6, 69.3], [58, 62.2, 67.1],
              [36, 45.3, 48], [60, 66.6, 69.3], [46, 55.1, 60],
              [42.6, 50.2, 57.3], [46, 55.1, 60], [57, 66.6, 69.3],
              [57.3, 66.6, 69.3], [54.6, 62.2, 66.6]]

    # Amplitude scaler to adapt to different sound fonts. this is for fluidsynth
    def A(a):
        return ([s * 1.35 for s in a] if type(a) is list else a * 1.5)


    # Microtonal divisions of the semitone. 2 is quartertone (50 cents) etc.
    microdivs = 7
    # 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(microdivs)})
    # Track 1 holds the composition.
    track1 = Seq()
    # Create a score and give it tr1 to hold the score event data.
    score = Score(out=track1)
    # The sections of the piece
    s1 = spray(score,
               pitch=48,
               duration=3,
               rhythm=[1, .5],
               amplitude=A([.3, .35, .4]),
               band=scale1,
               end=40)
    s2 = spray(score,
               pitch=48,
               duration=3,
# Plain Hunt change ringing for 10 bells.
items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
rules = [[0, 2, 1], [1, 2, 1]]
items = allrotations(items, rules, False, True)
m = MidiSeq.metaseq(ins={
    0: TubularBells,
    1: TubularBells,
    2: TubularBells,
    3: TubularBells
},
                    tuning=4)
s = MidiSeq()
q = Scheduler(s)
q.compose(playbells(q, items, _conventry_fkeys, .25, .6, .8))
f = MidiFile("coventry.mid", [m, s]).write()

csoundac_score_node = CsoundAC.ScoreNode()
csoundac_score = csoundac_score_node.getScore()
musx_csoundac.to_csoundac_score(f, csoundac_score)

print("Generated:")
print(csoundac_score.getCsoundScore())

orc = '''
sr = 48000
ksmps = 128
nchnls = 2
0dbfs = 100

; Ensure the same random stream for each rendering.
Beispiel #12
0
    "af3 ef4 gf bf ef5 gf cf6", "af3 ef4 f bf df5 f5 bf5",
    "gf3 df4 af ef af cf6 ef", "gf3 df4 bf d5 f bf d6",
    "a3 c4 d fs bf df5 gf bf df6", "bf3 cs e gs c5 d gs c6",
    "c4 d f a4 cs5 e a", "cs4 e fs bf d5 f", "fs4 g bf d5 fs a",
    "fs4 a b ds5 es gs", "f4 bf d5 e g", "e4 af cs5 d", "d4 g b cs5 e",
    "cs4 f bf b f5", "b3 e4 af bf", "af3 cs4 f g", "gf3 cf4 ef f"
])

cello_talea = rhythm('h q. h h e e q. e e e e q. e e h', tempo=80)

cello_color = keynum('c6 e d f# bf5')

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: Violin})
    # 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)
    # Create the piano and cello composers.
    piano = brush(score,
                  length=len(piano_talea) * 8 + 14,
                  rhythm=piano_talea,
                  pitch=piano_color,
                  instrument=0)
    cello = brush(score,
                  length=len(cello_talea) * 6,
                  rhythm=cello_talea,
                  amplitude=.2,
                  pitch=cello_color,
Beispiel #13
0
if __name__ == '__main__':
    from musx.midi.gm import Celesta, Glockenspiel, MusicBox, Vibraphone,\
        Marimba, Xylophone, TubularBells
    from musx import Seq, MidiFile
    from musx import Score

    # Plain Hunt change ringing for 10 bells.
    items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    rules = [[0, 2, 1], [1, 2, 1]]
    items = all_rotations(items, rules, False, True)
    # 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: TubularBells,
        1: TubularBells,
        2: TubularBells,
        3: TubularBells
    })
    # Track 1 will hold the composition.
    track1 = Seq()
    # Create a score and give it tr1 to hold the score event data.
    sco = Score(out=track1)
    # Create the composition.
    sco.compose(playbells(sco, items, _conventry_fkeys, .25, .6, .8))
    # Write the tracks to a midi file in the current directory.
    file = MidiFile("coventry.mid", [track0, track1]).write()
    print(f"Wrote '{file.pathname}'.")

    # To automatially play demos use setmidiplayer() and playfile().
    # Example:
    #     setmidiplayer("fluidsynth -iq -g1 /usr/local/sf/MuseScore_General.sf2")
Beispiel #14
0
    """
    Gesture4 is similar to gesture3 but chooses octaves and gradually
    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),
Beispiel #15
0
To run this script cd to the parent directory of demos/ and do:
```bash
python3 -m demos.blues
```
"""

if __name__ == '__main__':

    from musx import Score, Seq, MidiFile, pick
    from musx.paint import spray

    # The blues scale.
    blues = [0, 3, 5, 6, 7, 10, 12]
    # 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()
    # 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)
    # The sections of the piece
    s1 = spray(score,
               duration=.2,
               rhythm=.2,
               band=[0, 3, 5],
               pitch=30,
               amplitude=0.35,
               end=36)
    s2 = spray(score,
               duration=.2,
               rhythm=[-.2, -.4, .2, .2],
Beispiel #16
0
          dur=1,
          amp=0.75,
          chan=9,
          tuning=4),
    brush(q,
          len=828,
          key=pphase,
          rhy=1 / 32,
          dur=7,
          amp=0.75,
          chan=1,
          tuning=4),
    brush(q, len=1000, key=arf, rhy=1 / 8, dur=1, amp=1, chan=1, tuning=4),
    brush(q, len=200, key=pphase, rhy=1 / 2, dur=7, amp=0.75, chan=1, tuning=4)
])
f = MidiFile("jimmy.mid", [t0, t1]).write()

csoundac_score_node = CsoundAC.ScoreNode()
csoundac_score = csoundac_score_node.getScore()
musx_csoundac.to_csoundac_score(f, csoundac_score)

print("Generated:")
print(csoundac_score.getCsoundScore())

orc = '''
sr = 48000
ksmps = 128
nchnls = 2
0dbfs = 100

; Ensure the same random stream for each rendering.
Beispiel #17
0
    for meas in range(measures):
        root = next(roots)
        if 0 == meas % 12:
            ampl = between(.5, 1)
        score.compose(jazz_piano(score, root, tempo, ampl))
        score.compose(jazz_cymbals(score, tempo, ampl))
        score.compose(jazz_high_hat(score, tempo, ampl))
        score.compose(jazz_drums(score, tempo, ampl))
        score.compose(jazz_bass(score, root - 12, tempo, ampl))
        yield intempo(4, tempo)


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: AcousticBass})
    # 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)

    # c=[]
    # for t in range(0, 15, 2): # t -> 0 2 4 6 8 10 12 14
    #     c += [[t, jazz_high_hat(q, 120, .9)],
    #           [t, jazz_drums(q, 120, .9)],
    #           [t, jazz_cymbals(q, 120, .9)],
    #           [t, jazz_piano(q, 58, 120, .9)],
    #           [t, jazz_bass(q, 46, 120, .9)]
    #           ]

    # Create the composition.