コード例 #1
0
    def refreshGrooves(self):
        # get the latest paths from GUI
        mmaPath = self.mmaPathEntry.get().strip(' ')
        pythonPath = self.pythonPathEntry.get().strip(' ')
        customGroovePath = self.customGroovePathEntry.get().strip(' ')

        # validate paths
        if not os.path.exists(pythonPath):
            tkMessageBox.showerror(
                "Error", "Python path: '" + pythonPath +
                "' does not exist. Please check your settings.")
            return
        if not os.path.exists(mmaPath):
            tkMessageBox.showerror(
                "Error", "MMA path: '" + mmaPath +
                "' does not exist. Please check your settings.")
            return
        if os.path.isdir(pythonPath):
            tkMessageBox.showerror(
                "Error", "Python path: '" + pythonPath +
                "' is a directory and not a filename. Please check your settings."
            )
            return
        if os.path.isdir(mmaPath):
            tkMessageBox.showerror(
                "Error", "MMA path: '" + mmaPath +
                "' is a directory and not a filename. Please check your settings."
            )
            return

        if customGroovePath != "" and not os.path.exists(customGroovePath):
            tkMessageBox.showwarning(
                "Warning", "Custom groove path: '" + customGroovePath +
                "' does not exist. These will not be added.")

        mmaDir = os.path.dirname(mmaPath)
        #mmaDir = re.compile(r'.*[\\/]').match(mmaPath).group()
        if common.libDir == "" or not os.path.exists(common.libDir):
            common.printOutput(
                "Couldn't find the MMA grooves directory. Please check your settings."
            )
            return

        # clear out the grooves
        global groovedict
        global groovelib_lookup

        groovedict = {}
        groovelib_lookup = {}

        self.addGrooves(common.libDir, pythonPath, mmaPath)
        if customGroovePath != "":
            self.addGrooves(customGroovePath, pythonPath, mmaPath)
        #print groovedict
        #write groovedict to grooves file
        f = open(common.groovesFile, "w")
        p = cPickle.Pickler(f)
        p.dump(groovedict)
        p.dump(groovelib_lookup)
        f.close()
コード例 #2
0
ファイル: fonts.py プロジェクト: sangibeaud/LeMMA
    def apply(self):
        # update the fonts
        for i in range(7):
            FONTS[FONTKEYS[i]] = self.tempFonts[i]

        FONTS["Groove None"] = (FONTS["Groove"][0], FONTS["Groove"][1],
                                "normal")
        FONTS["Code None"] = (FONTS["Code"][0], FONTS["Code"][1], "normal")

        # save to settings.dat
        config = ConfigParser.ConfigParser()
        config.read(common.settingsFile)
        if not config.has_section("gui"):
            config.add_section("gui")
        for key in FONTS.keys():
            config.set(
                "gui", "font." + key,
                FONTS[key][0] + "," + FONTS[key][1] + "," + FONTS[key][2])
        f = open(common.settingsFile, 'w')
        config.write(f)
        f.close()

        common.printOutput("Font settings saved to " + common.settingsFile)
        # Show info for now. Next time can reconfigure all fonts live.
        tkMessageBox.showinfo(
            "Please restart LeMMA",
            "The new font settings will only fully take effect when you restart LeMMA"
        )
        return
コード例 #3
0
	def saveMMA(self, event=None):
		# KeRi: if we have aready a filename save it as that
		if self.currentFile == "" or self.currentFile == ():	#	KeRi
			self.askAndSaveMMA()
		else:													#	KeRi
			self.doSaveMMA(self.currentFile)					#	KeRi
			common.printOutput("Saved " + self.currentFile)		#	KeRi
			return												#	KeRi
コード例 #4
0
	def askAndSaveMMA(self):
		temp = tkFileDialog.asksaveasfilename(filetypes = MMA_filetypes)
		if temp != "" and temp != ():
			self.currentFile = temp
			self.updateTitle()
			self.doSaveMMA(self.currentFile)
			common.printOutput("Saved as " + self.currentFile)
			return
		common.printOutput("Save cancelled")
コード例 #5
0
ファイル: settings.py プロジェクト: KeesR/LeMMA
def readGrooves():
	global groovedict
	global groovelib_lookup
	try:
		f = open(common.groovesFile, "r")
		p = cPickle.Unpickler(f)
		groovedict = p.load()
		groovelib_lookup = p.load()
		f.close()
	except IOError:
		common.printOutput("Error opening " + common.groovesFile + ". Please check your settings, then refresh the grooves.", True)
コード例 #6
0
def readGrooves():
    global groovedict
    global groovelib_lookup
    try:
        f = open(common.groovesFile, "r")
        p = cPickle.Unpickler(f)
        groovedict = p.load()
        groovelib_lookup = p.load()
        f.close()
    except IOError:
        common.printOutput(
            "Error opening " + common.groovesFile +
            ". Please check your settings, then refresh the grooves.", True)
コード例 #7
0
ファイル: settings.py プロジェクト: KeesR/LeMMA
	def refreshGrooves(self):
		# get the latest paths from GUI
		mmaPath = self.mmaPathEntry.get().strip(' ')
		pythonPath = self.pythonPathEntry.get().strip(' ')
		customGroovePath = self.customGroovePathEntry.get().strip(' ')

		# validate paths
		if not os.path.exists(pythonPath):
			tkMessageBox.showerror("Error", "Python path: '" + pythonPath + "' does not exist. Please check your settings.")
			return
		if not os.path.exists(mmaPath):
			tkMessageBox.showerror("Error", "MMA path: '" + mmaPath + "' does not exist. Please check your settings.")
			return
		if os.path.isdir(pythonPath):
			tkMessageBox.showerror("Error", "Python path: '" + pythonPath + "' is a directory and not a filename. Please check your settings.")
			return
		if os.path.isdir(mmaPath):
			tkMessageBox.showerror("Error", "MMA path: '" + mmaPath + "' is a directory and not a filename. Please check your settings.")
			return

		if customGroovePath != "" and not os.path.exists(customGroovePath):
			tkMessageBox.showwarning("Warning", "Custom groove path: '" + customGroovePath + "' does not exist. These will not be added.")

		mmaDir = os.path.dirname(mmaPath)
		#mmaDir = re.compile(r'.*[\\/]').match(mmaPath).group()
		if common.libDir == "" or not os.path.exists(common.libDir):
			common.printOutput("Couldn't find the MMA grooves directory. Please check your settings.")
			return

		# clear out the grooves
		global groovedict
		global groovelib_lookup

		groovedict = {}
		groovelib_lookup = {}

		self.addGrooves(common.libDir, pythonPath, mmaPath)
		if customGroovePath != "":
			self.addGrooves(customGroovePath, pythonPath, mmaPath)
		#print groovedict
		#write groovedict to grooves file
		f = open(common.groovesFile, "w")
		p = cPickle.Pickler(f)
		p.dump(groovedict)
		p.dump(groovelib_lookup)
		f.close()
コード例 #8
0
ファイル: fonts.py プロジェクト: KeesR/LeMMA
	def apply(self):
		# update the fonts
		for i in range(7):
			FONTS[FONTKEYS[i]] = self.tempFonts[i]

		FONTS["Groove None"] = (FONTS["Groove"][0], FONTS["Groove"][1], "normal")
		FONTS["Code None"] = (FONTS["Code"][0], FONTS["Code"][1], "normal")

		# save to settings.dat
		config = ConfigParser.ConfigParser()
		config.read(common.settingsFile)
		if not config.has_section("gui"):
			config.add_section("gui")
		for key in FONTS.keys():
			config.set("gui", "font." + key, FONTS[key][0] + "," + FONTS[key][1] + "," + FONTS[key][2])
		f = open(common.settingsFile, 'w')
		config.write(f)
		f.close()

		common.printOutput("Font settings saved to " + common.settingsFile)
		# Show info for now. Next time can reconfigure all fonts live.
		tkMessageBox.showinfo("Please restart LeMMA", "The new font settings will only fully take effect when you restart LeMMA")
		return
コード例 #9
0
	def loadMMA(self, event=None, filename=""):
		currentLibPath = common.libDir
		currentAutoLibPath = "stdlib"

		global MMA_filetypes
		if filename == "":
			temp = tkFileDialog.askopenfilename(filetypes = MMA_filetypes)
		else:
			temp = filename

		if temp == "" or temp == ():
			return
		else:
			self.currentFile = temp
			self.updateTitle()
		
		self.clearCanvas()
		f = open(self.currentFile, "r")
		i = 0 # measure number
		
		measure = 0
		repeatending_count = 1
		clearcontents = 1
		reached_first_measure = False
		
		# read each line
		for line in f:
			line = line.rstrip()

			matched = False
			
			if reached_first_measure == False and re.compile(r'^\s*KeySig\s*', re.IGNORECASE).match(line):
				line = re.compile(r'^\s*KeySig\s*', re.IGNORECASE).sub("", line)
				self.keyEntry.delete(0, END)
				self.keyEntry.insert(0, line)
				continue
			
			if reached_first_measure == False and re.compile(r'^\s*TimeSig\s*', re.IGNORECASE).match(line):
				line = re.compile(r'^\s*TimeSig\s*', re.IGNORECASE).sub("", line)
				line = line.replace(" " , "/")
				self.timeSigEntry.delete(0, END)
				self.timeSigEntry.insert(0, line)
				continue
			
			if reached_first_measure == False and re.compile(r'^\s*Tempo\s*', re.IGNORECASE).match(line):
				line = re.compile(r'^\s*Tempo\s*', re.IGNORECASE).sub("", line)
				self.tempoEntry.delete(0, END)
				self.tempoEntry.insert(0, line)
				continue
			
			if reached_first_measure == False and re.compile(r'^\s*SwingMode\s*', re.IGNORECASE).match(line):
				line = re.compile(r'^\s*SwingMode\s*', re.IGNORECASE).sub("", line)
				if line == "On":
					self.SwingMode.set(1)
					#self.swingCheckBtn.select()
				else:
					self.SwingMode.set(0)
					#self.swingCheckBtn.deselect()
				continue

			if re.compile(r'^\s*SetLibPath\s*', re.IGNORECASE).match(line):
				if not reached_first_measure:
					reached_first_measure = True
				line = re.compile(r'^\s*SetLibPath\s*', re.IGNORECASE).sub("", line)
				currentLibPath = line
				if currentLibPath == common.libDir:
					self.grooves_libpath[measure] = "<default>"
				else:
					self.grooves_libpath[measure] = currentLibPath
				continue
	
			if re.compile(r'^\s*SetAutoLibPath\s*', re.IGNORECASE).match(line):
				if not reached_first_measure:
					reached_first_measure = True
				line = re.compile(r'^\s*SetAutoLibPath\s*', re.IGNORECASE).sub("", line)
				currentAutoLibPath = line
				self.grooves_autolibpath[measure] = currentAutoLibPath
				continue
			
			if re.compile(r'^\s*Groove\s*', re.IGNORECASE).match(line):
				if not reached_first_measure:
					reached_first_measure = True
				line = re.compile(r'^\s*Groove\s*', re.IGNORECASE).sub("", line)
				if (' ' in line) or ('$' in line):	# more than just a groove name, make this a code line instead
					logging.debug("[loadMMA] Found a programmatic groove line, moving to code section: '"+line+"'")
					self.codes[measure] += "Groove " + line + "\n"
					self.codebtns[measure].configure(foreground=CODE_COLOR_BG, background=CODE_COLOR_FG, font=autoScaleFont(FONTS["Code"]))
					continue

				self.grooves[measure].configure(text=line, foreground=GROOVE_COLOR_FG, font=autoScaleFont(FONTS["Groove"]))
				if self.grooves_libpath[measure] == "":
					if currentLibPath == common.libDir:
						self.grooves_libpath[measure] = "<default>"
					else:
						self.grooves_libpath[measure] = currentLibPath
				if self.grooves_autolibpath[measure] == "":
					self.grooves_autolibpath[measure] = currentAutoLibPath
				# lookup the library file that contains this groove
				key = line + "|" + self.grooves_libpath[measure]
				if key.lower() in settings.groovelib_lookup.keys():
					self.grooves_lib[measure] = settings.groovelib_lookup[key.lower()]
				else:
					tkMessageBox.showwarning("Warning", "Groove '"+line+"' is not found in LeMMA groove database. You may want to refresh it under 'Settings'.")
				continue

			if clearcontents == 1:
				contents = ""
			
			# is this a repeat, repeatending?
			if line == "Repeat":
				#contents = "|: "
				contents = ""
				matched = True
				# Is this a repeatend + repeat?
				if self.barlines[measure]["text"] == ":| ":
					self.barlines[measure].configure(text=":|:")
				else:
					self.barlines[measure].configure(text=" |:")
				repeatending_count = 1
				clearcontents = 0

			if line == "RepeatEnding":
				contents = "[" + str(repeatending_count) + " "
				matched = True
				repeatending_count += 1
				clearcontents = 0
				
			# form the measure contents field
			if re.compile(r'\d+').match(line):
				line = re.compile(r'^\d+\s*').sub("", line)
				contents = contents + line
				matched = True
				clearcontents = 1
			
			# is this a repeat end? then need to retrieve and add to previous bar
			if line == "RepeatEnd":
				self.barlines[measure].configure(text=":| ")
				#measure = measure - 1
				#contents = self.measures[measure].contents.get()
				#self.measures[measure].contents.delete(0, END)
				#contents += " :|"
				clearcontents = 1
				matched = True
			
			# insert into measure
			if clearcontents == 1 and contents != "":
				self.measures[measure].contents.insert(0, contents)
				measure = measure + 1
				if measure > len(self.measures):
					break
				continue
			
			if line == "cut -1":
				break

			# Must be some MMA code
			if reached_first_measure and not matched:
				#print measure, line
				self.codes[measure] += line + "\n"
				self.codebtns[measure].configure(foreground=CODE_COLOR_BG, background=CODE_COLOR_FG, font=autoScaleFont(FONTS["Code"]))

		# Check and adjust the measure widths
		for measure in self.measures:
			measure.adjustWidth(adjustScroll=False)

		# Update the canvas scroll area
		self.measures[0].contents.focus()
		self.adjustCanvasScroll(self.measures[0])
		self.measures[0].validateMeasures()
		f.close()

		# reset any pause settings
		common.playerIsPaused = False
		common.printOutput("Loaded " + self.currentFile)
コード例 #10
0
	def newFile(self, event=None):
		if tkMessageBox.askokcancel("Warning", "All contents will be lost! Continue?"):
			self.currentFile = ""
			self.clearCanvas()
			self.updateTitle()
			common.printOutput("New file selected")
コード例 #11
0
ファイル: settings.py プロジェクト: KeesR/LeMMA
	def addGrooves(self, currlibDir, pythonPath, mmaPath):
		# get all groove files starting from currlibDir, note this takes a while to complete
		mmaDir = os.path.dirname(mmaPath)
		#mmaDir = re.compile(r'.*[\\/]').match(mmaPath).group()

		currentdir = os.getcwd()
		os.chdir(mmaDir)
		
		global groovedict

		groovecount = 0
		p1 = re.compile(r'\\filehead\{(.*?)\}\{(.*?)\}')
		p2 = re.compile(r'\\instable\{(.*?)\}\{(.*?)\}')
		
		# check MMA version
		mmaversion = 1.2
		versionstr = ""
		try:
			#	quote pythonPath to handle correctly space characters in it
			cmd = "\"" + pythonPath + "\" " + mmaPath + " -v"
			#pipe = os.popen(cmd, 'r')
			pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).stdout
			output = pipe.read()
			versionstr = re.compile(r'^\d+\.\d+', re.S|re.M).search(output).group(0)
			mmaversion = float(versionstr)
			status = pipe.close()
			common.printOutput("Detected MMA version " + versionstr)
			logging.debug("[addGrooves] Detected MMA version " + versionstr)
		except:
			common.printOutput("Couldn't get MMA version! '" + cmd + "' Assuming version > 1.0")
			logging.debug("[addGrooves] Unable to get MMA version. Using '" + cmd + "'")

		# set the path part of the key to groovedict and groovelib_lookup
		# we'll define it as "<default>" if currlibDir matches the current global libDir
		# with this definition, currently loaded files will be less affected if libDir changes (when refreshing grooves)
		if currlibDir == common.libDir:
			keylibDir = "<default>"
		else:
			keylibDir = currlibDir

		# Count how many files we will be processing
		tree = os.walk(currlibDir)
		totalfiles = 0
		for directory in tree:
			for file in directory[2]:
				if file.endswith("mma"):
					totalfiles += 1
		#print totalfiles
		progressWin = ProgressBarWindow(self)

		filecount = 0.0
		tree = os.walk(currlibDir)
		# start walking the directory
		for directory in tree:
			for file in sorted(directory[2]):
				if file.endswith("mma"):
					filecount += 1.0
					filename = os.path.normcase(directory[0] + "/" + file)
					# run MMA command
					try:
						# NOTE: In Windows, I need a shell window for this to work!
						#	quote pythonPath to handle correctly space characters in it
						if mmaversion > 1.0:
							cmd = "\"" + pythonPath + "\" " + mmaPath + " -Dxl -w " + filename
						else:
							cmd = "\"" + pythonPath + "\" " + mmaPath + " -Dx -w " + filename
						pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE).stdout
						logging.debug("[addGrooves] Calling subprocess '" + cmd + "'")
						#pipe = os.popen(cmd, 'r')
						grooveinfo = pipe.read()
						status = pipe.close()
						
						#print grooveinfo
					except:
						#common.printOutput("Oops, an error was encountered")
						logging.debug("[addGrooves] Error encountered trying to run '" + cmd + "'")
						
					m1 = p1.search(grooveinfo)

					if m1 == None:
						continue

					groovelibname = m1.group(1)
					groovelibrary = groovelibname + "|" + keylibDir

					# Rename the groovelibrary if clashes found (the mambo grooves). This is no conflict as long as the grooves themselves don't clash. If so, it will depend on MMA's resolution rules.
					# Unfortunately, it happens that the yamaha grooves conflict with each other...
					if groovelibrary in groovedict.keys():
						new_groovelibname = groovelibname
						libname_suffix = 1
						while (new_groovelibname + "|" + keylibDir) in groovedict.keys():
							new_groovelibname = groovelibname + "_" + str(libname_suffix)
						groovelibrary = new_groovelibname + "|" + keylibDir
						logging.debug("[addGrooves] " + groovelibname + " renamed to " + new_groovelibname)

					groovedict[groovelibrary] = [m1.group(2), filename]
					
					#print groovedict
					m2 = p2.findall(grooveinfo)
					grooves = []
					
					headerstr = "[MMA " + versionstr + "] Reading grooves from " + currlibDir + "...\n"
					outputstr = headerstr + "Library: " + groovelibname + "\n"
					
					for groove in m2:	
						groovename = groove[0]
						groovedesc = groove[1]
						
						groovename = groovename.replace("\\\\","\\")
						groovename = groovename.replace("\\&","&")
						groovename = groovename.replace("``","`")
						groovename = groovename.replace("\"\"","\"")
						groovename = groovename.replace("\'\'","\'")
						
						groovedesc = groovedesc.replace("\\\\","\\")
						groovedesc = groovedesc.replace("\\&","&")
						groovedesc = groovedesc.replace("``","`")
						groovedesc = groovedesc.replace("\"\"","\"")
						groovedesc = groovedesc.replace("\'\'","\'")
						
						#print groovename
						
						outputstr += groovename + " "
						groovecount += 1
						
						grooves += [[groovename, groovedesc]]
						groovelib_lookup[groovename.lower()+"|"+keylibDir] = groovelibname
					groovedict[groovelibrary] += [grooves]
					
					common.printOutput(outputstr)
					#print filecount / totalfiles
					progressWin.set(filecount / totalfiles)

		progressWin.destroy()
		os.chdir(currentdir)
		common.printOutput(headerstr + "Done: Read " + str(groovecount) + " grooves")
コード例 #12
0
ファイル: settings.py プロジェクト: KeesR/LeMMA
	def apply(self):
		# read variables and strip trailing spaces	
		pythonPath = self.pythonPathEntry.get().strip(' ')
		mmaPath = self.mmaPathEntry.get().strip(' ')
		libDir = self.mmaLibDirEntry.get().strip(' ')
		midiEngine = self.midiEngineButton["text"]
		midiPlayer = self.midiPlayerEntry.get().strip(' ')
		customGroovePath = self.customGroovePathEntry.get().strip(' ')
		measuresPerRow = self.measuresPerRowEntry.get().strip(' ')

		logging.debug("[Settings] Settings are: (" + pythonPath + "," + mmaPath + "," + midiPlayer + "," + customGroovePath + ")")
		# validate the existence of these paths
		if not os.path.exists(pythonPath):
			tkMessageBox.showerror("Error", "Python path: '" + pythonPath + "' does not exist.")
			return
		if not os.path.exists(mmaPath):
			tkMessageBox.showerror("Error", "MMA path: '" + mmaPath + "' does not exist.")
		if os.path.isdir(pythonPath):
			tkMessageBox.showerror("Error", "Python path: '" + pythonPath + "' is a directory and not a filename.")
			return
		if os.path.isdir(mmaPath):
			tkMessageBox.showerror("Error", "MMA path: '" + mmaPath + "' is a directory and not a filename.")
			return

		if not os.path.exists(libDir):
			tkMessageBox.showerror("Error", "MMA grooves path: '" + libDir + "' does not exist.")
			return

		realmidipath = re.compile(r'\s-[^\s]*').sub("", midiPlayer)	# strip any command-line options
		if not os.path.exists(realmidipath):
			tkMessageBox.showwarning("Warning", "Midi player path: '" + midiPlayer + "' does not exist. You won't be able to play MMA files.")
		if os.path.isdir(realmidipath):
			tkMessageBox.showwarning("Warning", "Midi player path: '" + midiPlayer + "' is a directory and not a filename. You won't be able to play the MMA file.")

		if customGroovePath != "" and not os.path.exists(customGroovePath):
			tkMessageBox.showwarning("Warning", "Custom groove path: '" + customGroovePath + "' does not exist.")

		# save the settings into settings file

		config = ConfigParser.ConfigParser()
		config.read(common.settingsFile)
		if not config.has_section("paths"):
			config.add_section("paths")
		config.set("paths", "python", pythonPath)
		config.set("paths", "mma", mmaPath)
		config.set("paths", "midiplayer", midiPlayer)
		config.set("paths", "grooves", libDir)
		config.set("paths", "customgrooves", customGroovePath)

		if not config.has_section("misc"):
			config.add_section("misc")
		config.set("misc", "measures_per_row", measuresPerRow)
		config.set("misc", "midiengine", midiEngine)

		f = open(common.settingsFile, "w")
		config.write(f)
		f.close()

		common.printOutput("Settings saved in " + common.settingsFile)

		# read the settings file to set the global variables
		common.readSettings()
コード例 #13
0
    def addGrooves(self, currlibDir, pythonPath, mmaPath):
        # get all groove files starting from currlibDir, note this takes a while to complete
        mmaDir = os.path.dirname(mmaPath)
        #mmaDir = re.compile(r'.*[\\/]').match(mmaPath).group()

        currentdir = os.getcwd()
        os.chdir(mmaDir)

        global groovedict

        groovecount = 0
        p1 = re.compile(r'\\filehead\{(.*?)\}\{(.*?)\}')
        p2 = re.compile(r'\\instable\{(.*?)\}\{(.*?)\}')

        # check MMA version
        mmaversion = 1.2
        versionstr = ""
        try:
            #	quote pythonPath to handle correctly space characters in it
            cmd = "\"" + pythonPath + "\" " + mmaPath + " -v"
            #pipe = os.popen(cmd, 'r')
            pipe = subprocess.Popen(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    stdin=subprocess.PIPE).stdout
            output = pipe.read()
            versionstr = re.compile(r'^\d+\.\d+',
                                    re.S | re.M).search(output).group(0)
            mmaversion = float(versionstr)
            status = pipe.close()
            common.printOutput("Detected MMA version " + versionstr)
            logging.debug("[addGrooves] Detected MMA version " + versionstr)
        except:
            common.printOutput("Couldn't get MMA version! '" + cmd +
                               "' Assuming version > 1.0")
            logging.debug("[addGrooves] Unable to get MMA version. Using '" +
                          cmd + "'")

        # set the path part of the key to groovedict and groovelib_lookup
        # we'll define it as "<default>" if currlibDir matches the current global libDir
        # with this definition, currently loaded files will be less affected if libDir changes (when refreshing grooves)
        if currlibDir == common.libDir:
            keylibDir = "<default>"
        else:
            keylibDir = currlibDir

        # Count how many files we will be processing
        tree = os.walk(currlibDir)
        totalfiles = 0
        for directory in tree:
            for file in directory[2]:
                if file.endswith("mma"):
                    totalfiles += 1
        #print totalfiles
        progressWin = ProgressBarWindow(self)

        filecount = 0.0
        tree = os.walk(currlibDir)
        # start walking the directory
        for directory in tree:
            for file in sorted(directory[2]):
                if file.endswith("mma"):
                    filecount += 1.0
                    filename = os.path.normcase(directory[0] + "/" + file)
                    # run MMA command
                    try:
                        # NOTE: In Windows, I need a shell window for this to work!
                        #	quote pythonPath to handle correctly space characters in it
                        if mmaversion > 1.0:
                            cmd = "\"" + pythonPath + "\" " + mmaPath + " -Dxl -w " + filename
                        else:
                            cmd = "\"" + pythonPath + "\" " + mmaPath + " -Dx -w " + filename
                        pipe = subprocess.Popen(cmd,
                                                shell=True,
                                                stdout=subprocess.PIPE,
                                                stderr=subprocess.PIPE,
                                                stdin=subprocess.PIPE).stdout
                        logging.debug("[addGrooves] Calling subprocess '" +
                                      cmd + "'")
                        #pipe = os.popen(cmd, 'r')
                        grooveinfo = pipe.read()
                        status = pipe.close()

                        #print grooveinfo
                    except:
                        #common.printOutput("Oops, an error was encountered")
                        logging.debug(
                            "[addGrooves] Error encountered trying to run '" +
                            cmd + "'")

                    m1 = p1.search(grooveinfo)

                    if m1 == None:
                        continue

                    groovelibname = m1.group(1)
                    groovelibrary = groovelibname + "|" + keylibDir

                    # Rename the groovelibrary if clashes found (the mambo grooves). This is no conflict as long as the grooves themselves don't clash. If so, it will depend on MMA's resolution rules.
                    # Unfortunately, it happens that the yamaha grooves conflict with each other...
                    if groovelibrary in groovedict.keys():
                        new_groovelibname = groovelibname
                        libname_suffix = 1
                        while (new_groovelibname + "|" +
                               keylibDir) in groovedict.keys():
                            new_groovelibname = groovelibname + "_" + str(
                                libname_suffix)
                        groovelibrary = new_groovelibname + "|" + keylibDir
                        logging.debug("[addGrooves] " + groovelibname +
                                      " renamed to " + new_groovelibname)

                    groovedict[groovelibrary] = [m1.group(2), filename]

                    #print groovedict
                    m2 = p2.findall(grooveinfo)
                    grooves = []

                    headerstr = "[MMA " + versionstr + "] Reading grooves from " + currlibDir + "...\n"
                    outputstr = headerstr + "Library: " + groovelibname + "\n"

                    for groove in m2:
                        groovename = groove[0]
                        groovedesc = groove[1]

                        groovename = groovename.replace("\\\\", "\\")
                        groovename = groovename.replace("\\&", "&")
                        groovename = groovename.replace("``", "`")
                        groovename = groovename.replace("\"\"", "\"")
                        groovename = groovename.replace("\'\'", "\'")

                        groovedesc = groovedesc.replace("\\\\", "\\")
                        groovedesc = groovedesc.replace("\\&", "&")
                        groovedesc = groovedesc.replace("``", "`")
                        groovedesc = groovedesc.replace("\"\"", "\"")
                        groovedesc = groovedesc.replace("\'\'", "\'")

                        #print groovename

                        outputstr += groovename + " "
                        groovecount += 1

                        grooves += [[groovename, groovedesc]]
                        groovelib_lookup[groovename.lower() + "|" +
                                         keylibDir] = groovelibname
                    groovedict[groovelibrary] += [grooves]

                    common.printOutput(outputstr)
                    #print filecount / totalfiles
                    progressWin.set(filecount / totalfiles)

        progressWin.destroy()
        os.chdir(currentdir)
        common.printOutput(headerstr + "Done: Read " + str(groovecount) +
                           " grooves")
コード例 #14
0
    def apply(self):
        # read variables and strip trailing spaces
        pythonPath = self.pythonPathEntry.get().strip(' ')
        mmaPath = self.mmaPathEntry.get().strip(' ')
        libDir = self.mmaLibDirEntry.get().strip(' ')
        midiEngine = self.midiEngineButton["text"]
        midiPlayer = self.midiPlayerEntry.get().strip(' ')
        customGroovePath = self.customGroovePathEntry.get().strip(' ')
        measuresPerRow = self.measuresPerRowEntry.get().strip(' ')

        logging.debug("[Settings] Settings are: (" + pythonPath + "," +
                      mmaPath + "," + midiPlayer + "," + customGroovePath +
                      ")")
        # validate the existence of these paths
        if not os.path.exists(pythonPath):
            tkMessageBox.showerror(
                "Error", "Python path: '" + pythonPath + "' does not exist.")
            return
        if not os.path.exists(mmaPath):
            tkMessageBox.showerror(
                "Error", "MMA path: '" + mmaPath + "' does not exist.")
        if os.path.isdir(pythonPath):
            tkMessageBox.showerror(
                "Error", "Python path: '" + pythonPath +
                "' is a directory and not a filename.")
            return
        if os.path.isdir(mmaPath):
            tkMessageBox.showerror(
                "Error", "MMA path: '" + mmaPath +
                "' is a directory and not a filename.")
            return

        if not os.path.exists(libDir):
            tkMessageBox.showerror(
                "Error", "MMA grooves path: '" + libDir + "' does not exist.")
            return

        realmidipath = re.compile(r'\s-[^\s]*').sub(
            "", midiPlayer)  # strip any command-line options
        if not os.path.exists(realmidipath):
            tkMessageBox.showwarning(
                "Warning", "Midi player path: '" + midiPlayer +
                "' does not exist. You won't be able to play MMA files.")
        if os.path.isdir(realmidipath):
            tkMessageBox.showwarning(
                "Warning", "Midi player path: '" + midiPlayer +
                "' is a directory and not a filename. You won't be able to play the MMA file."
            )

        if customGroovePath != "" and not os.path.exists(customGroovePath):
            tkMessageBox.showwarning(
                "Warning", "Custom groove path: '" + customGroovePath +
                "' does not exist.")

        # save the settings into settings file

        config = ConfigParser.ConfigParser()
        config.read(common.settingsFile)
        if not config.has_section("paths"):
            config.add_section("paths")
        config.set("paths", "python", pythonPath)
        config.set("paths", "mma", mmaPath)
        config.set("paths", "midiplayer", midiPlayer)
        config.set("paths", "grooves", libDir)
        config.set("paths", "customgrooves", customGroovePath)

        if not config.has_section("misc"):
            config.add_section("misc")
        config.set("misc", "measures_per_row", measuresPerRow)
        config.set("misc", "midiengine", midiEngine)

        f = open(common.settingsFile, "w")
        config.write(f)
        f.close()

        common.printOutput("Settings saved in " + common.settingsFile)

        # read the settings file to set the global variables
        common.readSettings()