Browse Source

merge transforming functions

Paola Fontana Gasio 4 years ago
parent
commit
e10b2a6e19
4 changed files with 119 additions and 71 deletions
  1. 49 31
      src/gizmo_transforming_functions.py
  2. 64 34
      src/thema-gen
  3. 3 3
      tests/start-haenschen-klein
  4. 3 3
      tests/testfile

+ 49 - 31
src/gizmo_transforming_functions.py

@@ -1,9 +1,6 @@
 
 
-""" helper functions """
-# temporary notation fix
 
 
-def fix_temp(note):
-    return note[:4] + note[6:]
+""" helper functions """
 
 
 # converts float duration to string in the form x.xx
 # converts float duration to string in the form x.xx
 def duration_to_string(input_float_duration):
 def duration_to_string(input_float_duration):
@@ -20,28 +17,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 """
@@ -50,7 +54,7 @@ def interval(note_1, note_2):
 def tempo(input_list, temp):
 def tempo(input_list, temp):
     working_list = []
     working_list = []
     for note in input_list:
     for note in input_list:
-        duration = float (note[0:4]) * float(temp)
+        duration = float (note[0:4]) * temp
         note = duration_to_string(duration) + note[4:]
         note = duration_to_string(duration) + note[4:]
         working_list.append(note)
         working_list.append(note)
     return working_list
     return working_list
@@ -63,7 +67,7 @@ def verkleinerung(input_list):
 def vergrösserung(input_list):
 def vergrösserung(input_list):
     return tempo(input_list, 2)
     return tempo(input_list, 2)
 
 
-    # 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 = note.split(',')
     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']
@@ -83,13 +87,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):
@@ -100,14 +104,28 @@ 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:
-        tmp_note = highes_note(mirror, - interval(mirror, note))
-        working_list.append(tmp_note)
+        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
     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
+
+
 # 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]

+ 64 - 34
src/thema-gen

@@ -28,7 +28,8 @@ except (IndexError, ValueError):
     number = 4 
     number = 4 
 
 
 #output_list = sequenz(stdin_list, 1)
 #output_list = sequenz(stdin_list, 1)
-output_list2 = verkleinerung(stdin_list)
+motiv_list = verkleinerung(stdin_list)
+#motiv_list = stdin_list
 
 
 # create lists
 # create lists
 for i in range(number):
 for i in range(number):
@@ -38,39 +39,68 @@ for i in range(number):
 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 = [\
-    "verkleinerung(output_list2)",\
-    "krebs(output_list2)",\
-    "vergrösserung(output_list2)",\
-    "output_list2",\
-    "sequenz(output_list2, 1)"\
+function_list = [
+    "verkleinerung(motiv_list)",
+    "krebs(motiv_list)",
+    "vergrösserung(motiv_list)",
+    "motiv_list",
+    "sequenz(motiv_list, 5)"
     ]
     ]
 
 
-# adjust function_list to the entered number
-if number < len(function_list):
-    # if smaller, simply cut/strip it
-    function_list = function_list[:number]
-elif number > len(function_list):
-    for i in range(number-len(function_list)):
-        function_list.append(random.choice(function_list))
-
-# randomize the list
-random.shuffle(function_list)
-
-# OPTIONAL: add some post procession here
-
-# DEBUG:
-#print(len(function_list))
-#print(function_list)
-
-# now run each item through a list
-for i in range(number):
-    exec("list%s = %s" % (str(i),str(function_list[i])))
-
-# append lists
-final_list = []
-for i in range(number):
-    exec("final_list.extend(list%s)" % (str(i)))
-
-# write to stdout
+def first_equals_last_pitch(input_list):
+    is_same_pitch = not(bool(interval(fix_temp(input_list[0]), fix_temp(input_list[-1]))))
+    return is_same_pitch
+
+"""copy over function_list and start main loop that stops when every post
+processing requirement is satified"""
+
+# default values are all all generating 'False' to simulate a 'do while' loop
+final_list = ['1.00,D4','1.00,C3']
+
+while not(first_equals_last_pitch(final_list)):
+    working_list = function_list
+    
+    # adjust working_list to the entered number
+    if number < len(working_list):
+        # if smaller, simply randomize + cut/strip it
+        random.shuffle(working_list)
+        working_list = working_list[:number]
+    elif number > len(working_list):
+        for i in range(number-len(working_list)):
+            working_list.append(random.choice(working_list))
+    
+    # randomize the list
+    random.shuffle(working_list)
+    
+    # OPTIONAL: add some post procession here
+    
+    # now run each item through a list
+    for i in range(number):
+        exec("list%s = %s" % (str(i),str(working_list[i])))
+    
+    # append lists
+    final_list = []
+    for i in range(number):
+        exec("final_list.extend(list%s)" % (str(i)))
+    
+    """
+    DEBUG:
+
+    print(len(working_list))
+    print(working_list)
+
+    print(final_list)
+    print(len(motiv_list))
+    unzip_string = "item0"
+    for i in range(1, len(motiv_list)):
+        unzip_string += ", item%s" % (str(i))
+    print(unzip_string)
+    exec("for %s in zip(*[iter(final_list)]*%s): print(%s)" % (unzip_string, str(len(motiv_list)), unzip_string))
+    print(motiv_list)
+    
+    print(first_equals_last_pitch(final_list))
+    print(interval('1.00C4','1.00C4'))
+    """
+    
+# finally, write to standard output
 gizmo_stdout(final_list)
 gizmo_stdout(final_list)

+ 3 - 3
tests/start-haenschen-klein

@@ -1,3 +1,3 @@
-0.5,G4
-0.5,E4
-1.0,E4
+0.50,G4
+0.50,E4
+1.00,E4

+ 3 - 3
tests/testfile

@@ -1,3 +1,3 @@
-1.0,C4
-2.0,C3
-4.0,D#4
+1.00,C4
+2.00,C3
+4.00,D#4