diff --git a/FoxDot/lib/Workspace/Editor.py b/FoxDot/lib/Workspace/Editor.py index 828def9c..c730afaf 100644 --- a/FoxDot/lib/Workspace/Editor.py +++ b/FoxDot/lib/Workspace/Editor.py @@ -193,8 +193,8 @@ def check_versions(): # Key bindings (Use command key on Mac) - ctrl = "Command" if SYSTEM == MAC_OS else "Control" - alt = "Option" if SYSTEM == MAC_OS else "Alt" + ctrl = "Mod2" if SYSTEM == MAC_OS else "Control" + alt = "Control" if SYSTEM == MAC_OS else "Alt" self.text.bind("<>", self.on_text_modified) diff --git a/FoxDot/lib/Workspace/tmp/tempfile.txt b/FoxDot/lib/Workspace/tmp/tempfile.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/sandbox/bar_melody.py b/sandbox/bar_melody.py new file mode 100644 index 00000000..54ed6a48 --- /dev/null +++ b/sandbox/bar_melody.py @@ -0,0 +1,178 @@ +from FoxDot.lib.Players import rest + +def melody(s,n_bars=1,base_duration=4,verbose=False): + """ + Convert a melody string to triple of note values, + note durations and note sustain values. + + A melody string could look something like this: + + >>> s = "0123" + + which translates to ``Cut the bar in four fourth notes, + whith values [ 0, 1, 2, 3].'' + + Another example would be + + >>> s = "0.1.2.3." + + which translates to ``Cut the bar in eight eigths, + but play only four eights notes, each of which is followed + by an eigth rest. Note values like above.`` + + Notes can, however, be sustained like so: + + >>> s = "0=1.2.3." + + which is similar to the last case, besides the fact that + the first note will not be followed by a rest but be + sustained until the second note is played. The following + string would yield the same melody + + >>> s = "0===1=..2=..3=.." + + Note that in this example, one character corresponds to + a 16th note. + + This can become quite messy to overlook, so one may add + the "|" character as a visual aid. The function will + ignore this character. The string + + >>> s = "0===|1=..|2=..|3=.." + + would therefore yield the same result as the last two + strings. + + Final example: melody strings can begin with a rest: + + >>> s = ".0=.|1...|2...|3..." + + + Parameters + ========== + s : str + The melody string. + n_bars : int, default = 1 + The number of bars this melody string is supposed to span. + base_duration : float, default = 4 + The duration of a single bar (in beats). + verbose : bool, default = False + Be chatty. + + Returns + ======= + notes : list of int + The notes to play. + durs : list of float + The corresponding note durations. + suss : list of float + The corresponding note sustain values. + """ + + # check if the input is a string + if type(s) != str: + raise TypeError("s has to be a String") + + # remove all "|" character as those are supposed to be helpers + s = s.replace("|","") + + # raise an error if the melody string is empty + if len(s) == 0: + raise ValueError("There's no notes in this bar (length 0)") + + # calculate the duration of this whole melody, + # the total number of notes + # and duration of a single character + barlength = base_duration * n_bars + n_notes = len(s) + note_duration = barlength / n_notes + + # define empty notes (rests) + empty = [" ","."] + + # initialize return lists + notes = [] + durs = [] + suss = [] + + # check first character (check whether to begin with a rest) + i = 0 + initial_note_is_rest = s[0] in empty + + if initial_note_is_rest: + + # this first note is going to be muted, so we just assign value 0 + notes.append(0) + + # while the string contains rests, increase the rest duration + initial_rest = 0 + while (i