From 9a4993996d43ed6cd10826e63a902d38c1a102c4 Mon Sep 17 00:00:00 2001 From: anilpatel38 Date: Wed, 22 Mar 2017 23:51:17 -0400 Subject: [PATCH 1/3] finished algorithmic music toolbox --- blues_solo.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/blues_solo.py b/blues_solo.py index 0408e06..edc513c 100644 --- a/blues_solo.py +++ b/blues_solo.py @@ -2,7 +2,8 @@ import atexit import os -from random import choice +import random +# from random import choice from psonic import * @@ -17,11 +18,13 @@ def play_note(note, beats=1, bpm=60, amp=1): """Plays note for `beats` beats. Returns when done.""" # `note` is this many half-steps higher than the sampled note half_steps = note - SAMPLE_NOTE - # An octave higher is twice the frequency. There are twelve half-steps per octave. Ergo, + # An octave higher is twice the frequency. There are twelve half-steps per + # octave. Ergo, # each half step is a twelth root of 2 (in equal temperament). rate = (2 ** (1 / 12)) ** half_steps assert os.path.exists(SAMPLE_FILE) - # Turn sample into an absolute path, since Sonic Pi is executing from a different working directory. + # Turn sample into an absolute path, since Sonic Pi is executing from a + # different working directory. sample(os.path.realpath(SAMPLE_FILE), rate=rate, amp=amp) sleep(beats * 60 / bpm) @@ -33,10 +36,29 @@ def stop(): msg = msg.build() synthServer.client.send(msg) -atexit.register(stop) # stop all tracks when the program exits normally or is interrupted -# These are the piano key numbers for a 3-octave blues scale in A. See: http://en.wikipedia.org/wiki/Blues_scale -blues_scale = [40, 43, 45, 46, 47, 50, 52, 55, 57, 58, 59, 62, 64, 67, 69, 70, 71, 74, 76] +# stop all tracks when the program exits normally or is interrupted +atexit.register(stop) + +# These are the piano key numbers for a 3-octave blues scale in A. +# See: http://en.wikipedia.org/wiki/Blues_scale +blues_scale = [40, 43, 45, 46, 47, 50, 52, 55, 57, 58, 59, 62, 64, 67, 69, 70, + 71, 74, 76] beats_per_minute = 45 # Let's make a slow blues solo -play_note(blues_scale[0], beats=1, bpm=beats_per_minute) +# play_note(blues_scale[8], beats=1, bpm=beats_per_minute) + +curr_note = 0 +# play_note(blues_scale[curr_note], 1, beats_per_minute) +licks = [[(1, 0.5), (2, 0.25), (3, 1), (1, 0.5)], + [(-2, 0.25), (-1, .25), (1, 1.5), (2, 1)]] +for _ in range(8): + lick = random.choice(licks) + for note in lick: + curr_note += note[0] + + # if curr note is out of index range, pick a random note and continue + if curr_note > len(blues_scale): + curr_note = random.choice(range(len(blues_scale))) + print(curr_note) + play_note(blues_scale[curr_note], note[1], beats_per_minute) From 2f8bfbe47a760c3526088618ee4f4b1fcd4aa766 Mon Sep 17 00:00:00 2001 From: anilpatel38 Date: Thu, 23 Mar 2017 00:03:05 -0400 Subject: [PATCH 2/3] added swing licks to finish assignment --- blues_solo.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/blues_solo.py b/blues_solo.py index edc513c..1723d33 100644 --- a/blues_solo.py +++ b/blues_solo.py @@ -52,13 +52,15 @@ def stop(): # play_note(blues_scale[curr_note], 1, beats_per_minute) licks = [[(1, 0.5), (2, 0.25), (3, 1), (1, 0.5)], [(-2, 0.25), (-1, .25), (1, 1.5), (2, 1)]] + +swing_lick = [[(1, 0.5 * 1.5), (3, 0.5 * 0.9), (2, 0.5 * 1.5), (-4, 0.5 * 0.9)], [(3, 0.5 * 1.5), (-2, 0.5 * 0.9), (-1, 0.5 * 1.5), (3, 0.5 * 0.9)]] + for _ in range(8): - lick = random.choice(licks) + lick = random.choice(swing_lick) for note in lick: curr_note += note[0] - + print(curr_note) # if curr note is out of index range, pick a random note and continue - if curr_note > len(blues_scale): + if curr_note > len(blues_scale)-1: curr_note = random.choice(range(len(blues_scale))) - print(curr_note) play_note(blues_scale[curr_note], note[1], beats_per_minute) From 591388d262a7022071aa2d3bbd286d52e2955b56 Mon Sep 17 00:00:00 2001 From: anilpatel38 Date: Mon, 24 Apr 2017 02:22:52 -0400 Subject: [PATCH 3/3] finished mini project 5 revisions --- blues_solo.py | 82 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/blues_solo.py b/blues_solo.py index 1723d33..e8a1060 100644 --- a/blues_solo.py +++ b/blues_solo.py @@ -37,6 +37,32 @@ def stop(): synthServer.client.send(msg) +""" +define a list of lengths for the following function to use. +""" +lengths = [] +curr_length = 0.1 +for i in range(11): + lengths.append(curr_length) + curr_length += 0.03 + curr_length = round(curr_length, 3) + + +def rand_lick(): + """ + function for making random licks. + randomizes note length and interval jump + """ + num_notes = random.choice(range(5, 10)) + notes = [] + for i in range(num_notes): + interval = random.choice(range(-3, 3)) + length = random.choice(lengths) + note = (interval, length) + notes.append(note) + return notes + + # stop all tracks when the program exits normally or is interrupted atexit.register(stop) @@ -46,21 +72,53 @@ def stop(): 71, 74, 76] beats_per_minute = 45 # Let's make a slow blues solo -# play_note(blues_scale[8], beats=1, bpm=beats_per_minute) - -curr_note = 0 -# play_note(blues_scale[curr_note], 1, beats_per_minute) -licks = [[(1, 0.5), (2, 0.25), (3, 1), (1, 0.5)], - [(-2, 0.25), (-1, .25), (1, 1.5), (2, 1)]] +r_note = (1, 0.1) # note in an ascending run lick +r_note2 = (-1, 0.1) # note in a descending run lick +hold_note = (1, 0.3) # held out note +length = 0.15 # standard note length for regular licks +curr_note = 0 # starting at curr_note of 0 -swing_lick = [[(1, 0.5 * 1.5), (3, 0.5 * 0.9), (2, 0.5 * 1.5), (-4, 0.5 * 0.9)], [(3, 0.5 * 1.5), (-2, 0.5 * 0.9), (-1, 0.5 * 1.5), (3, 0.5 * 0.9)]] +# pre define two types of lists. Regular swing and a fast run of notes. +straight_lick = [[(1, length * 1.5), (3, length * 0.9), (2, length * 1.5), (-4, length * 0.9)], [(3, length * 1.5), (-2, length * 0.9), (-1, length * 1.5), (3, length * 0.9)]] +run_lick = [[r_note, r_note, r_note, hold_note], [r_note2, r_note2, r_note2, hold_note]] +# run through 8 licks for _ in range(8): - lick = random.choice(swing_lick) + """ + To change the frequency of different types of licks I pick a random numbers + in a range of 0-6 and depending on which number is picked a different list + of licks is selected from. + + The default swing licks are the most common, random licks are less common, + and the "runs" are the least common. + """ + check = random.choice(range(6)) + if check == 4: + lick = random.choice(run_lick) + print('run') + elif check > 4: + lick = rand_lick() + # for each random lick start at a random spot not too extreme. + curr_note = random.choice(range(6, 12)) + print('rand') + else: + lick = random.choice(straight_lick) + print('regular') + + # loop through each note in the licks for note in lick: curr_note += note[0] - print(curr_note) - # if curr note is out of index range, pick a random note and continue + # print(curr_note) + # if curr note is out of index then pick a random note near the extreme if curr_note > len(blues_scale)-1: - curr_note = random.choice(range(len(blues_scale))) - play_note(blues_scale[curr_note], note[1], beats_per_minute) + curr_note = random.choice(range(15, 19)) + + # if curr note is out of index then subtract short random interval + if curr_note < 0: + curr_note = random.choice(range(1, 6)) + + # if statement for making top and bottom of the scale longer notes + if curr_note == 0 or curr_note == 19: + play_note(blues_scale[curr_note], 1, beats_per_minute, 1) + else: + play_note(blues_scale[curr_note], note[1], beats_per_minute, 1)