Beispiel #1
0
def fm_improv(score, line, beat):
    """
    Uses a contour line of carrier frequencies (specified as midi keynums)
    to produces fm spectra that creates both melodic and harmoinc gestures.
    The inputs and outputs of the fmspectrum() calls are printed during the
    improvisation.
    """
    amp = .7
    dur = beat
    for knum in line:
        ismel = odds(.7)
        rhy = pick(dur, dur / 2, dur / 4)
        f, r, x = hertz(knum), between(1.1, 1.9), pick(1, 2, 3)
        #print("\ncarrier=",f,"c/m ratio=",r,"fm index=",x)
        spec = fmspectrum(f, r, x)
        keys = spec.keynums(unique=True, minkey=knum - 14, maxkey=knum + 14)

        if ismel:
            random.shuffle(keys)
        sub = rhy / len(keys) if ismel else 0
        #print("melody:" if ismel else "chord:", "time=", score.now, "duration=", rhy, "keys=", keys)
        for i, k in enumerate(keys):
            m = Note(time=score.now + (i * sub),
                     duration=dur,
                     pitch=k,
                     amplitude=amp)
            score.add(m)
        yield rhy
Beispiel #2
0
def rmfunky(score, reps, dur, keys):
    """
    Main composer chooses input spectra , creates a ring modulated
    output spectrum and plays them using two parts.

    Parameters
    ----------
    score : Score
        The musical score.
    reps : int
        The number of sections to compose.
    dur : int
        The surface rhythm
    keys : list
        List of keynums for ring modulation input.
    """
    num = choose([1, 2, 3])
    # scramble the cycle of fourths
    pat = jumble(keys)
    for _ in range(reps):
        # input1 is 1, 2 or 3 notes from cycle of 4ths
        keys1 = [next(pat) for _ in range(next(num))]
        # input2 is same
        keys2 = [next(pat) for _ in range(next(num))]
        # ring modulate the inputs
        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)
Beispiel #3
0
def ghosts(score):
    """
    Creates mid-range clarinet line and decorates it with
    calls to the other instrument composers.
    
    Parameters
    ----------
    score : Score
        The musical score to add events to.
    """
    for _ in range(12):
        here = score.elapsed
        ahead = (here + 1 / 2) * 2
        melody = between(53, 77)
        high = (melody >= 65)
        amp = .2 if high else .4
        rhy = pick(1 / 4, 1 / 2, 3 / 4)
        # the clarinet line
        note = Note(time=score.now,
                    duration=rhy + .2,
                    pitch=melody,
                    amplitude=amp,
                    instrument=1)
        score.add(note)
        # 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
Beispiel #4
0
def jazz_piano(score, on, tmpo, ampl):
    """
    The jazz piano improvises jazz chords based on a pattern of root
    changes and a scale pattern that is transposed to each root. The
    piano randomly choose between playing triplet eighths or straight
    eights for a given measure.
    """
    reps = odds(.65, 8, 12)
    scal = jumble(jazz_scale)
    rhys = cycle([2 / 3, 1 / 3] if reps == 8 else [1 / 3])
    for _ in range(reps):
        r = intempo(next(rhys), tmpo)
        l = [] if odds(2 / 5) else [next(scal) for _ in range(between(1, 9))]
        for k in l:
            a = pick(.4, .5, .6, .7, .8)
            m = Note(time=score.now,
                     duration=r,
                     pitch=on + k,
                     amplitude=a,
                     instrument=0)
            score.add(m)
        yield r
Beispiel #5
0
 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],
            band=[3, 7, 6],
            pitch=pick(30, 42),
            amplitude=0.5,
            end=25)
 s3 = spray(score,
            duration=.2,
            rhythm=[-.2, .2, .2],
            band=blues,
            pitch=pick(42, 54),
            instrument=2,
            end=20)
 s4 = spray(score,
            duration=.2,
            rhythm=[-.6, .4, .4],
            band=blues,
            pitch=66,
            amplitude=0.4,