def create_base0(self, process, loop, name='new'): # base0 = [['c3*',4], ['g3*',4], ['c4*',4], ['r',4], # ['g2*',4], ['d3*',4], ['g3*',4], ['r',4], # ['a2*',4], ['e3*',4], ['a3*',4], ['r',4], # ['e2*',4], ['b2*',4], ['e3*',4], ['r',4], # ['f2*',4], ['c3*',4], ['f3*',4], ['r',4], # ['c2*',4], ['g2*',4], ['c3*',4], ['r',4], # ['f2*',4], ['c3*',4], ['f3*',4], ['r',4], # ['g2*',4], ['d3*',4], ['g3*',4], ['r',4]] base_1 = [] first_chord = True for loop_index in range(loop): for chord in process: if first_chord: first_chord = False scale = sc.make_scale(chord[0], chord[1], 3) else: scale = sc.make_scale(chord[0], chord[1], 2) do = scale[0+octave_adjust] mi = scale[2+octave_adjust] so = scale[4+octave_adjust] do_octave = scale[7+octave_adjust] base_1.append((do,1)) base_1.append((so,1)) base_1.append((do_octave,1)) base_1.append(('r',1)) base_melody = self.make_base(base_1) return base_melody
def create_base1(self, process, name='new'): base_1 = [] base_2 = [] for chord in process: scale = sc.make_scale(chord[0],chord[1], 3) do = scale[0+octave_adjust] mi = scale[2+octave_adjust] so = scale[4+octave_adjust] base_1.append((do+'*',8)) base_1.append(('r',8)) base_1.append((so+'*',8)) base_1.append(('r',8)) base_2.append(('r',8)) base_2.append(('r',8)) base_2.append((mi+'*',8)) base_2.append(('r',8)) ##### Tried to make last chord different as a ending chord ##### # last_chord = process[-1] # last_scale = make_scale(last_chord[0],last_chord[1]) # do = last_scale[0] # mi = last_scale[2] # so = last_scale[4] # base_1.append((so,8)) # base_1.append(('r',8)) # base_1.append((mi,8)) # base_1.append(('r',8)) # base_1.append((do,4)) # base_2.append((mi,8)) # base_2.append(('r',8)) # base_2.append((do,8)) # base_2.append(('r',8)) return None
def __init__(self, process, loop=1, base_type=None): self.base = [] self.loop = loop # self.create_base(base_type) self.first_chord = process[0] self.keys = sc.make_scale(self.first_chord[0], self.first_chord[1]) self.base = self.create_base0(process, loop)
def createMelody(process, measure_length, loop=1): notes = [] beats = bt.Beat(process, loop, measure_length=4) relative_notes_index = [] first_chord = process[ 0] # first_chord[0] == C D E... first_chord[1] == major minor ... keys = sc.make_scale( first_chord[0], first_chord[1]) # ex) first_chord[0] = c , first_chord[1] = major print('main keys: ', keys) beats = beats.beats print("------Generating Melody------") for loop_index in range(loop): for chord_index in range(len(process)): chord = process[chord_index] print("chord:", chord) print("measure_beat:", beats[len(process) * loop_index + chord_index]) # Make melody according to beats scale = sc.make_scale(chord[0], chord[1]) # I need to fix it!!! measure_notes = generate_notes( process, chord_index, beats[len(process) * loop_index + chord_index], relative_notes_index, keys, notes) print("measure_notes:", measure_notes) # relative_measure_notes_index = make_relative_notes_index(scale, measure_notes) notes.append(measure_notes) # relative_notes_index.append(relative_measure_notes_index) print("-------------" + str(chord_index + 1 + len(process) * loop_index) + "/" + str(len(process) * loop) + ("-------------")) print("-------------" + str(loop_index + 1) + "/" + str(loop) + ("-------------")) print() print('len(notes) / len(beats): ', len(notes), ' / ', len(beats)) main_stream = zip_note_beat(notes, beats) return main_stream
def generate_notes(process, chord_index, measure_beat, relative_notes_index, keys, notes): # Make Note accordingly chord = process[chord_index] print("chord[0]: ", chord[0]) print("chord[1]: ", chord[1]) scale = sc.make_scale(chord[0], chord[1]) print("scale: ", scale) accum_beat = 0 measure_notes = [] relative_measure_notes_index = [] prev_key = None prev_note = None for iter_beat_index in range(len(measure_beat)): do = scale[0 + octave_adjust] mi = scale[2 + octave_adjust] so = scale[4 + octave_adjust] next_note = None probability = [0] * len(keys) if (chord_index == 0 or chord_index == 1): # make first measure random8 if (accum_beat == 0): # start with one of the tride note next_note = rd.choice([do, mi, so]) else: apply_up_down_tendancy(probability, measure_notes, keys) apply_tride_notes_probability(probability, scale, keys, accum_beat) # Tring to repeat the melody within current measure.... working on it # if(accum_beat is 0.5): # first_note = measure_notes[0] # first_note_index = keys.index(first_note) # probability[first_note_index] += 5 next_note = rd.choices(keys, weights=probability, k=1)[0] else: # make the rest of the measures imitating the first measure try: comparitive_note_index = relative_notes_index[ chord_index % 2][iter_beat_index] keys_index = keys.index(do) + comparitive_note_index comparitive_note = keys[keys_index] if (comparitive_note in scale): probability[keys_index] += 20 else: probability[keys_index] += 10 except: pass ##### got it from first measure###### if prev_note != None: prev_note_index = keys.index(prev_note) apply_up_down_tendancy(probability, measure_notes, keys) apply_tride_notes_probability(probability, scale, keys, accum_beat) ##### got it from first measure###### # print(chord[0],' probability:', probability) # print(chord[0],' scale:', scale) next_note = rd.choices(keys, weights=probability, k=1)[0] prev_note = next_note accum_beat += 1.0 / measure_beat[iter_beat_index] relative_next_note_index = keys.index(next_note) - keys.index(do) relative_measure_notes_index.append(relative_next_note_index) measure_notes.append(next_note) relative_notes_index.append(relative_measure_notes_index) return measure_notes
#! /usr/bin/python import argparse from scales import make_scale from board import Board parser = argparse.ArgumentParser() parser.add_argument('-t', '--tunning', type=str, help='Guitar tunning', default='EADGBE') parser.add_argument('-k', '--key', type=str, help='Key note of the scale', required=True) parser.add_argument('-s', '--scale', type=str, help='Scale to draw', required=True) args = parser.parse_args() note = args.key.lower() scale = args.scale.lower() scale_notes = make_scale(note, scale) board = Board(args.tunning) print board.draw(scale_notes)