Browse Source

added small 'thema' generator + cleanup

Noah 4 years ago
parent
commit
08d3a7cb12
7 changed files with 75 additions and 32 deletions
  1. 4 7
      src/final-converter
  2. 8 0
      src/gizmo_funtions.py
  3. 9 3
      src/gizmo_transforming_functions.py
  4. 0 16
      src/krebs
  5. 9 6
      src/template
  6. 41 0
      src/thema-gen
  7. 4 0
      tests/motiv-1

+ 4 - 7
src/final-converter

@@ -5,14 +5,11 @@ from music21 import *
 from matplotlib import *
 environment.set('musicxmlPath', '/usr/bin/musescore')
 
-# read from standard input
-import sys
-stdin_list = []
-for line in sys.stdin:
-    stdin_list.append(line.rstrip())
-
 # import needed gizmo funtions
-from gizmo_funtions import return_part
+from gizmo_funtions import return_part, stdin
+
+# read from standard input
+stdin_list = stdin()
 
 # create stream
 stream1 = stream.Stream()

+ 8 - 0
src/gizmo_funtions.py

@@ -31,3 +31,11 @@ def replace_substring_of_list_part(input_list, split_index, pattern, replace_str
 def gizmo_stdout(input_list):
     for item in input_list:
         print(item)
+
+# function to read from standard input and return it a list of each line
+def stdin():
+    stdin_list = []
+    import sys
+    for line in sys.stdin:
+        stdin_list.append(line.rstrip())
+    return stdin_list

+ 9 - 3
src/gizmo_transforming_functions.py

@@ -1,4 +1,3 @@
-
 """ helper functions """
 
 # converts float duration to string in the form x.xx
@@ -27,6 +26,7 @@ def convert_multiple_key_signetures(note):
             note = note[:5] + note[7:]
     return note
 
+# TODO: add description
 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:])
@@ -44,7 +44,7 @@ def interval(note_1, note_2):
 def tempo(input_list, temp):
     working_list = []
     for note in input_list:
-        duration = float (note[0:4]) * temp
+        duration = float (note[0:4]) * float(temp)
         note = duration_to_string(duration) + note[4:]
         working_list.append(note)
     return working_list
@@ -86,6 +86,7 @@ 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:
@@ -94,6 +95,7 @@ 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]
@@ -101,4 +103,8 @@ def mirror(input_list):
         tmp_note = highes_note(mirror, - interval(mirror, note))
         print (tmp_note)
         working_list.append(tmp_note)
-    return working_list
+    return working_list
+
+# reverses list of notes (krebs)
+def krebs(input_list):
+    return input_list[::-1]

+ 0 - 16
src/krebs

@@ -1,16 +0,0 @@
-#!/usr/bin/env python3
-
-# read from standard input
-import sys
-stdin_list = []
-for line in sys.stdin:
-    stdin_list.append(line.rstrip())
-
-# import needed gizmo funtions
-from gizmo_funtions import *
-
-stdin_list.reverse()
-def gizmo_stdout(input_list):
-    for item in input_list:
-        print(item)
-gizmo_stdout(stdin_list)

+ 9 - 6
src/template

@@ -1,10 +1,13 @@
 #!/usr/bin/env python3
 
-# read from standard input
-import sys
-stdin_list = []
-for line in sys.stdin:
-    stdin_list.append(line.rstrip())
-
 # import needed gizmo funtions
 from gizmo_funtions import *
+from gizmo_transforming_functions import *
+
+# read from standard input
+stdin_list = stdin()
+
+
+
+# write to standard output
+gizmo_stdout(stdin_list)

+ 41 - 0
src/thema-gen

@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# import needed gizmo funtions
+from gizmo_funtions import *
+from gizmo_transforming_functions import *
+
+# read from standard input
+stdin_list = stdin()
+
+output_list2 = verkleinerung(stdin_list)
+#output_list = sequenz(stdin_list, 1)
+
+"""
+now this should be an algorithm that takes in a number and multiply
+the motive by it. Then it randomly runs all this this copied motives
+trough a function.
+"""
+
+import random
+number = 4
+
+# create lists
+for i in range(number):
+    exec("list%s = []" % (str(i)))
+
+# list of indexes from the motive list without repetition
+l = random.sample(range(0,number), number)
+
+# now run each item through a list, TODO: is HARDCODED right now
+exec("list%s = verkleinerung(output_list2)" % (str(l[0])))
+exec("list%s = krebs(output_list2)" % (str(l[1])))
+exec("list%s = vergrösserung(output_list2)" % (str(l[2])))
+exec("list%s = output_list2" % (str(l[3])))
+
+# append lists
+final_list = []
+for i in range(number):
+    exec("final_list.extend(list%s)" % (str(i)))
+
+# write to stdout
+gizmo_stdout(final_list)

+ 4 - 0
tests/motiv-1

@@ -0,0 +1,4 @@
+1.00,D4
+1.00,E4
+1.00,D4
+1.00,C4