|
| 1 | +#!/bin/python2 |
| 2 | +""" |
| 3 | +Input example: |
| 4 | +python2 thisprogram.py 2 2 4 2 2 |
| 5 | +Each number declares how many of the corresponding exercises are produced |
| 6 | +
|
| 7 | +If there is no input, then there is a helpful prompt. |
| 8 | +""" |
| 9 | +# Set those for Aebersold's patterns |
| 10 | +Maj251Patterns=range(1,9) |
| 11 | +Min251Patterns=range(1,9) |
| 12 | + |
| 13 | +import sys |
| 14 | +import os |
| 15 | +from collections import OrderedDict |
| 16 | +from Generate_guitar_exercises_definitions import * |
| 17 | + |
| 18 | +# Dictionary as follows: |
| 19 | +# { Function name : [description,number of exercises], |
| 20 | +# ... |
| 21 | +# } |
| 22 | +# In other words, for x in the exercises |
| 23 | +# - x is the function |
| 24 | +# - Exercise[x][0] is the description |
| 25 | +# - Exercise[x][1] is the number of exercises |
| 26 | + |
| 27 | +Exercises=OrderedDict([ |
| 28 | + (BilliesBounce,["Billie's bounce",0]), |
| 29 | + (IIVIVI_improvlines,["2-5-1-6 Improv lines",0]), |
| 30 | + (ScalePracticeTechniques,["Scale practice technique",0]), |
| 31 | + (IIVILineExample,["2-5-1 Line examples",0]), |
| 32 | + (ApproachBluesInF,["Approach: Blues in F",0]), |
| 33 | +# (Scale,["Scales",0]), |
| 34 | +# (Triad,["Triads",0]), |
| 35 | +# (Moving_treble,["Moving trebles",0]), |
| 36 | +# (Diatonic_chords_within_a_CAGED_form,["Diatonic chords",0]), |
| 37 | + (II_V_I_Aebersold_patterns,["Aebersold II-V-I patterns",0]), |
| 38 | +# (Sight_reading_studies,["Sight-reading (Leavitt)",0]), |
| 39 | +# (Technique_patterns,["Technique: patterns",0]), |
| 40 | +# (Technique_right_hand_fingers,["Technique: right hand fingers",0]), |
| 41 | +# (Technique_right_hand_picking,["Technique: right hand picking",0]) |
| 42 | +]) |
| 43 | + |
| 44 | +# Input prompt |
| 45 | +Input_prompt="" |
| 46 | +for e in Exercises: |
| 47 | + Input_prompt+= '%d. %s\n' % (Exercises.keys().index(e)+1,Exercises[e][0]) |
| 48 | +Input_prompt+=" --- Press <C-c> to exit, or enter numbers of exercises separated by spaces.\n\n" |
| 49 | + |
| 50 | +# Set some variables according to whether we are doing latex or not |
| 51 | +TexMode=False |
| 52 | +ExtraArgs=1 # Number of input strings other than exercise numbers |
| 53 | +if len(sys.argv) > 1: |
| 54 | + if sys.argv[1] in ["-t","--tex-mode"]: |
| 55 | + TexMode=True |
| 56 | + ExtraArgs=2 |
| 57 | + AebDict=dict() |
| 58 | + MyTitle = raw_input("Enter title (press return for \"Guitar exercises\"): ") |
| 59 | + |
| 60 | +# Setting how many times we do each exercise |
| 61 | +if len(sys.argv)==len(Exercises)+ExtraArgs: # User gave arguments correctly |
| 62 | + TimesEachExercise=[int(i) for i in sys.argv[ExtraArgs:]] |
| 63 | +else: # No user input or input not given correctly |
| 64 | + InputNums = raw_input(Input_prompt) |
| 65 | + TimesEachExercise = [int(i) for i in InputNums.split() if i.isdigit()] |
| 66 | + while len(TimesEachExercise) != len(Exercises): |
| 67 | + print "\nSomething was wrong, try again: " |
| 68 | + InputNums = raw_input() |
| 69 | + TimesEachExercise = [int(i) for i in InputNums.split() if i.isdigit()] |
| 70 | +for e in Exercises: |
| 71 | + i=Exercises.keys().index(e) |
| 72 | + Exercises[e][1]=TimesEachExercise[i] |
| 73 | + |
| 74 | +List_of_exercises=[] |
| 75 | +for e in Exercises: |
| 76 | + # The following is a special case, since we need the scans |
| 77 | + if e.__name__=='II_V_I_Aebersold_patterns': |
| 78 | + for i in range(Exercises[e][1]): |
| 79 | + AebOutput=e(Maj251Patterns,Min251Patterns) |
| 80 | + AebExercise=AebOutput[0] |
| 81 | + AebPatternLabel=AebOutput[1] |
| 82 | + if TexMode: |
| 83 | + AebDict[AebPatternLabel]=AebDict.get(AebPatternLabel,0)+1 |
| 84 | + s = '\t\item %s \label{%s-%d}\\dotfill$\square$\n' % (AebExercise,AebPatternLabel,AebDict[AebPatternLabel]) |
| 85 | + else: |
| 86 | + s = AebOutput[0] |
| 87 | + List_of_exercises.append(s) |
| 88 | + # If you have any other special exercises, elif them here |
| 89 | + # Continuing with radom regular exercises |
| 90 | + else: |
| 91 | + for i in range(Exercises[e][1]): |
| 92 | + if TexMode: |
| 93 | + s = '\t\item %s\\dotfill$\square$\n' % (e()) |
| 94 | + else: |
| 95 | + s = e() |
| 96 | + List_of_exercises.append(s) |
| 97 | + |
| 98 | +random.shuffle(List_of_exercises) |
| 99 | + |
| 100 | +if TexMode: |
| 101 | + # Overview of exercises |
| 102 | + IncludedExercises="\\section*{Overview}\n\\begin{itemize}\n" |
| 103 | + for e in Exercises: |
| 104 | + if Exercises[e][1]>0: |
| 105 | + IncludedExercises+='\item %s: %d\n' % (Exercises[e][0],Exercises[e][1]) |
| 106 | + IncludedExercises+="\\end{itemize}" |
| 107 | + |
| 108 | + # Take care of the figures, if any |
| 109 | + IIVIFiguresParagraph= "" |
| 110 | + if Exercises[II_V_I_Aebersold_patterns][1]>0: # There exist Aebersold 251 exercises |
| 111 | + Items_for_251_figures=[] |
| 112 | + for pattern in AebDict: |
| 113 | + s="\\item Used in \\cref{" |
| 114 | + for i in range(AebDict[pattern]-1): |
| 115 | + s+='%s-%d,' % (pattern,i+1) |
| 116 | + s+= '%s-%d}' % (pattern,AebDict[pattern]) |
| 117 | + s+= "\n\\newline\\newline\n" |
| 118 | + s+= '\\includegraphics[width=0.8\\linewidth]{scans251/%s.png}' % (pattern) |
| 119 | + Items_for_251_figures.append(s) |
| 120 | + |
| 121 | + IIVIFiguresParagraph= "\n\\section*{II-V-I patterns}\n" |
| 122 | + IIVIFiguresParagraph+= "\\begin{itemize}\n" |
| 123 | + for i in Items_for_251_figures: |
| 124 | + IIVIFiguresParagraph+=i |
| 125 | + IIVIFiguresParagraph+= "\n\\end{itemize}\n" |
| 126 | + |
| 127 | + TexOutput="" |
| 128 | + TexOutput+="\documentclass[letterpaper]{article}\n" |
| 129 | + TexOutput+="\usepackage[top=1in, left=1.2in, right=1.2in, bottom=1.5in]{geometry}\n" |
| 130 | + TexOutput+="\usepackage{amssymb,graphicx,enumitem,cleveref}\n" |
| 131 | + TexOutput+="\crefname{enumi}{exercise}{exercises}\n" |
| 132 | + if MyTitle: |
| 133 | + TexOutput+='\\title{%s}\n\date{\\vspace{-3em}\\today}\n' % (MyTitle) |
| 134 | + else: |
| 135 | + TexOutput+="\\title{Guitar exercises}\n\date{\\vspace{-3em}\\today}\n" |
| 136 | + TexOutput+="\n\\author{}\n" |
| 137 | + TexOutput+="\\begin{document}\n" |
| 138 | + TexOutput+="\\maketitle\n" |
| 139 | + TexOutput+=IncludedExercises |
| 140 | + TexOutput+="\n\\section*{Exercises}" |
| 141 | + TexOutput+="\\begin{enumerate}\n" |
| 142 | + for e in List_of_exercises: |
| 143 | + x=e.replace("flat","$\\flat$") |
| 144 | + x=x.replace("#","$\\sharp$") |
| 145 | + TexOutput+=x |
| 146 | + TexOutput+="\\end{enumerate}\n" |
| 147 | + |
| 148 | + TexOutput+=IIVIFiguresParagraph |
| 149 | + TexOutput+="\n\\end{document}\n" |
| 150 | + |
| 151 | + f = open("Tex/GuitarExercises.tex", "w") |
| 152 | + f.write(TexOutput) |
| 153 | + f.close() |
| 154 | + |
| 155 | + for i in range(3): |
| 156 | + os.system("sh -c 'cd Tex && pdflatex -interaction=nonstopmode GuitarExercises.tex'") |
| 157 | + os.system("sh -c 'cd Tex && zathura GuitarExercises.pdf &'") |
| 158 | + |
| 159 | + |
| 160 | +else: |
| 161 | + for e in List_of_exercises: |
| 162 | + print e.replace("flat","b") |
| 163 | + |
| 164 | + |
0 commit comments