mirror of
https://github.com/kastdeur/bwwtolily.git
synced 2024-11-25 05:03:31 +01:00
Hella refactored some shit
This commit is contained in:
parent
01ea98f703
commit
dce0309a22
1 changed files with 372 additions and 369 deletions
27
bwwtolily.py
27
bwwtolily.py
|
@ -7,11 +7,17 @@ GPL v3
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import sys,os,re,subprocess
|
import sys,os,re,subprocess
|
||||||
|
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
|
|
||||||
|
#make a print function to handle various version of python
|
||||||
|
def do_print(string):
|
||||||
|
try:
|
||||||
|
eval("print "+string)
|
||||||
|
except:
|
||||||
|
print(string)
|
||||||
|
|
||||||
#define the class that will convert a bww file to a lilypond file
|
#define the class that will convert a bww file to a lilypond file
|
||||||
class bwwtolily :
|
class bwwtolily :
|
||||||
|
|
||||||
def __init__(self,addmidi=False):
|
def __init__(self,addmidi=False):
|
||||||
self.tune_elements = []
|
self.tune_elements = []
|
||||||
self.most_recent_note = 0
|
self.most_recent_note = 0
|
||||||
|
@ -72,7 +78,6 @@ class bwwtolily :
|
||||||
else:
|
else:
|
||||||
self.lily_midi=''
|
self.lily_midi=''
|
||||||
|
|
||||||
|
|
||||||
def set_file(self,file_path):
|
def set_file(self,file_path):
|
||||||
#determine the absolute path to the file
|
#determine the absolute path to the file
|
||||||
abs_file = os.path.join(os.getcwd(),file_path)
|
abs_file = os.path.join(os.getcwd(),file_path)
|
||||||
|
@ -88,8 +93,9 @@ class bwwtolily :
|
||||||
|
|
||||||
def quit(self,string=""):
|
def quit(self,string=""):
|
||||||
if string!="":
|
if string!="":
|
||||||
print string
|
do_print( string)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
'''reate a string that represents the converted
|
'''reate a string that represents the converted
|
||||||
contents of the file'''
|
contents of the file'''
|
||||||
|
@ -150,8 +156,6 @@ class bwwtolily :
|
||||||
elements = tune_notes.split()
|
elements = tune_notes.split()
|
||||||
for element in elements:
|
for element in elements:
|
||||||
self.transpose(element)
|
self.transpose(element)
|
||||||
#print self.tune_notes
|
|
||||||
|
|
||||||
|
|
||||||
def lilynote(self,bwwname):
|
def lilynote(self,bwwname):
|
||||||
#convert a bww notename to a lilypond notename
|
#convert a bww notename to a lilypond notename
|
||||||
|
@ -308,10 +312,9 @@ class bwwtolily :
|
||||||
self.tune_elements.append(dict_result)
|
self.tune_elements.append(dict_result)
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
print "unparsed: "+element
|
do_print( "unparsed: "+element)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
#handle writing the output
|
#handle writing the output
|
||||||
def create_output_file(self):
|
def create_output_file(self):
|
||||||
#determine the output file
|
#determine the output file
|
||||||
|
@ -378,18 +381,18 @@ if __name__ == "__main__" :
|
||||||
parser.add_option("-i", "--in", dest="input",
|
parser.add_option("-i", "--in", dest="input",
|
||||||
help="the FILE to convert", metavar="FILE")
|
help="the FILE to convert", metavar="FILE")
|
||||||
parser.add_option("-l", "--lilypond",
|
parser.add_option("-l", "--lilypond",
|
||||||
action="store_true", dest="runlilypond", default=False,
|
action="store_true", dest="runlilypond",default=False,
|
||||||
help="run lilypond after converting the file")
|
help="run lilypond after converting the file")
|
||||||
parser.add_option("-m", "--midi",
|
parser.add_option("-m", "--midi",
|
||||||
action="store_true", dest="addmidi", default=False,
|
action="store_true", dest="addmidi",default=False,
|
||||||
help="add midi output to the lilypond file")
|
help="add midi output to the lilypond file")
|
||||||
parser.add_option("-v","--version",dest='version', default=False,
|
parser.add_option("-v","--version",dest='version',default=False,
|
||||||
action="store_true",help="print version information and quit")
|
action="store_true",help="print version information and quit")
|
||||||
|
|
||||||
#parse the args
|
#parse the args
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
if options.version:
|
if options.version:
|
||||||
print "bwwtolily: ",version
|
do_print( "bwwtolily: ",version)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if options.input!=None:
|
if options.input!=None:
|
||||||
|
|
Loading…
Reference in a new issue