1
0
Fork 0
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:
Jezra 2013-08-13 22:49:09 -07:00
parent 01ea98f703
commit dce0309a22

View file

@ -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
@ -389,7 +392,7 @@ if __name__ == "__main__" :
#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: