Exemplo n.º 1
0
def composer_stephen_foster(q, num, shift=0, chan=0):
    # A second-order markov process generates the melody.
    melody = pattern_stephen_foster()
    # randomly select rhythmic patterns characterisitic of Foster's style
    rhythms = choose([[2, 2], [1, 1, 1, 1], [2, 1, 1], [1, 1, 2], [1, 2, 1], [4]],
                        [.375, .125, .125, .125 ,.25, .125])
    for _ in range(num):
        n=0
        for r in next(rhythms):
            k = keynum(next(melody)) + (shift*12)
            r = intempo(r, 200)
            m = MidiNote(time=q.now+n, dur=r, key=k, amp=.5, chan=chan)
            q.out.addevent(m)
            n += r
        yield n
Exemplo n.º 2
0
from musx.paint import brush, spray
from musx.midi import MidiNote, MidiSeq, MidiFile
from musx.scheduler import Scheduler
from musx.tools import playfile, setmidiplayer
from musx.rhythm import rhythm
from musx.scales import keynum
from musx.midi.gm import AcousticGrandPiano, Violin

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

piano_color = keynum([
    "f3 g bf c4 ef b e5", "f3 g bf c4 e a d5", "f3 af bf df4 ef a d5",
    "f3 af bf df4 ef g c5", "f3 g bf d4 fs b c5", "f3 g bf d4 e a c5",
    "f3 a c4 d g cs5 fs", "f3 g c4 d g b e5", "f3 bf df4 gf e5",
    "f3 b d4 g e5 g", "f3 c4 ef af g5", "f3 cs4 e a g5 b",
    "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.
    t0 = MidiSeq.metaseq(ins={0: AcousticGrandPiano, 1: Violin})
    # Track 1 will hold the composition.
Exemplo n.º 3
0
def fm_chords(q, reps, cen, cm1, cm2, in1, in2, rhy):
    """
    Generates a series of FM chords with random fluctuations in its
    C/M ratios and indexes to yield variations of chordal notes.
    """
    for _ in reps:
        spec = fmspectrum(hertz(cen), between(cm1, cm2), between(in1, in2)) 
        for k in spec.keynums(minkey=48, maxkey=72):
            m = MidiNote(time=q.now, dur=rhy, key=k, amp=.5)
            q.out.addevent(m)
    yield rhy


contour = keynum("a4 g f e a4 b c d gs b c5 ef fs g a5 bf g f e a5 b c d \
                  gs3 f e cs c bf5 gs5 as3 cs5 e6 f4 gs5 d6 e f g c5 b a \
                  g bf c5 cs e4 f gs d4 c b a4 e5 f g a5")

def fm_improv(q, 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)
Exemplo n.º 4
0
# assignments, micro tuning, etc. to track 0 in your midi file.
t0 = MidiSeq.metaseq()
# Track 1 will hold the composition.
t1 = MidiSeq()
# Create a scheduler and give it t1 as its output object.
q = Scheduler(t1)
# Start our composer in the scheduler, this creates the composition.
# Specify levels and melody length with care! The number of events 
# sierpinski generates 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!
# q.compose(sierpinski(q, keynum('a0'), [0, 7, 5], 12, 4, 3, .5))
# q.compose(sierpinski(q, keynum('a0'), [0, 7, 5], 8, 5, 7, .5))
levels = 5
#     def sierpinski(q, tone,         shape,             trans, levels, dur, amp, highest_level):
q.compose(sierpinski(q, keynum('a0'), [1, -3, 3, 6, -1], 13,    levels, 150,  .5, levels))

# Write a midi file with our track data.
f = MidiFile("sierpinski.mid", [t0, t1]).write()
# To automatially play demos use setmidiplayer() to assign a shell
# command that will play midi files on your computer. Example:
#   setmidiplayer("fluidsynth -iq -g1 /usr/local/sf/MuseScore_General.sf2")
print(f"Wrote '{f.pathname}'.")
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 = '''
        note = MidiNote(time=q.now, dur=rate, key=knum, amp=.9)
        # Add the midi note to the output midi sequence.
        q.out.addevent(note)
        # Return the amount of time until this composer runs again.
        yield rate


# It's good practice to add any metadata such as tempo, midi instrument
# assignments, micro tuning, etc. to track 0 in your midi file.
t0 = MidiSeq.metaseq()
# Track 1 will hold the composition.
t1 = MidiSeq()
# Create a scheduler and give it t1 as its output object.
q = Scheduler(t1)
# 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(q, 180, keys, .167), piano_phase(q, 180, keys, .170)]
# Start our composer in the scheduler, this creates the composition.
q.compose(pianos)
# Write the seq to a midi file in the current directory.
f = MidiFile("reich.mid", [t0, t1]).write()
# To automatially play demos use setmidiplayer() to assign a shell
# command that will play midi files on your computer. Example:
#   setmidiplayer("fluidsynth -iq -g1 /usr/local/sf/MuseScore_General.sf2")
print(f"Wrote '{f.pathname}'.")

csoundac_score_node = CsoundAC.ScoreNode()
csoundac_score = csoundac_score_node.getScore()
musx_csoundac.to_csoundac_score(f, csoundac_score)
Exemplo n.º 6
0
"""

from musx.midi import MidiNote, MidiSeq, MidiFile
from musx.midi.gm import AcousticGrandPiano, AcousticBass
from musx.generators import cycle, choose, jumble
from musx.rhythm import intempo
from musx.scheduler import Scheduler
from musx.ran import odds, pick, between
from musx.tools import playfile, setmidiplayer
from musx.scales import keynum
import types

jazz_scale = [0, 2, 3, 5, 7, 9, 10, 12, 14]
"""The scale used by the improvisor."""

jazz_changes = keynum('bf3 ef4 bf3 bf ef4 ef bf3 bf f4 ef bf3 bf')
"""The chord changes for the piano and bass parts."""

jazz_tempo = 120
"""The tempo of the compostion."""


def jazz_high_hat(q, tmpo, ampl):
    """
    Plays the High Hat on the second and fourth quarter of every measure and
    rests on the first and third beats. Each sound lasts for the duration one
    triplet eighth note i.e. 1/3 of a beat.
    """
    rhy = intempo(1, tmpo)
    dur = intempo(1 / 3, tmpo)
    amp = .5
# It's good practice to add any metadata such as tempo, midi instrument
# assignments, micro tuning, etc. to track 0 in your midi file.
t0 = MidiSeq.metaseq()
# Track 1 will hold the composition.
t1 = MidiSeq()
# Create a scheduler and give it t1 as its output object.
q = Scheduler(t1)
# Start our composer in the scheduler, this creates the composition.
# Specify levels and melody length with care! The number of events
# sierpinski generates 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!
# q.compose(sierpinski(q, keynum('a0'), [0, 7, 5], 12, 4, 3, .5))
# q.compose(sierpinski(q, keynum('a0'), [0, 7, 5], 8, 5, 7, .5))
q.compose(sierpinski(q, keynum('a0'), [0, -1, 2, 13], 12, 5, 24, .5))

# Write a midi file with our track data.
f = MidiFile("sierpinski.mid", [t0, t1]).write()
# To automatially play demos use setmidiplayer() to assign a shell
# command that will play midi files on your computer. Example:
#   setmidiplayer("fluidsynth -iq -g1 /usr/local/sf/MuseScore_General.sf2")
print(f"Wrote '{f.pathname}'.")
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 = '''