In [20]:
import os
In [1]:
notesDict = {}
with open('notes.tabs', 'rt') as f:
for line in f:
note, freq, wave = (line.replace('\n','').replace(' ', '').split('\t'))
for note in note.split('/'):
notesDict[note] = freq
In [2]:
def appendToFile(path, data):
"""
appendToFile appends a line of data to specified file. Then adds new line
Args:
path (string): the file path
data (data): the data to be written
Return:
VOID
"""
with open(path, 'a') as file:
file.write(data + '\n')
In [3]:
def writeSong(path, song, notesDict, metronome):
for note, time in twinkleTwinkle:
time = int(float(1000 * 60 * 4 * time / 80))
data = ("{},{}".format(int(float(notesDict[note])), time))
appendToFile(path, data)
In [4]:
metronome = 40
In [16]:
pause = ['D3', 1/2]
In [12]:
twinkleTwinkle = [['C5', 1/4], ['C5', 1/4], ['G5', 1/4], ['G5', 1/4],
['A5', 1/4], ['A5', 1/4], ['G5', 1/2],
['F5', 1/4], ['F5', 1/4], ['E5', 1/4], ['E5', 1/4],
['D5', 1/4], ['D5', 1/4], ['C5', 1/2],
]
In [17]:
song = []
for note in twinkleTwinkle:
song.append(note)
song.append(pause)
In [19]:
In [21]:
os.remove('twinkleTwinkle.csv')
writeSong('twinkleTwinkle.csv', song, notesDict, metronome)
In [ ]: