Browse Source

cleanup highes_note

Paola Fontana Gasio 4 years ago
parent
commit
d89171bb56
2 changed files with 79 additions and 70 deletions
  1. 5 4
      src/gizmo_transforming_functions.py
  2. 74 66
      tests/test.py

+ 5 - 4
src/gizmo_transforming_functions.py

@@ -1,5 +1,7 @@
+
 """ helper functions """
 # temporary notation fix
+
 def fix_temp(note):
     return note[:4] + note[6:]
 
@@ -29,7 +31,8 @@ def convert_multiple_key_signetures(note):
             note = note[:5] + note[7:]
     return note
 
-# TODO: add description
+# returns the pitch difference from two notes
+
 def interval(note_1, note_2):
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
     octave = int(note_2[-1:]) - int(note_1[-1:])
@@ -90,7 +93,6 @@ def highes_note(note, value):
     return note
 
 # returns a part higher by some value
-# TODO: not dynamically working as intended
 def sequenz(input_list, value):
     working_list = []
     for n in input_list:
@@ -99,16 +101,15 @@ def sequenz(input_list, value):
     return working_list
 
 # mirrors notes at the first note
-# TODO: not dynamically working as intended
 def mirror(input_list):
     working_list = []
     mirror = input_list[0]
     for note in input_list:
         tmp_note = highes_note(mirror, - interval(mirror, note))
-        print (tmp_note)
         working_list.append(tmp_note)
     return working_list
 
 # reverses list of notes (krebs)
 def krebs(input_list):
     return input_list[::-1]
+    

+ 74 - 66
tests/test.py

@@ -1,39 +1,18 @@
 
-# returns a part higher by some value
-def sequenz(input_list, value):
-    working_list = []
-    for n in input_list:
-        note = highes_note(n, value)
-        working_list.append(note)
-    return working_list
+""" helper functions """
 
-# return the note higher by a value (1 = half a step)
-def highes_note(note, value):
-    notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
-    is_up = True
-    if value < 0:
-        notes_list.reverse()
-        value = -value
-        is_up = False
-    tmp_note = note[:4]
-    pitch = note[4:5]
-    ord_number = notes_list.index(pitch)
-    octave = int(note[-1:])
-    ord_number += value
-    while ord_number >= 12:
-        if is_up:
-            octave += 1
-        else:
-            octave -= 1
-        ord_number = ord_number - 12
-    if note[5:6] == '#':
-        note = tmp_note + notes_list[ord_number] + '#' + str(octave)
-    elif note[5:6] == '-':
-        note = tmp_note + notes_list[ord_number] + '-' + str(octave)
-    else:
-        note = tmp_note + notes_list[ord_number] + str(octave)
-    note = convert_multiple_key_signetures(note)
-    return note
+# converts float duration to string in the form x.xx
+def duration_to_string(input_float_duration):
+    input_float_duration *= 100
+    input_int_duration = int(input_float_duration)
+    duration = ""
+    for i in range (0, 3):
+        x = input_int_duration % 10
+        duration = duration + str(x)
+        input_int_duration = input_int_duration // 10
+    duration = duration[::-1]
+    duration = duration[:1] + '.' + duration[1:]
+    return duration
 
 # converts the weird notation like -#, ## or -- to nothing, one note higher or lower respectivly
 def convert_multiple_key_signetures(note):
@@ -47,19 +26,9 @@ def convert_multiple_key_signetures(note):
         if note[5:7] == "-#" or note[5:7] == "#-":
             note = note[:5] + note[7:]
     return note
-    
-# mirrors notes at the first note
-def mirror(input_list):
-    working_list = []
-    mirror = input_list[0]
-    for note in input_list:
-        tmp_note = highes_note(mirror, - interval(mirror, note))
-        print (tmp_note)
-        working_list.append(tmp_note)
-    return working_list
 
+# returns the pitch difference from two notes
 
-# returns pitch difference of two notes
 def interval(note_1, note_2):
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
     octave = int(note_2[-1:]) - int(note_1[-1:])
@@ -70,30 +39,69 @@ def interval(note_1, note_2):
     if note_1[5:6] == '-': pitch += 1
     if note_2[5:6] == '#': pitch += 1
     return pitch
+    
+""" actual functions """
 
-h = ['0.50G4', '0.50E4','1.00E4']
-print (mirror(h))
+# changes tempo
+def tempo(input_list, temp):
+    working_list = []
+    for note in input_list:
+        duration = float (note[0:4]) * temp
+        note = duration_to_string(duration) + note[4:]
+        working_list.append(note)
+    return working_list
 
-"""
-note_1 = '1.00D-5'
-note_2 = '0.25F#4'
-print (interval(note_2, note_1))
+# half duration
+def verkleinerung(input_list):
+    return tempo(input_list, .5)
 
-l = ['1.00D#5', '0.25F-4', '0.50C5']
-print (l)
-print(sequenz(l, 3))
-for i in range(0, 3):
-    print('for loop ', i)
-    print(sequenz(l, -i))
+# double duration
+def vergrösserung(input_list):
+    return tempo(input_list, 2)
 
-print(highes_note('1.00D5', 2))
-print(highes_note('1.00D5', -2))
-print(highes_note('1.00D5', 13))
-print(highes_note('1.00D5', -13))
+    # return the note higher by a value (1 = half a step)
+def highes_note(note, value):
+    note = note.split(',')
+    notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
+    is_up = True
+    if value < 0: # check if value is negative and store in is_up
+        notes_list.reverse()
+        value = -value
+        is_up = False
+    pitch = note[1][:1] # first char from 2nd list argument
+    ord_number = notes_list.index(pitch)
+    octave = int(note[1][-1:])
+    ord_number += value
+    while ord_number >= 12:
+        if is_up:
+            octave += 1
+        else:
+            octave -= 1
+        ord_number = ord_number - 12
+    if note[1][1:2] == '#': # 2nd char from 2nd list argument
+        note = note[0] + notes_list[ord_number] + '#' + str(octave)
+    elif note[1][1:2] == '-':
+        note = note[0] + notes_list[ord_number] + '-' + str(octave)
+    else:
+        note = note[0] + notes_list[ord_number] + str(octave)
+    note = convert_multiple_key_signetures(note)
+    return note
+
+# returns a part higher by some value
+def sequenz(input_list, value):
+    working_list = []
+    for n in input_list:
+        note = highes_note(n, value)
+        working_list.append(note)
+    return working_list
 
+# mirrors notes at the first note
+def mirror(input_list):
+    working_list = []
+    mirror = input_list[0]
+    for note in input_list:
+        note[0] = highes_note(mirror, - interval(mirror, note))
+        working_list.append(note[0])
+    return working_list
 
-print(convert_multiple_key_signetures('1.00D##5'))
-print(convert_multiple_key_signetures('1.00D#-5'))
-print(convert_multiple_key_signetures('1.00D--5'))
-print(convert_multiple_key_signetures('1.00D5'))
-"""
+print(highes_note('1.00,D#4', 2))