Browse Source

new notation, now pitch and tempo are seperatet by ',' and added mirror_rythme function

Paola Fontana Gasio 4 years ago
parent
commit
269cc9c18a
3 changed files with 78 additions and 39 deletions
  1. 9 11
      src/gizmo_transforming_functions.py
  2. 3 2
      src/thema-gen
  3. 66 26
      tests/test.py

+ 9 - 11
src/gizmo_transforming_functions.py

@@ -65,17 +65,16 @@ def vergrösserung(input_list):
 
 
     # return the note higher by a value (1 = half a step)
     # return the note higher by a value (1 = half a step)
 def highes_note(note, value):
 def highes_note(note, value):
-    note = fix_temp(note)
+    note = note.split(',')
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
     is_up = True
     is_up = True
-    if value < 0:
+    if value < 0: # check if value is negative and store in is_up
         notes_list.reverse()
         notes_list.reverse()
         value = -value
         value = -value
         is_up = False
         is_up = False
-    tmp_note = note[:4]
-    pitch = note[4:5]
+    pitch = note[1][:1] # first char from 2nd list argument
     ord_number = notes_list.index(pitch)
     ord_number = notes_list.index(pitch)
-    octave = int(note[-1:])
+    octave = int(note[1][-1:])
     ord_number += value
     ord_number += value
     while ord_number >= 12:
     while ord_number >= 12:
         if is_up:
         if is_up:
@@ -83,12 +82,12 @@ def highes_note(note, value):
         else:
         else:
             octave -= 1
             octave -= 1
         ord_number = ord_number - 12
         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)
+    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:
     else:
-        note = tmp_note + notes_list[ord_number] + str(octave)
+        note = note[0] + notes_list[ord_number] + str(octave)
     note = convert_multiple_key_signetures(note)
     note = convert_multiple_key_signetures(note)
     return note
     return note
 
 
@@ -112,4 +111,3 @@ def mirror(input_list):
 # reverses list of notes (krebs)
 # reverses list of notes (krebs)
 def krebs(input_list):
 def krebs(input_list):
     return input_list[::-1]
     return input_list[::-1]
-    

+ 3 - 2
src/thema-gen

@@ -35,14 +35,15 @@ for i in range(number):
     exec("list%s = []" % (str(i)))
     exec("list%s = []" % (str(i)))
 
 
 # list of indexes from the motive list without repetition
 # list of indexes from the motive list without repetition
-index_list = random.sample(range(0,number), number)
+index_list = random.sample(range(0,number), number) 
 
 
 # list of functions to use
 # list of functions to use
 function_list = [\
 function_list = [\
     "verkleinerung(output_list2)",\
     "verkleinerung(output_list2)",\
     "krebs(output_list2)",\
     "krebs(output_list2)",\
     "vergrösserung(output_list2)",\
     "vergrösserung(output_list2)",\
-    "output_list2"\
+    "output_list2",\
+    "sequenz(output_list2, 1)"\
     ]
     ]
 
 
 # adjust function_list to the entered number
 # adjust function_list to the entered number

+ 66 - 26
tests/test.py

@@ -16,28 +16,35 @@ def duration_to_string(input_float_duration):
 
 
 # converts the weird notation like -#, ## or -- to nothing, one note higher or lower respectivly
 # converts the weird notation like -#, ## or -- to nothing, one note higher or lower respectivly
 def convert_multiple_key_signetures(note):
 def convert_multiple_key_signetures(note):
-    while len(note) > 7:
-        if note[5:7] == "##":
-            note = note[:5] + note[7:]
-            note = highes_note(note, 2)
-        if note[5:7] == "--":
-            note = note[:5] + note[7:]
-            note = highes_note(note, -2)
-        if note[5:7] == "-#" or note[5:7] == "#-":
-            note = note[:5] + note[7:]
-    return note
+    conv_note = note
+    note = note.split(',')
+    while len(note[1]) > 3:
+        if note[1][1:3] == "##":
+            note[1] = note[1][:1] + note[1][-1:] #remove ##
+            conv_note = note[0] + ',' + note[1] #built new note
+            conv_note = highes_note(conv_note, 2) #highes note by 2
+        elif note[1][1:3] ==  "--":
+            note[1] = note[1][:1] + note[1][-1:] #remove --
+            conv_note = note[0] + ',' + note[1] #built new note
+            conv_note = highes_note(conv_note, -2) #highes note by 2
+        elif note[1][1:3] == "-#" or note[1][1:3] == "#-":
+            note[1] = note[1][:1] + note[1][-1:] #remove #- or -#
+            conv_note = note[0] + ',' + note[1] #built new note
+    return conv_note
 
 
 # returns the pitch difference from two notes
 # returns the pitch difference from two notes
-
+# assumes that last char is octave indicater
 def interval(note_1, note_2):
 def interval(note_1, note_2):
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
     notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
-    octave = int(note_2[-1:]) - int(note_1[-1:])
-    pitch = notes_list.index(note_2[4:5]) - notes_list.index(note_1[4:5])
+    note_1 = note_1.split(',')
+    note_2 = note_2.split(',')
+    octave = int(note_2[1][-1:]) - int(note_1[1][-1:])
+    pitch = notes_list.index(note_2[1][:1]) - notes_list.index(note_1[1][:1])
     pitch += 12 * octave
     pitch += 12 * octave
-    if note_1[5:6] == '#': pitch -= 1
-    if note_2[5:6] == '-': pitch -= 1
-    if note_1[5:6] == '-': pitch += 1
-    if note_2[5:6] == '#': pitch += 1
+    if note_1[1][1:2] == '#': pitch -= 1
+    if note_2[1][1:2] == '-': pitch -= 1
+    if note_1[1][1:2] == '-': pitch += 1
+    if note_2[1][1:2] == '#': pitch += 1
     return pitch
     return pitch
     
     
 """ actual functions """
 """ actual functions """
@@ -79,13 +86,13 @@ def highes_note(note, value):
             octave -= 1
             octave -= 1
         ord_number = ord_number - 12
         ord_number = ord_number - 12
     if note[1][1:2] == '#': # 2nd char from 2nd list argument
     if note[1][1:2] == '#': # 2nd char from 2nd list argument
-        note = note[0] + notes_list[ord_number] + '#' + str(octave)
+        higher_note = note[0] + ',' + notes_list[ord_number] + '#' + str(octave)
     elif note[1][1:2] == '-':
     elif note[1][1:2] == '-':
-        note = note[0] + notes_list[ord_number] + '-' + str(octave)
+        higher_note = note[0] + ',' + notes_list[ord_number] + '-' + str(octave)
     else:
     else:
-        note = note[0] + notes_list[ord_number] + str(octave)
-    note = convert_multiple_key_signetures(note)
-    return note
+        higher_note = note[0] + ',' + notes_list[ord_number] + str(octave)
+    higher_note = convert_multiple_key_signetures(higher_note)
+    return higher_note
 
 
 # returns a part higher by some value
 # returns a part higher by some value
 def sequenz(input_list, value):
 def sequenz(input_list, value):
@@ -96,12 +103,45 @@ def sequenz(input_list, value):
     return working_list
     return working_list
 
 
 # mirrors notes at the first note
 # mirrors notes at the first note
-def mirror(input_list):
+def mirror_pitch(input_list):
     working_list = []
     working_list = []
     mirror = input_list[0]
     mirror = input_list[0]
     for note in input_list:
     for note in input_list:
-        note[0] = highes_note(mirror, - interval(mirror, note))
-        working_list.append(note[0])
+        pitch = highes_note(mirror, - interval(mirror, note)) # change pitch
+        note = note.split(',')
+        pitch = pitch.split(',')
+        mir_note = note[0] + ',' + pitch[1] # take duration from "note"
+        working_list.append(mir_note)
+    return working_list
+
+# mirrors the rythme from back to front
+def mirror_rythm(input_list):
+    r_input_list = input_list[::-1]
+    working_list = [] # revesed list
+    for i in range (0, len(input_list)):
+        r_note = r_input_list[i].split(',')
+        n_note = input_list[i].split(',')
+        working_list.append(r_note[0] + ',' + n_note[1]) 
     return working_list
     return working_list
+    
+
+l = [
+'0.50,D4',
+'1.00,E4',
+'0.25,D4',
+'1.00,C4'
+]
+"""
+print('list')
+print(l)
+print('verkleinerung')
+print (verkleinerung(l))
+print('vergrösserung')
+print(vergrösserung(l))
+print('sequenz')
+print(sequenz(l, 1))
+"""
+print('mirror')
+print (l)
+print(mirror_rythm(l))
 
 
-print(highes_note('1.00,D#4', 2))