From 4cf91550b8f21c2d51f619960811b2819cde1ed9 Mon Sep 17 00:00:00 2001 From: Benjamin Maier Date: Thu, 6 Jun 2019 17:33:32 +0200 Subject: [PATCH 1/3] fixed wrong keybindings on Mac --- FoxDot/lib/Workspace/Editor.py | 4 ++-- FoxDot/lib/Workspace/tmp/tempfile.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/FoxDot/lib/Workspace/Editor.py b/FoxDot/lib/Workspace/Editor.py index e5790572..10da196c 100644 --- a/FoxDot/lib/Workspace/Editor.py +++ b/FoxDot/lib/Workspace/Editor.py @@ -199,8 +199,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 index e69de29b..ef1d7d76 100644 --- a/FoxDot/lib/Workspace/tmp/tempfile.txt +++ b/FoxDot/lib/Workspace/tmp/tempfile.txt @@ -0,0 +1,2 @@ +d1 >> play("x--- ---") +qd2 >> play(" o([---] ) ",room=10) \ No newline at end of file From ce713135163bb2f6c656b32d3e7d5572fba808c3 Mon Sep 17 00:00:00 2001 From: Benjamin Maier Date: Tue, 11 Jun 2019 10:59:37 +0200 Subject: [PATCH 2/3] removed text file --- FoxDot/lib/Workspace/tmp/tempfile.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 FoxDot/lib/Workspace/tmp/tempfile.txt diff --git a/FoxDot/lib/Workspace/tmp/tempfile.txt b/FoxDot/lib/Workspace/tmp/tempfile.txt deleted file mode 100644 index ef1d7d76..00000000 --- a/FoxDot/lib/Workspace/tmp/tempfile.txt +++ /dev/null @@ -1,2 +0,0 @@ -d1 >> play("x--- ---") -qd2 >> play(" o([---] ) ",room=10) \ No newline at end of file From 11e5efcf87c820d17aaea4f34ab630d822c8d2d8 Mon Sep 17 00:00:00 2001 From: Benjamin Maier Date: Sun, 1 Sep 2019 00:28:17 +0200 Subject: [PATCH 3/3] added initial idea for a melody function --- sandbox/bar_melody.py | 178 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 sandbox/bar_melody.py 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