def launch(self, fmt, fp, options='', app=None): # see common.fileExtensions for format names m21Format, unused_ext = common.findFormat(fmt) if m21Format == 'lilypond': environmentKey = 'lilypondPath' elif m21Format in ['png', 'jpeg']: environmentKey = 'graphicsPath' elif m21Format in ['svg']: environmentKey = 'vectorPath' elif m21Format in ['pdf']: environmentKey = 'pdfPath' elif m21Format == 'musicxml': environmentKey = 'musicxmlPath' elif m21Format == 'midi': environmentKey = 'midiPath' elif m21Format == 'vexflow': try: import webbrowser if fp.find('\\') != -1: pass else: if fp.startswith('/'): fp = 'file://' + fp webbrowser.open(fp) return except: print "Cannot open webbrowser, sorry. go to file://%s" % fp else: environmentKey = None fpApp = None if environmentKey is not None: fpApp = self._ref[environmentKey] # substitute app provided via argument if app is not None: fpApp = app platform = common.getPlatform() if fpApp is None and platform not in ['win', 'darwin']: raise EnvironmentException( "Cannot find a valid application path for format %s. Specify this in your Environment by calling environment.set(%r, 'pathToApplication')" % (m21Format, environmentKey)) if platform == 'win' and fpApp is None: # no need to specify application here: windows starts the program based on the file extension cmd = 'start %s' % (fp) elif platform == 'win': # note extra set of quotes! cmd = '""%s" %s "%s""' % (fpApp, options, fp) elif platform == 'darwin' and fpApp is None: cmd = 'open %s %s' % (options, fp) elif platform == 'darwin': cmd = 'open -a"%s" %s %s' % (fpApp, options, fp) elif platform == 'nix': cmd = '%s %s %s' % (fpApp, options, fp) os.system(cmd)
def launch(self, fmt, fp, options='', app=None): # see common.fileExtensions for format names format, ext = common.findFormat(fmt) if format == 'lilypond': environmentKey = 'lilypondPath' elif format in ['png', 'jpeg']: environmentKey = 'graphicsPath' elif format in ['svg']: environmentKey = 'vectorPath' elif format in ['pdf']: environmentKey = 'pdfPath' elif format == 'musicxml': environmentKey = 'musicxmlPath' elif format == 'midi': environmentKey = 'midiPath' elif format == 'vexflow': try: import webbrowser if fp.find('\\') != -1: pass else: if fp.startswith('/'): fp = 'file://' + fp webbrowser.open(fp) return except: print "Cannot open webbrowser, sorry. go to file://%s" % fp else: environmentKey = None fpApp = None if environmentKey is not None: fpApp = self._ref[environmentKey] # substitute app provided via argument if app is not None: fpApp = app platform = common.getPlatform() if fpApp is None and platform not in ['win', 'darwin']: raise EnvironmentException("Cannot find a valid application path for format %s. Specify this in your Environment by calling environment.set(%r, 'pathToApplication')" % (format, environmentKey)) if platform == 'win' and fpApp is None: # no need to specify application here: windows starts the program based on the file extension cmd = 'start %s' % (fp) elif platform == 'win': # note extra set of quotes! cmd = '""%s" %s "%s""' % (fpApp, options, fp) elif platform == 'darwin' and fpApp is None: cmd = 'open %s %s' % (options, fp) elif platform == 'darwin': cmd = 'open -a"%s" %s %s' % (fpApp, options, fp) elif platform == 'nix': cmd = '%s %s %s' % (fpApp, options, fp) os.system(cmd)
def writeStream(m21stream, format='midi', wrtpath=None, scoreTitle=None, scoreComposer=None, scoreTempo=None, scoreInstruments=None): """ scoreTitle: str scoreComposer: str scoreTempo: int scoreInstrument: str Write out Music21 stream in a given format. If wrtpath is not specified the file is written in the current working directory (as 'untitled.ext'), or if wrtpath is a directory, 'untitled.ext' files are written there. The possible output formats are musicxml lily(pond) midi """ import os from music21.common import findFormat fmt, ext = findFormat(format) if not wrtpath: wrtpath = os.path.join(os.getcwd(), 'untitled' + ext) if os.path.isdir(wrtpath): wrtpath = os.path.join(wrtpath, 'untitled' + ext) # Part writing (app.py: MyFrame.getOffsetScore) if isinstance(m21stream, stream.Part): import copy score = stream.Score() score.append(copy.deepcopy(m21stream)) m21stream = score # Metadata if not m21stream.metadata: m21stream.insert(0.0, metadata.Metadata()) if scoreTitle: m21stream.metadata.title = scoreTitle else: m21stream.metadata.title = "Untitled" if scoreComposer: m21stream.metadata.composer = scoreComposer else: m21stream.metadata.composer = "Unknown Composer" if scoreTempo: m21stream.insert(0, tempo.MetronomeMark(number=scoreTempo)) if scoreInstruments: if len(scoreInstruments) == 1: for p in m21stream.parts: p.insert(0, instrument.fromString(scoreInstruments[0])) else: parts = m21stream.parts for n, i in enumerate(scoreInstruments): parts[n].insert(0, instrument.fromString(i)) m21stream.write(format, wrtpath)
def idAndParseFile(fileToParse,filename): '''Takes in a file object and filename, identifies format, and returns parsed file''' matchedFormat = re.sub(r'^.*\.', '', filename) if matchedFormat == "": pass else: music21FormatName = common.findFormat(matchedFormat)[0] if music21FormatName is None: parsedFile = None else: parsedFile = converter.parse(fileToParse.read(),format=music21FormatName) return parsedFile
def launch(self, fmt, fp, options='', app=None): ''' Opens a file with an either default or user-specified applications. OMIT_FROM_DOCS Optionally, can add additional command to erase files, if necessary Erase could be called from os or command-line arguments after opening the file and then a short time delay. TODO: Move showImageDirectfrom lilyString.py ; add MIDI TODO: Switch to module subprocess to prevent hanging. ''' # see common.fileExtensions for format names format, ext = common.findFormat(fmt) if format == 'lilypond': fpApp = self.ref['lilypondPath'] elif format in ['png', 'jpeg']: fpApp = self.ref['graphicsPath'] elif format in ['pdf']: fpApp = self.ref['pdfPath'] elif format == 'musicxml': fpApp = self.ref['musicxmlPath'] elif format == 'midi': fpApp = self.ref['midiPath'] else: fpApp = None # substitute provided app if app != None: fpApp = app platform = common.getPlatform() if fpApp is None and platform != 'win': raise EnvironmentException("Cannot find an application for format %s, specify this in your environment" % fmt) if platform == 'win' and fpApp is None: # no need to specify application here: windows starts the program based on the file extension cmd = 'start %s' % (fp) elif platform == 'win': # note extra set of quotes! cmd = '""%s" %s "%s""' % (fpApp, options, fp) elif platform == 'darwin': cmd = 'open -a"%s" %s %s' % (fpApp, options, fp) elif platform == 'nix': cmd = '%s %s %s' % (fpApp, options, fp) print cmd os.system(cmd)
def writeStream(m21stream, format='midi', wrtpath=None, scoreTitle=None, scoreComposer=None, scoreTempo=None, scoreInstruments=None): """ scoreTitle: str scoreComposer: str scoreTempo: int scoreInstruments: list[ str ] Write out Music21 stream in a given format. If wrtpath is not specified the file is written in the current working directory (as 'untitled.ext'), or if wrtpath is a directory, 'untitled.ext' files are written there. The possible output formats are musicxml lily(pond) midi """ import os from music21.common import findFormat fmt, ext = findFormat(format) if not wrtpath: wrtpath = os.path.join(os.getcwd(), 'untitled' + ext) if os.path.isdir(wrtpath): wrtpath = os.path.join(wrtpath, 'untitled' + ext) # Part writing (app.py: MyFrame.getOffsetScore) if isinstance(m21stream, stream.Part): import copy score = stream.Score() score.append(copy.deepcopy(m21stream)) m21stream = score # Metadata setMetadata(m21stream, scoreTitle=scoreTitle, scoreComposer=scoreComposer, scoreTempo=scoreTempo, scoreInstruments=scoreInstruments, midiPrograms=False) m21stream.write(format, wrtpath)
def launch(self, fmt, filePath, options='', app=None): ''' DEPRECATED May 24, 2014 -- call Launch on SubConverter Needed still just for graphics, graph.launch('png'), lily.translate(), scale Create a png, svg, etc. converter (or just a graphics converter) and call launch on it ''' # see common.fileExtensions for format names m21Format, unused_ext = common.findFormat(fmt) environmentKey = self.formatToKey(m21Format) if environmentKey is None: environmentKey = self.formatToKey(fmt) if m21Format == 'vexflow': try: import webbrowser if filePath.find('\\') != -1: pass else: if filePath.startswith('/'): filePath = 'file://' + filePath webbrowser.open(filePath) return except ImportError: print('Cannot open webbrowser, sorry. Go to file://{}'.format( filePath)) if app is not None: # substitute app provided via argument fpApp = app elif environmentKey is not None: fpApp = self._ref[environmentKey] else: fpApp = None platform = common.getPlatform() if fpApp is None: if platform == 'win': # no need to specify application here: # windows starts the program based on the file extension cmd = 'start %s' % (filePath) elif platform == 'darwin': cmd = 'open %s %s' % (options, filePath) else: if m21Format == 'braille': with open(filePath, 'r') as f: for line in f: print(line, end="") print("") return else: raise EnvironmentException( "Cannot find a valid application path for format {}. " "Specify this in your Environment by calling " "environment.set({!r}, 'pathToApplication')".format( m21Format, environmentKey)) elif platform == 'win': # note extra set of quotes! cmd = '""%s" %s "%s""' % (fpApp, options, filePath) elif platform == 'darwin': cmd = 'open -a"%s" %s "%s"' % (fpApp, options, filePath) elif platform == 'nix': cmd = '%s %s "%s"' % (fpApp, options, filePath) os.system(cmd)