def josquin(): main_theme = NoteSeq("file://josquin") theme1 = main_theme.stretch_dur(0.66666) theme2 = main_theme[0:24].stretch_dur(2).transp(Note("C")) theme3 = main_theme[0:50] midi = Midi(3, tempo=80) midi.seq_notes(theme1, track=0) midi.seq_notes(theme2, track=1) midi.seq_notes(theme3, track=2) midi.write("midi/josquin.mid")
def midi_from_melodies(melodies): notes = [[Note(x % Octave, 4 + x // Octave, 1 / 4) for x in melody] for melody in melodies] chords = [ NoteSeq([melody_notes[i] for melody_notes in notes]) for i in range(len(melody)) ] midi = Midi(tempo=120) midi.seq_chords(chords) return midi
def rhythm_6_17_left(self, chord: Chord) -> [Chord]: rhythm = [] new_chord = NoteSeq() new_chord.append(chord.first_note.octave_shift(-1)) new_chord.append(chord.first_note.octave_shift(-2)) rhythm.append(new_chord.stretch_dur(12 / self.subdivided)) rhythm.append(new_chord.stretch_dur(12 / self.subdivided)) rhythm.append(new_chord.stretch_dur(8 / self.subdivided)) return rhythm
def _read_keys(self, mypath="keys/"): ''' Initialization method that reads in all available keys, in a specified path. :param str mypath: The location of the keys to be read ''' key_files = [f for f in listdir(mypath) if isfile(join(mypath, f))] for key in key_files: new_key = key.replace(".txt", "") key_notes = NoteSeq("file://" + mypath + key) self.music_keys[new_key] = key_notes
def randomSeq(n, pitches, durations, rests=True): # Add a rest to the set of pitches if desired. if rests: pitches.add('r') this_seq = '' for i in range(n): pitch = random.sample(pitches, 1) duration = random.sample(durations, 1) this_seq += pitch[0] + duration[0] + ' ' return NoteSeq(this_seq)
def canon(): theme1 = NoteSeq("file://canon-quaerendo-invenietis") part1 = theme1 + theme1[2:] + theme1[2:11] part2 = theme1 + theme1[2:] + theme1[2:4] voice1 = part1 voice2 = part2.inversion_startswith(Note(2, 4)) midi = Midi(2, tempo=150) midi.seq_notes(voice1, time=3, track=0) midi.seq_notes(voice2, time=13, track=1) midi.write("midi/canon.mid")
def getNotesFromNums(nums, scaleNum, durations): #convert back to noteSeq scale = majorScales[scaleNum] ans = NoteSeq() j = 0 for num in nums: for i in range(len(scale)): if num==i: ans.append(Note(scale[i], dur=durations[j])) j+=1 #print(ans) return ans
def writesong(): soprano = NoteSeq() alto = NoteSeq() tenor = NoteSeq() bass = NoteSeq() for x in range(0, SONG_DURATION, 1): if x == SONG_DURATION: soprano += random_notes(I_PITCHLIST_AT, SOP_RANGE, 1, 120) alto += random_notes(I_PITCHLIST_AT, ALT_RANGE, 1, 90) tenor += random_notes(I_PITCHLIST_AT, TEN_RANGE, 1, 90) bass += random_notes(I_PITCHLIST_B, BAS_RANGE, 1, 120) elif x % 4 == 0: soprano += random_notes(RANDOM_PITCHLIST, SOP_RANGE, 0.0625, 120) alto += random_notes(I_PITCHLIST_AT, ALT_RANGE, 0.125, 90) tenor += random_notes(I_PITCHLIST_AT, TEN_RANGE, 0.25, 90) bass += random_notes(I_PITCHLIST_B, BAS_RANGE, 0.5, 90) elif x % 4 == 1: soprano += random_notes(RANDOM_PITCHLIST, SOP_RANGE, 0.0625, 120) alto += random_notes(IV_PITCHLIST_AT, ALT_RANGE, 0.125, 90) tenor += random_notes(IV_PITCHLIST_AT, TEN_RANGE, 0.25, 90) bass += random_notes(IV_PITCHLIST_B, BAS_RANGE, 0.5, 90) elif x % 4 == 2: soprano += random_notes(RANDOM_PITCHLIST, SOP_RANGE, 0.0625, 120) alto += random_notes(V_PITCHLIST_AT, ALT_RANGE, 0.125, 90) tenor += random_notes(V_PITCHLIST_AT, TEN_RANGE, 0.25, 90) bass += random_notes(V_PITCHLIST_B, BAS_RANGE, 0.5, 90) elif x % 4 == 3: soprano += random_notes(RANDOM_PITCHLIST, SOP_RANGE, 0.0625, 120) alto += random_notes(VI_PITCHLIST_AT, ALT_RANGE, 0.125, 90) tenor += random_notes(VI_PITCHLIST_AT, TEN_RANGE, 0.25, 90) bass += random_notes(VI_PITCHLIST_B, BAS_RANGE, 0.5, 90) midi = Midi(4, tempo=150) midi.seq_notes(soprano, track=0) midi.seq_notes(alto, track=1) midi.seq_notes(tenor, track=2) midi.seq_notes(bass, track=3) return midi
def create_midi_with_time(music, beat_of_music): global LEN_OF_MUSIC noteSeq = [] for i in range(LEN_OF_MUSIC): if music[i] == 101: noteSeq.append(Rest(dur=beat_of_music[i])) else: noteSeq.append(Note(music[i], dur=beat_of_music[i])) seq = NoteSeq(noteSeq) midi = Midi(number_tracks=1, tempo=90) midi.seq_notes(seq, track=0) midi.write("midi/markov_Gavotte_test1.mid")
def rhythm_heart_and_soul_right(self, chord: Chord) -> [NoteSeq]: rhythm = [] new_chord = chord silence_chord = NoteSeq("R") rhythm.append(silence_chord.stretch_dur(8 / self.subdivided)) rhythm.append(new_chord.stretch_dur(4 / self.subdivided)) rhythm.append(new_chord.stretch_dur(4 / self.subdivided)) rhythm.append(silence_chord.stretch_dur(8 / self.subdivided)) rhythm.append(new_chord.stretch_dur(4 / self.subdivided)) rhythm.append(new_chord.stretch_dur(4 / self.subdivided)) return rhythm
def abstraction(): a = NoteSeq("C4. Eb8") a1 = a.transp(5).stretch_dur(0.5) a2 = a.inv("Db''") a3 = a1.inv(8) A = a + a1 + a2 + a3 A2 = A.transp(2) B = a1.transp(8) + a1.transp("Eb''") c = NoteSeq([Note(x.value, dur=0.125) for x in a + a1]) C = (c.inv("Ab''") + c.inv(10) + c.stretch_inverval(2).transp(2) + c.inv("G''") + c.inv("E''").stretch_inverval(1) + c.inv("A").stretch_inverval(1)) a4 = a.stretch_dur(2).inv(6) Part1 = A + NoteSeq("C2") + A2 + B Part2 = C + a4 midi = Midi(1, tempo=90) midi.seq_notes(Part1 + Part2, track=0) midi.write("midi/abstraction.mid")
def test_tonal_transposition(self): scale = NoteSeq("C D E F G A B") c = Note("C") c_transp_fifth_up = c.tonal_transposition(5, scale) c_transp_second_up = c.tonal_transposition(2, scale) a = Note("A") a_transp_fourth_up = a.tonal_transposition(4, scale) a_transp_fifth_up = a.tonal_transposition(5, scale) self.assertEqual(c_transp_fifth_up, Note("G")) self.assertEqual(c_transp_second_up, Note("D")) self.assertEqual(a_transp_fourth_up, Note("D''")) self.assertEqual(a_transp_fifth_up, Note("E''"))
def midicreate(notelist,name,page): NoteList = [] for i in range(len(notelist)): if(notelist[i].scale=='Rest'): chord = Rest(notelist[i].tempo) elif(notelist[i].harmony==0): continue elif(notelist[i].harmony==2): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo)]) elif(notelist[i].harmony==3): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo),Note(notelist[i+2].scale,dur=notelist[i].tempo)]) elif(notelist[i].harmony==4): chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo),Note(notelist[i+1].scale,dur=notelist[i].tempo),Note(notelist[i+2].scale,dur=notelist[i].tempo),Note(notelist[i+3].scale,dur=notelist[i].tempo)]) else: chord = NoteSeq([Note(notelist[i].scale,dur=notelist[i].tempo)]) NoteList.append(chord) midi = Midi(1, tempo=117) checktract = 0 midi.seq_chords(NoteList,track=0) midi.write(f"/home/ec2-user/Ourchord/MIDI/{page}/{name}.mid") # ---------------------------------------------------- 경로 수정
def __init__(self, piece): if not isinstance(piece, MusicPiece): raise TypeError( 'A Piece object should be built using MusicPiece object' + ' as an argument.') self.soprano = NoteSeq(piece.soprano) self.alto = NoteSeq(piece.alto) self.tenor = NoteSeq(piece.tenor) self.bass = NoteSeq(piece.bass) self.title = piece.title self.parts = { "S": self.soprano, "A": self.alto, "T": self.tenor, "B": self.bass } self._key = [None, None] self._chords = [] self._err_count = 0 self._war_count = 0 self._err_detailed = [] self._war_detailed = [] self._read_chords() self._set_key()
def main(arguments): # Authenticate on Twitter auth_file = "auth.txt" with open(auth_file) as f: auth_list = f.readlines() f.close() consumer_key = auth_list[0].strip('\n') consumer_secret = auth_list[1].strip('\n') access_token_key = auth_list[2].strip('\n') access_token_secret = auth_list[3].strip('\n') api = twitter.Api(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_token_key, access_token_secret=access_token_secret) # Clean up arguments so it's just a list of hashtags arguments.pop('--help', None) #Remove --help option filename = arguments.pop('FILE', None) + ".mid" # Search for each of the given hashtags individually comboResults = [] for key in sorted(set(arguments)): comboResults.append(api.GetSearch(term="%23" + arguments[key])) # Create list of times and notes # Each hashtag has its own note # Major blues scale C, D, D♯/E♭, E, G, A scale = ["C", "D", "D#", "E", "G", "A"] results = [] for i in range(len(comboResults)): for twt in comboResults[i]: results.append((twt.created_at_in_seconds, scale[i])) # Sort notes in place by time results.sort(key=lambda tup: tup[0]) # Get a list of just notes notes = "" for i in results: notes = notes + i[1] + " " # Create MIDI file score = NoteSeq(notes) midi = Midi(1, tempo=90) midi.seq_notes(score, track=0) midi.write(filename)
def random_melody(note_list, octave_low, octave_high, dur_list): rm_seq = NoteSeq() #[] rm_data = [] melody_len = 0 while melody_len < 8: # while True if break bug pitch = random.choice(note_list) #refactor by root +2 +4 ... octave = random.randint(octave_low, octave_high) dur = random.choice(dur_list) vol = random.randrange(80, 125, 5) #refactor print([pitch, octave, dur, vol]) rm_seq.append(Note(pitch, octave, dur, vol)) #refactor rm_data.append([pitch, octave, dur, vol]) melody_len += dur print(melody_len) rm = [rm_seq, rm_data] return rm
def get_random_notes(n, pitches, durations, rests=True): if rests: pitches.append('r') result = NoteSeq() for i in range(n): pitch = random.choice(pitches) duration = random.choice(durations) if pitch == 'r': result.append(Rest(dur=duration)) else: result.append(Note(pitch, octave=4, dur=duration)) return result
def convert_chords_to_midi(chord_list, filename): '''Requires pyknon to create the midi...''' from pyknon.music import NoteSeq from pyknon.genmidi import Midi chord_prog = [] midi = Midi(1, tempo=90) for chord in chord_list: chord = chord.upper() chord = chord.replace('B', 'BB') chord = chord.replace('H', 'B') chord_prog.append(NoteSeq(chord)) midi.seq_chords(chord_prog, 0, 0) midi.write(filename)
def play_list(pitch_list, octave_list, duration, volume=120): result = NoteSeq() durl = [1/8, 1/8, 1/16, 1/16] cc = [choice([0,1,2,3,4,5,6,7,8,9,10,11]), choice([0,1,2,3,4,5,6,7,8,9,10,11]), choice([0,1,2,3,4,5,6,7,8,9,10,11]), choice([0,1,2,3,4,5,6,7,8,9,10,11])] st = 0 for pitch in pitch_list: note1 = pitch note = cc[st%4] #octave = choice_if_list(octave_list) octave = change_range(note1, 0, 11, 1, 7) #dur = choice_if_list(duration) dur = durl[st%4] st += 1 vol = choice_if_list(volume) result.append(Note(note, octave, dur, vol)) return result
def clean_freq(samples): "create freq samples" sample_size = len(samples) chords = [ NoteSeq([Note(classes[i]) for i in sample]) for sample in samples ] midi = Midi(1, tempo=tempo) for i in range(sample_size): midi.seq_chords([chords[i]], time=5 * i) midi.write("temp.mid") subprocess.call("timidity temp.mid -Ow -o temp.wav".split(), stdout=subprocess.PIPE) rate, data = wavfile.read('temp.wav') return channel_freqs( data.T[0])[:sample_size * 10:10].astype(int) / suppress_noise
def proc(centroid_list, num): num_notes = len(centroid_list)/4 notes = [] for i in range(num_notes): if num == 2: a, b = getSingleObj(centroid_list[i], centroid_list[i+1],\ centroid_list[i+2], centroid_list[i+3]) notes.append(a) notes.append(b) elif num == 1: a, b = getSingleObj(centroid_list[i], centroid_list[i+1], 0, 0) notes.append(a) pdb.set_trace() sequence = NoteSeq(notes) midi = Midi(i, tempo=90, instrument=0) midi.seq_notes(sequence, track=0) midi.write("temp.mid") play_music("temp.mid")
def genMelody(notes): scale = choice(Music.getScales(notes)) scaleName = Music.note_name(scale, -1).lower() + " major" print("scale:", scaleName) Melody = NoteSeq() Melody += notes currNotes = notes for note in notes: note.dur = choice(durations) print(notes.items) for i in range(4): currNotes = Transform(notes, scale) Melody += currNotes Melody += end(currNotes, scale) print(Melody.items) Music.getSheetMusic(Melody, scaleName.split()) return Melody
def make_midi(midi_path, notes, bpm=120): note_names = 'c c# d d# e f f# g g# a a# b'.split() result = NoteSeq() for n in notes: duration = 1. / n[1] if n[0].lower() == 'r': result.append(Rest(dur=duration)) else: pitch = n[0][:-1] octave = int(n[0][-1]) + 1 pitch_number = note_names.index(pitch.lower()) result.append(Note(pitch_number, octave=octave, dur=duration)) midi = Midi(1, tempo=bpm) midi.seq_notes(result, track=0) midi.write(midi_path)
def play_chord(notes, tempo, duration): """ notes is a list of indices: [C1, C#1, D1, D#1, E1, F1, F#1, G1, G#1, A1, A#1, B1, C2, C#2, D2, D#2, E2, F2, F#2, G2, G#2, A2, A#2, B2] """ chord = [] for note in notes: chord.append( Note(value=(note % 12), octave=((note // 12) + 4), dur=duration)) filepath = "chord.mid" midi = Midi(tempo=tempo) midi.seq_chords([NoteSeq(chord)]) midi.write(filepath) pg.init() pg.mixer.music.load(filepath) pg.mixer.music.play() os.remove(filepath)
def generate(self): rand_list = [] for i in range(1500): note = random.choice(self.note) if i<500: number = random.randrange(1,5) elif i>=500 and i<800: number = random.randrange(5,10) elif i>=800 and i<1000: number = random.randrange(10,15) else: number = random.randrange(15, 18) rand_list.append(note + str(number)) print(rand_list) self.sequence = rand_list notes = NoteSeq(' '.join(self.sequence)) midi = Midi(1, tempo=500) midi.seq_notes(notes, track=0) midi.write(file_name) subprocess.call(["timidity", file_name])
def main(): new = input('Do you want to creat a new random melody? ') if new == 'y': note_list = [0, 2, 4, 6, 7, 9, 11] #refactor by root +2 +4 ... octave_low = 5 octave_high = 6 dur_list = [0.125, 0.25, 0.5] rm = random_melody(note_list, octave_low, octave_high, dur_list) rm_seq, rm_data = rm print(rm_seq) store_rm(rm_data, 'random_melody_in_C_data.csv') elif new == 'n': rm_data = open_rm('random_melody_in_C_data.csv') rm_seq = NoteSeq( ) #rm_seq = NoteSeq([Note(int(p[0])) for p in rm_data]) for p in rm_data: rm_seq.append(Note(p[0], p[1], p[2], p[3])) print(rm_seq) # cprog6251r = chord_prog([9, 2, 7, 0]) # cprog62513 = chord_prog([0, 5, 11, 4]) #inversion 9 0 # gen_midi(rm_seq, cprog6251r, cprog62513, 'random_melody_in_C_3.mid') fsprog = fusion_prog_rym(rm_data, [0], [10, 11], [14]) fsprogr, fsprog7, fsprog9 = fsprog gen_midi(rm_seq, fsprogr, fsprog7, fsprog9, 'random_melody_in_C_.mid')
seqLine3 = text_to_bits(LINE3) seq1 = list(seqLine1) seq2 = list(seqLine2) seq3 = list(seqLine3) for i in range(len(seq1)): seq1[i] = int(seq1[i]) seq2[i] = int(seq2[i]) seq3[i] = int(seq3[i]) for i in range(len(seq1)): seq1[i] += SHIFT1 seq2[i] += SHIFT2 seq3[i] += SHIFT3 finalSequence = [] for i in range(len(seq1)): finalSequence.append(seq1[i]) finalSequence.append(seq2[i]) finalSequence.append(seq3[i]) midi = Midi(tempo=SPEED) midi.seq_notes( NoteSeq([ Note(value=x, octave=4, dur=1 / 16, volume=127) for x in finalSequence ])) midi.write("file.mid")
h = [] s = [] v = [] for i in data: print(i) c = colorsys.rgb_to_hsv(i[0]/255,i[1]/255,i[2]/255) print(c) all.append(c) #h.append(int(c[0]*12)) #s.append(int(c[1]*8)+1) #v.append(c[2]) if c[2] > 0.5: s = 1/8 else: s = 1/16 seq.append( (int(c[0]*12),int(c[1]*8)+1,s)) #print all baseSeq = [] for i in range(int(len(seq)/4)): baseSeq.append([0,4,7][i%3]) #seq = chain.from_iterable(data) midi = Midi(number_tracks=2,tempo=120) #Note(note from 0-11, pitch(octave), length(in beat)) #midi.seq_notes(NoteSeq([Note(x%12, 4, 1/8) for x in seq])) midi.seq_notes(NoteSeq([Note(x, 4, 1/4) for x in baseSeq]),track=0) midi.seq_notes(NoteSeq([Note(x[0], x[1], x[2]) for x in seq]),track=1) midi.write("output.mid") #fluidsynth -T wav -F output.wav Piano.sf2
from pyknon.genmidi import Midi from pyknon.music import NoteSeq notes1 = NoteSeq("D4 F#8 A Bb4") midi = Midi(1, tempo=90, instrument=53) midi.seq_notes(notes1, track=0) midi.write("output/demo.mid")
# major root done = 0 for octave in range(2, 9): for note in range(12): if (note == 0) and (octave == 2): # start on C#2 continue if (note == 3) and (octave == 8): # end on D8 done = 1 break for volume_note1 in [80, 100, 120]: for volume_note2 in [80, 100, 120]: for volume_note3 in [80, 100, 120]: note1 = NoteSeq([ Note(value=note, octave=octave, dur=1 / 16, volume=volume_note1) ]) note2_str = note_above(int_to_note(note) + str(octave), 4) note2 = NoteSeq([ Note(value=note_to_int(note2_str), octave=int(note2_str[-1]), dur=1 / 16, volume=volume_note2) ]) note3_str = note_above(int_to_note(note) + str(octave), 7) note3 = NoteSeq([ Note(value=note_to_int(note3_str), octave=int(note3_str[-1]),