Browse Source

added main loop width conditions in thema generator

Noah 4 years ago
parent
commit
7bdaa18168
4 changed files with 73 additions and 42 deletions
  1. 3 3
      src/gizmo_transforming_functions.py
  2. 64 33
      src/thema-gen
  3. 3 3
      tests/start-haenschen-klein
  4. 3 3
      tests/testfile

+ 3 - 3
src/gizmo_transforming_functions.py

@@ -3,7 +3,7 @@
 # temporary notation fix
 
 def fix_temp(note):
-    return note[:4] + note[6:]
+    return note[:4] + note[5:]
 
 # converts float duration to string in the form x.xx
 def duration_to_string(input_float_duration):
@@ -97,7 +97,7 @@ def sequenz(input_list, value):
     working_list = []
     for n in input_list:
         note = highes_note(n, value)
-        working_list.append(note)
+        working_list.append(note[:4]+","+note[4:])
     return working_list
 
 # mirrors notes at the first note
@@ -112,4 +112,4 @@ def mirror(input_list):
 # reverses list of notes (krebs)
 def krebs(input_list):
     return input_list[::-1]
-    
+    

+ 64 - 33
src/thema-gen

@@ -28,7 +28,8 @@ except (IndexError, ValueError):
     number = 4 
 
 #output_list = sequenz(stdin_list, 1)
-output_list2 = verkleinerung(stdin_list)
+motiv_list = verkleinerung(stdin_list)
+#motiv_list = stdin_list
 
 # create lists
 for i in range(number):
@@ -38,38 +39,68 @@ for i in range(number):
 index_list = random.sample(range(0,number), number)
 
 # list of functions to use
-function_list = [\
-    "verkleinerung(output_list2)",\
-    "krebs(output_list2)",\
-    "vergrösserung(output_list2)",\
-    "output_list2"\
+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)

+ 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