|
@@ -1,41 +1,20 @@
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
from midiutil import MIDIFile
|
|
|
-from mingus.core import chords
|
|
|
+import mingus.core.notes as notes
|
|
|
+import mingus.core.chords as chords
|
|
|
|
|
|
-NOTES = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B']
|
|
|
OCTAVES = list(range(11))
|
|
|
-NOTES_IN_OCTAVE = len(NOTES)
|
|
|
+NOTES_IN_OCTAVE = 12
|
|
|
|
|
|
errors = {
|
|
|
'notes': 'Bad input please refer this spec-\n',
|
|
|
}
|
|
|
|
|
|
-def swap_accidentals(note):
|
|
|
- match note:
|
|
|
- case 'Db':
|
|
|
- return 'C#'
|
|
|
- case 'D#':
|
|
|
- return 'Eb'
|
|
|
- case 'E#':
|
|
|
- return 'F'
|
|
|
- case 'Gb':
|
|
|
- return 'F#'
|
|
|
- case 'G#':
|
|
|
- return 'Ab'
|
|
|
- case 'A#':
|
|
|
- return 'Bb'
|
|
|
- case 'B#':
|
|
|
- return 'C'
|
|
|
- case _:
|
|
|
- return note
|
|
|
-
|
|
|
def note_to_number(note: str, octave: int) -> int:
|
|
|
- note = swap_accidentals(note)
|
|
|
- assert note in NOTES, errors['notes']
|
|
|
assert octave in OCTAVES, errors['notes']
|
|
|
|
|
|
- notenum = NOTES.index(note)
|
|
|
+ notenum = notes.note_to_int(note)
|
|
|
notenum += (NOTES_IN_OCTAVE * octave)
|
|
|
|
|
|
assert 0 <= notenum <= 127, errors['notes']
|
|
@@ -61,11 +40,11 @@ bass_nums = [note_to_number(x, bass_octave) for x in bass_notes]
|
|
|
arpeggio_track = 0
|
|
|
bass_track = 1
|
|
|
channel = 0
|
|
|
-time = 0 # in beats
|
|
|
-arpeggio_duration = 1 # in beats
|
|
|
-bass_duration = 4 # in beats
|
|
|
-tempo = 120 # in BPM
|
|
|
-volume = 100 # 0-127
|
|
|
+time = 0 # in beats
|
|
|
+arpeggio_duration = 1 # in beats
|
|
|
+bass_duration = 4 # in beats
|
|
|
+tempo = 120 # in BPM
|
|
|
+volume = 100 # 0-127
|
|
|
|
|
|
MyMIDI = MIDIFile(2) # two tracks, defaults to format 1
|
|
|
# tempo track is created automatically
|