Skip to content
Snippets Groups Projects
Verified Commit d3b98b20 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add support for octave tracking like in Mir(?)BSD, closes #4.

parent 9cde6b6a
No related branches found
No related tags found
1 merge request!5Add support for octave tracking like in Mir(?)BSD, closes #4.
......@@ -35,7 +35,11 @@ Symbols of MML
:O(n):
Octave 0 sets the current octave. There are 7 octaves (0 through 6).
Default is 4. Middle C is at the beginning of octave 2.
Default is 4. Middle C is at the beginning of octave 2. The special
values L and N control octave tracking. L enables octave tracking, N
disables it; with octave tracking enabled, jumps between notes are
limited to 6 half-tones, otherwise, the octave is incremented or
decremented accordingly. Octave tracking is disabled by default.
:P(n):
Pause. n may range from 1-64; the current L value is used if omitted.
......
......@@ -200,6 +200,8 @@ def mml(macro, _nplay=None, _barline=None):
art = 'N'
bpm = 120
octave = 4
octave_tracking = False
octave_tracking_last_note = None
timevalue = 4
# normalise macro string, create input list
......@@ -222,6 +224,12 @@ def mml(macro, _nplay=None, _barline=None):
if char in _MML_NAME2STEP.keys():
# base note
note = 12 * octave + _MML_NAME2STEP[char]
if octave_tracking and octave_tracking_last_note:
if note - octave_tracking_last_note > 6:
octave -= 1
elif note - octave_tracking_last_note < -6:
octave += 1
note = 12 * octave + _MML_NAME2STEP[char]
extra = (octave, char, u'')
# accidental sign
......@@ -242,6 +250,8 @@ def mml(macro, _nplay=None, _barline=None):
# sustain dots, and play the note
_play(macro, res, bpm, art, note, _length, extra)
# remember last note for octave tracking
octave_tracking_last_note = note
elif char == "L":
timevalue = _getint(macro, 1, 64, 4)
......@@ -257,7 +267,14 @@ def mml(macro, _nplay=None, _barline=None):
_play(macro, res, bpm, art, note, timevalue, note)
elif char == "O":
octave = _getint(macro, 0, 6, 4)
if macro[0].isdigit():
octave = _getint(macro, 0, 6, 4)
else:
char = macro.pop(0)
if char == "L":
octave_tracking = True
elif char == "N":
octave_tracking = False
elif char == "P":
_length = _getint(macro, 1, 64, timevalue)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment