Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/16 #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
38 changes: 31 additions & 7 deletions src/Arranging/ArrangeSections.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

class ArrangeSections :

def __init__ ( self, id, movement, outdir ) :
def __init__ ( self, id, movement, outdir , oneMidiPerLayer) :
self.id = id
self.movement = movement
self.outdir = outdir

self.oneMidiPerLayer = oneMidiPerLayer

def arrange ( self ) :

Expand Down Expand Up @@ -40,7 +40,7 @@ def arrange ( self ) :


self.midiEventsForSectionLayers = collections.OrderedDict()


sectionsObj = self.movement['SectionsObj'].mood
for secId in sectionsObj.sections :
Expand Down Expand Up @@ -193,12 +193,18 @@ def arrange ( self ) :
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer] )



self.midiEventsForLayers = collections.OrderedDict()
for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :
#print("Layer: ",layer,"len: ",len(self.midiEventsForLayers))
if (self.midiEventsForLayers.get(layer,"0") == "0" ) :
#print(layer)
self.midiEventsForLayers[layer] = []

for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :

CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer], self.outdir )

self.midiEventsForLayers[layer].extend(self.midiEventsForSectionLayers[secId][layer])

#if ( layer == 'bass1' or layer == 'bass2' or layer == 'mel5' or layer == 'piano1' or layer == 'rhythmChords' ) :
# CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer] )

Expand All @@ -207,5 +213,23 @@ def arrange ( self ) :
for ev in self.midiEventsForSectionLayers[secId][layer] :
print ( ev )
print()
if self.oneMidiPerLayer:
for layer in self.midiEventsForLayers :
CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, 1, layer, self.midiEventsForLayers[layer], self.outdir )
else:
for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :

CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer], self.outdir )

#if ( layer == 'bass1' or layer == 'bass2' or layer == 'mel5' or layer == 'piano1' or layer == 'rhythmChords' ) :
# CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer] )

if ( 0 and layer.startswith('mel5High') ) :
print ( "Section: ", secId, "Layer: ", layer )
for ev in self.midiEventsForSectionLayers[secId][layer] :
print ( ev )
print()



7 changes: 4 additions & 3 deletions src/Arranging/CreateMidiEventsForBass.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def CreateMidiFileForBass ( mvNum, secId, layer, midiEvents, outdir ) :

foutName = outdir + "WB_Mvmt" + str(mvNum) + "_Sec" + str(secId) + "_" + layer
fout = open ( foutName + ".py", mode='w' )
print("ouput " + foutName)


WriteInitialMidiFileSequence ( fout )
Expand Down Expand Up @@ -449,11 +450,11 @@ def WriteFinalMidiFileSequence ( fout, foutName ) :
fout.write ( "\nmidi.write_midifile(\"%s\", pattern)" %(foutMidiName) ) ;
fout.close() ;

#print ( "\nOutput midi file: %s\n" %(foutMidiName) ) ;
print ( "\nOutput midi file: %s\n" %(foutMidiName) ) ;
call = "python " + foutName + ".py" ;
os.system ( call ) ;
call = "rm " + foutName + ".py" ;
os.system ( call ) ;
#call = "rm " + foutName + ".py" ;
#os.system ( call ) ;


def WriteInitialMidiFileSequence ( fout ) :
Expand Down
16 changes: 10 additions & 6 deletions src/Skeleton/Skeleton.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
class Template :


def __init__ ( self, iniFname, midiFilePath, outDir ) :
def __init__ ( self, iniFname, midiFilePath, outDir,oneMidiPerLayer) :

self.tempo = None
self.midiFilePath = midiFilePath
self.outDir = outDir
self.ReadIniFile ( iniFname )
self.oneMidiPerLayer = oneMidiPerLayer

#Initialize mood and sections
for mvNum in self.movements :
Expand Down Expand Up @@ -374,7 +375,7 @@ def populateSections ( self ) :
self.movements[mvNum]['layers'][uniqCPId] = section.run ()


arrangeSections = ArrangeSections ( mvNum, self.movements[mvNum], self.outDir )
arrangeSections = ArrangeSections ( mvNum, self.movements[mvNum], self.outDir ,self.oneMidiPerLayer)
arrangeSections.arrange()


Expand Down Expand Up @@ -454,7 +455,7 @@ def usage() :

def run () :


print("in skeleton")
parser = argparse.ArgumentParser()

parser.add_argument('-i', action='store',
Expand All @@ -472,11 +473,13 @@ def run () :
default='./output/',
help='Output File Path')

parser.add_argument('-l', action='store_true',
dest='oneMidiPerLayer',
help="One midi per layer" )

parser.add_argument('-u', action='store_true',
dest='usage',
help="usage" )

help="usage" )

results = parser.parse_args()

Expand All @@ -499,14 +502,15 @@ def run () :
print('iniFile = {!r}'.format(results.iniFile ))
print('midiFile = {!r}'.format(results.midiFilePath ))
print('outputDir = {!r}'.format(results.outputFilePath ))
print('layerpermidi = {!r}'.format(results.oneMidiPerLayer ))


rmCmd = "rm -rf {}/WB*.mid {}/WB*.py".format( results.outputFilePath, results.outputFilePath )
os.system ( rmCmd )

#random.seed ( 10 )

skeleton = Template( results.iniFile, results.midiFilePath, results.outputFilePath )
skeleton = Template( results.iniFile, results.midiFilePath, results.outputFilePath,results.oneMidiPerLayer)