Example #1
0
def motive1(score, octave, limit, chan):
    """
    Motive1 generates three notes in random order but always with a
    whole step and minor seventh sounding. The motive can be randomly
    transposed within limit half-steps.

    Parameters
    ----------
    score : Score
        The score.
    octave : int
        The octave to play the notes in.
    limit : int
        The maximum transposition in half steps.
    chan : int
        The midi channel to assign to the notes.
    """
    # the basic pitches to transpose and jumble e.g. [F#4 E4 D5].
    pitches = jumble([6, 4, 14])
    # one of the three pitches will be louder than the others.
    amps = jumble([.75, .5, .5])
    # randomly chosen transpostion within a limit
    offset = random.randrange(limit)
    for _ in range(3):
        knum = next(pitches) + (octave * 12) + offset
        note = Note(time=score.now, duration=.1, pitch=knum, amplitude=next(amps), instrument=chan)
        score.add(note)
        yield .2
Example #2
0
def motive2(score, octave, limit, chan):
    """Motive2 generates a repeated tone with one tone accented."""
    amps = jumble([.75, .5, .5])
    rhys = jumble([.2, .2, .4])
    offset = random.randrange(limit)
    for _ in range(3):
        knum = 0 + (octave * 12) + offset
        note = Note(time=score.now, duration=.1, pitch=knum, amplitude=next(amps), instrument=chan)
        score.add(note)
        yield next(rhys)
Example #3
0
File: rm.py Project: ricktaube/musx
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)
Example #4
0
 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)
Example #5
0
def register(score, rhy, dur, low, high, amp):
    """
    Generates a chromatic scale betwen low and high choosing notes from the
    scale in random.
    """
    pat = jumble(scale(low, high - low + 1, 1))
    while score.elapsed < dur:
        keyn = next(pat)
        note = Note(time=score.now, duration=rhy, pitch=keyn, amplitude=amp)
        score.add(note)
        yield rhy
Example #6
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