예제 #1
0
def whimsical_melody_lead():
    notes = [
        # bar 1
        (None, 1),
        (sp.Ds4, 1),
        (sp.C4, 1),
        (sp.As4, 1 / 4),
        (sp.C4, 3 / 4),
        # bar 2
        (sp.C4, 1),
        (sp.Ds4, 1),
        (sp.C4, 1),
        (None, 1),
        # bar 3
        (None, 1),
        (sp.Ds4, 1),
        (sp.C4, 1),
        (sp.As4, 1 / 4),
        (sp.C4, 3 / 4),
        # bar 4
        (sp.C4, 1),
        (sp.Ds4, 1),
        (sp.C4, 1),
        (sp.As4, 1),
    ]

    for note in notes:
        sp.use_synth(sp.PLUCK)
        sp.play(note[0], amp=2)
        Metronome().beat_sleep(note[1])
예제 #2
0
def sonic_pi(freq):
    import psonic
    psonic.use_synth(psonic.PULSE)
    while True:
        with psonic.Fx(psonic.REVERB):
            print(freq.value)
            psonic.play(freq.value, release=0.2)
            sleep(0.08)
예제 #3
0
def play():
    global vol
    global pitch
    print("making music")

    while True:
        ps.play(pitch, sustain=.1, attack=.05, release=.05, amp=vol)
        ps.sleep(.1)
예제 #4
0
def three_quarter_notes_descending_arp():
    notes = sp.scale(root_note=sp.C5,
                     scale_mode=sp.MINOR_PENTATONIC,
                     num_octaves=1)
    for i in range(3):
        sp.use_synth(sp.SINE)
        sp.play(notes[-(i + 1)], release=0.1, amp=0.5)

        Metronome().beat_sleep(wait_len=0.25)
예제 #5
0
def synthwave_offbeat_bass():
    bar_number = Metronome().bar_number % 4
    notes = [sp.C1, sp.C1, sp.Ds1, sp.As0]

    Metronome().beat_sleep(wait_len=1 / 4)
    for _ in range(3):
        sp.use_synth(sp.TB303)
        octave_notes = [notes[bar_number - 1], notes[bar_number - 1] + 12]
        sp.play(octave_notes, sustain=0.1, release=0.1, amp=0.9, cutoff=110)
        Metronome().beat_sleep(wait_len=1 / 4)
예제 #6
0
def riff_3(tempo: float = 60):
    speed = 60 / tempo
    psonic.use_synth(psonic.PROPHET)
    sc = psonic.scale(psonic.E2, psonic.MINOR)
    s = random.choice([0.125 * speed, 0.25 * speed, 0.5 * speed])
    for i in range(8):
        r = random.choice([0.125, 0.25, 1, 2])
        n = random.choice(sc)
        co = random.randint(30, 100)
        psonic.play(n, release=r, cutoff=co)
        psonic.sleep(s)
예제 #7
0
def low_part(tempo):
    psonic.play([55, 59])
    psonic.sleep(1)
    psonic.play_pattern_timed([57], 0.5)
    psonic.play_pattern_timed([59], 1.5)
    psonic.play_pattern_timed([60], 1.5)
    psonic.play_pattern_timed([59], 1.5)
    psonic.play_pattern_timed([57], 1.5)  #b5
    psonic.play_pattern_timed([55], 1.5)  #b6
    psonic.play_pattern_timed([62, 59, 55, 62], 0.5)  #b7
    psonic.play_pattern_timed([50, 60, 59, 57], 0.25)
예제 #8
0
def switch_synth(selected_text):
    print(selected_text)
    # set synth according to request:
    if selected_text == available_synths[0]:
        psonic.use_synth(psonic.PIANO)
    elif selected_text == available_synths[1]:
        psonic.use_synth(psonic.PROPHET)
    elif selected_text == available_synths[2]:
        psonic.use_synth(psonic.SAW)

    psonic.play(55)
예제 #9
0
def simple_four_chords():
    bar_number = Metronome().bar_number % 4

    chords = [
        sp.chord(sp.C3, sp.MINOR),
        sp.chord(sp.C3, sp.MINOR),
        sp.chord(sp.Ds3, sp.MAJOR),
        sp.chord(sp.As2, sp.MAJOR),
    ]

    sp.use_synth(sp.TB303)
    sp.play(chords[bar_number - 1], amp=1.4, release=1.2)
    Metronome().beat_sleep(wait_len=4)
예제 #10
0
def sonic_pi(freq):
    psonic.use_synth(psonic.PULSE)
    while True:
        with psonic.Fx(psonic.REVERB):
            if instrument.value == 0:
                psonic.use_synth(psonic.PULSE)
            if instrument.value == 1:
                psonic.use_synth(psonic.SAW)
            if instrument.value == 2:
                psonic.use_synth(psonic.FM)

            psonic.play(freq.value, release=0.2)
            sleep(0.08)
 def neverland_event(self, entity, action, entity_id):
     '''
     entity_id 
     '''
     print(entity, action, entity_id)
     if entity == "cube":
         if action == "slide":
             run(cowbell)
             # run(test_run())
         if action == "rotate_left":
             # play (60, attack=0.5, decay=1, sustain_level=0.4, sustain=2, release=0.5)
             # attack 淡入时间,中间持续时间,release淡出时间
             # play是非阻塞的
             play(70, sustain=0.25)  # 响度 amp=2/0.5, 方向 pan=-1/1/0
             sleep(self.beat)
             play(72, sustain=0.25)
예제 #12
0
# To get this program to work, you must do three things:
# 1. Install the Python psonic module using PIP:
#    pip3 install python-sonic
# 2. Install the Sonic Pi music program, downloadable at:
#    https://sonic-pi.net/
# 3. Make sure that Sonic Pi (the music program) is running

import psonic
# Note: psonic allows us to pass commands into Sonic Pi programmatically

# List of MIDI Notes: https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies
psonic.use_synth(psonic.PIANO)
psonic.play(76)
psonic.sleep(0.25)
psonic.play(76)
psonic.sleep(0.5)
psonic.play(76)
psonic.sleep(0.5)
psonic.play(72)
psonic.sleep(0.25)
psonic.play(76)
psonic.sleep(0.5)
psonic.play(79)
psonic.sleep(1)
psonic.play(67)
psonic.sleep(1)
예제 #13
0
import psonic
import random

e = psonic.chord(psonic.E3, psonic.MINOR)
print(e)

# Challenge: Write a  loop that randomly plays a note from the
# e minor cord, for either 0.25, or 0.5 length of time
# after it plays 30 notes it should stop
psonic.use_synth(psonic.PROPHET)
psonic.play(e[0], release=0.6)
psonic.sleep(0.5)
예제 #14
0
def tests():
    for i in range(5):
        p.play(random.randrange(60, 80))
        p.sleep(1)
예제 #15
0
def play_e():
    psonic.play(52)
예제 #16
0
import psonic
MARIO_NOTES = [
    76, 76, 76, 72, 76, 79, 67, 72, 67, 64, 69, 71, 70, 69, 67, 76, 79, 81, 77,
    79, 76, 72, 74, 71
]

# Challenge: skip over all of the MIDI notes that equal 67
for note in MARIO_NOTES:
    if note == 67:
        print('skipping...', note)
        continue
    psonic.play(note)
    psonic.sleep(0.3)
예제 #17
0
def play_song_1():
    psonic.play(52)
    psonic.sleep(speed)
    psonic.play(54)
    psonic.sleep(speed)
예제 #18
0
def play_notes(notes, s=0.15):
    for n in notes:
        d = 0.3 + random.random()
        ps.play(70 + n, release=d)
        t = ps.random.choice([0.125, 0.25, 0, 0.2])
        ps.sleep(t)
예제 #19
0
import psonic

MARIO_NOTES = [
    76, 76, 76, 72, 76, 79, 67, 72, 67, 64, 69, 71, 70, 69, 67, 76, 79, 81, 77,
    79, 76, 72, 74, 71
]

# Challenge 1: use a *while* loop to PLAY all of the notes
# in the MARIO_NOTES list.
# Challenge 2: when the song ends, play it again

psonic.use_synth(psonic.PIANO)
psonic.play(76)
psonic.sleep(0.25)
예제 #20
0
]

SUPER_MARIO_NOTES = [
    76, 76, 76, 72, 76, 79, 67, 72, 67, 64, 69, 71,
    70, 69, 67, 76, 79, 81, 77, 79, 76, 72, 74, 71,
    79, 78, 77, 75, 76, 68, 69, 72, 69, 72, 74, 79,
    78, 77, 75, 76, 84, 79, 78, 77, 75, 76, 68, 69,
    72, 69, 72, 74, 75, 74, 72, 72, 74, 76, 72, 69,
    67, 72, 74, 76, 72, 74, 76, 72, 69, 67, 76, 72,
    76, 79, 67, 76, 72, 67, 68, 69, 77, 69, 71, 81,
    79, 77, 76, 72, 69, 67, 76, 72, 67, 68, 69, 77,
    69, 71, 77, 76, 74, 72
]

psonic.use_synth(psonic.PIANO)
psonic.play(HAPPY_BIRTHDAY[0])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[1])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[2])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[3])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[4])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[5])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[6])
psonic.sleep(0.25)
psonic.play(HAPPY_BIRTHDAY[7])
psonic.sleep(0.25)
예제 #21
0
def play_song(notes, speed):
    psonic.use_synth(psonic.PIANO)
    for note in notes:
        psonic.play(note)
        psonic.sleep(speed)
예제 #22
0
def play_c():
    psonic.play(48)
예제 #23
0
def play_f():
    psonic.play(53)
import psonic

MARIO_NOTES = [
    76, 76, 76, 72, 76, 79, 67, 72, 67, 64, 69, 71, 70, 69, 67, 76, 79, 81, 77,
    79, 76, 72, 74, 71
]
note_number = 0

while note_number < len(MARIO_NOTES):
    psonic.use_synth(psonic.PIANO)
    print(note_number, '/', len(MARIO_NOTES), 'MIDI NOTE:',
          MARIO_NOTES[note_number])

    # this just pauses the execution until the
    # user presses enter (which resumes the loop)
    input('Press enter to play next note')
    psonic.play(MARIO_NOTES[note_number])
    note_number += 1

print('End loop. No more notes')
예제 #25
0
import psonic
import random

e = psonic.chord(psonic.E2, psonic.MINOR) + \
    psonic.chord(psonic.E3, psonic.MINOR) + \
    psonic.chord(psonic.E4, psonic.MINOR)
print(e)

# Challenge: Write a while loop that randomly plays a note from the
# e minor cord, for either 0.25, or 0.5 length of time
# after it plays 30 notes it should stop
counter = 0
while counter < 30:
    psonic.use_synth(psonic.PROPHET)
    psonic.play(random.choice(e), release=0.6)
    psonic.sleep(random.choice([0.25, 0.5]))
    counter += 1
예제 #26
0
import psonic

c_arpeggio = psonic.scale(psonic.C2, psonic.MAJOR, num_octaves=4)
print(c_arpeggio)
psonic.use_synth(psonic.PIANO)

# play ascending arpeggio:
counter = 0
for note in c_arpeggio:
    if counter % 8 in [0, 2, 4]:
        psonic.play(note)
        psonic.sleep(0.2)
    counter += 1

# play top note:
psonic.play(c_arpeggio[-1])
psonic.sleep(0.2)

# play descending arpeggio:
start = len(c_arpeggio) - 1
end = -1
for i in range(start, end, -1):
    note = c_arpeggio[i]
    if i % 8 in [0, 2, 4]:
        psonic.play(note)
        psonic.sleep(0.2)

예제 #27
0
def play_song_2():
    psonic.play(55)
    psonic.sleep(speed)
    psonic.play(57)
    psonic.sleep(speed)
예제 #28
0
import psonic

MARIO_NOTES = [
    76, 76, 76, 72, 76, 79, 67, 72, 67, 64, 69, 71,
    70, 69, 67, 76, 79, 81, 77, 79, 76, 72, 74, 71
]

# Challenge 1: use a *while* loop to PLAY all of the notes
# in the MARIO_NOTES list.
# Challenge 2: when the song ends, play it again

psonic.use_synth(psonic.PIANO)
psonic.play(MARIO_NOTES[0])
psonic.sleep(0.25)
psonic.play(MARIO_NOTES[1])
psonic.sleep(0.25)
psonic.play(MARIO_NOTES[2])
psonic.sleep(0.25)
예제 #29
0
파일: music.py 프로젝트: eecs110/spring2019
def make_song():
    # do something interesting here with sound:
    psonic.use_synth(psonic.PIANO)
    psonic.play(76)
    psonic.sleep(0.25)
    psonic.play(76)
    psonic.sleep(0.5)
    psonic.play(76)
    psonic.sleep(0.5)
    psonic.play(72)
    psonic.sleep(0.25)
    psonic.play(76)
    psonic.sleep(0.5)
    psonic.play(79)
    psonic.sample(psonic.DRUM_CYMBAL_SOFT)
    psonic.sleep(1)
    psonic.play(67)
    psonic.sample(psonic.DRUM_BASS_HARD)
    psonic.sleep(1)

    # ...
예제 #30
0
def play_d():
    psonic.play(50)