Browse Source

apply patch

Noah 4 years ago
parent
commit
2d8cf02f36
1 changed files with 72 additions and 38 deletions
  1. 72 38
      src/thema-gen

+ 72 - 38
src/thema-gen

@@ -17,15 +17,44 @@ line and multiplies the motive by it. Then it randomly runs all this these
 copied motives trough a function to create a 'thema'.
 copied motives trough a function to create a 'thema'.
 """
 """
 
 
-# get command line argument
-try:
-    number = int(sys.argv[1])
-    # raise error if number too small
-    if number < 1:
-        raise ValueError("Number was too small (below 1)")
-except (IndexError, ValueError):
-    # set fallback value if no or wrong arguments given
-    number = 4 
+args = sys.argv[1:]
+
+# set default values
+number = 4
+condition_list = [False]
+
+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
+
+active_args = []
+# process commandline arguments
+if len(args)>0:
+    if "-fl" in args:
+        condition_list.append(False)
+        active_args.append('first_equals_last_pitch')
+    if ("-n" in args) or ("--number" in args):
+        try:
+            # get number
+            if "-n" in args:
+                entered_number = int(args[args.index("-n")+1])
+            else:
+                entered_number = int(args[args.index("--number")+1])
+            # exit if wrong form entered
+            if entered_number > 0:
+                number = entered_number
+            else:
+                raise ValueError("Error: Please give an integer bigger than 0.")
+        except (ValueError, IndexError):
+            print("Error: Please give an integer bigger than 0.")
+            exit()
+    if ("-h" in args) or ( "--help" in args):
+        # exit and display help message
+        print("Usage: thema-gen [options] [< input file]\n\n\
+Options:\n\
+     -fl\t\tthe first and last pitch have to be same\n\
+     -h, --help\t\tprint this help message")
+        exit()
 
 
 #output_list = sequenz(stdin_list, 1)
 #output_list = sequenz(stdin_list, 1)
 motiv_list = verkleinerung(stdin_list)
 motiv_list = verkleinerung(stdin_list)
@@ -47,9 +76,6 @@ function_list = [
     "sequenz(motiv_list, 5)"
     "sequenz(motiv_list, 5)"
     ]
     ]
 
 
-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
 """copy over function_list and start main loop that stops when every post
 processing requirement is satified"""
 processing requirement is satified"""
@@ -57,9 +83,12 @@ processing requirement is satified"""
 # default values are all all generating 'False' to simulate a 'do while' loop
 # default values are all all generating 'False' to simulate a 'do while' loop
 final_list = ['1.00,D4','1.00,C3']
 final_list = ['1.00,D4','1.00,C3']
 
 
-while not(first_equals_last_pitch(final_list)):
+while not all(condition_list):
+    # set first value to true (this is to simale a do while loop)
+    condition_list[0] = True
+
     working_list = function_list
     working_list = function_list
-    
+
     # adjust working_list to the entered number
     # adjust working_list to the entered number
     if number < len(working_list):
     if number < len(working_list):
         # if smaller, simply randomize + cut/strip it
         # if smaller, simply randomize + cut/strip it
@@ -68,39 +97,44 @@ while not(first_equals_last_pitch(final_list)):
     elif number > len(working_list):
     elif number > len(working_list):
         for i in range(number-len(working_list)):
         for i in range(number-len(working_list)):
             working_list.append(random.choice(working_list))
             working_list.append(random.choice(working_list))
-    
+
     # randomize the list
     # randomize the list
     random.shuffle(working_list)
     random.shuffle(working_list)
-    
+
     # OPTIONAL: add some post procession here
     # OPTIONAL: add some post procession here
-    
+
     # now run each item through a list
     # now run each item through a list
     for i in range(number):
     for i in range(number):
         exec("list%s = %s" % (str(i),str(working_list[i])))
         exec("list%s = %s" % (str(i),str(working_list[i])))
-    
+
     # append lists
     # append lists
     final_list = []
     final_list = []
     for i in range(number):
     for i in range(number):
         exec("final_list.extend(list%s)" % (str(i)))
         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'))
-    """
-    
+
+    if "-fl" in args:
+        if first_equals_last_pitch(final_list) and 'first_equals_last_pitch' in active_args:
+            condition_list[condition_list.index(False)] = True
+            active_args.remove('first_equals_last_pitch')
+
+"""
+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
 # finally, write to standard output
 gizmo_stdout(final_list)
 gizmo_stdout(final_list)