def testTrillExtensionA(self): """Test basic wave line creation and output, as well as passing objects through make measure calls. """ from music21 import stream, note, chord, expressions from music21.musicxml import m21ToString s = stream.Stream() s.repeatAppend(note.Note(), 12) n1 = s.notes[0] n2 = s.notes[-1] sp1 = expressions.TrillExtension(n1, n2) s.append(sp1) raw = m21ToString.fromMusic21Object(s) self.assertEqual(raw.count("wavy-line"), 2) s = stream.Stream() s.repeatAppend(chord.Chord(["c-3", "g4"]), 12) n1 = s.notes[0] n2 = s.notes[-1] sp1 = expressions.TrillExtension(n1, n2) s.append(sp1) raw = m21ToString.fromMusic21Object(s) # s.show() self.assertEqual(raw.count("wavy-line"), 2)
def testBasic(self): from music21 import musedata from music21.musedata import testFiles from music21.musicxml import m21ToString mdw = musedata.MuseDataWork() mdw.addString(testFiles.bach_cantata5_mvmt3) s = museDataWorkToStreamScore(mdw) #post = s.musicxml #s.show() self.assertEqual(len(s.parts), 3) self.assertEqual(s.parts[0].id, 'Viola Solo') self.assertEqual(s.parts[1].id, 'TENORE') self.assertEqual(s.parts[2].id, 'Continuo') self.assertEqual(len(s.parts[0].flat.notesAndRests), 1062) self.assertEqual(len(s.parts[1].flat.notesAndRests), 596) self.assertEqual(len(s.parts[2].flat.notesAndRests), 626) # try stage 1 mdw = musedata.MuseDataWork() mdw.addString(testFiles.bachContrapunctus1_part1) mdw.addString(testFiles.bachContrapunctus1_part2) s = museDataWorkToStreamScore(mdw) self.assertEqual(len(s.parts[0].flat.notesAndRests), 291) self.assertEqual(len(s.parts[1].flat.notesAndRests), 293) unused_raw = m21ToString.fromMusic21Object(s)
def testMusicxmlOutput(self): # test direct rendering of musicxml from music21.musicxml import m21ToString d = Dynamic('p') xmlout = m21ToString.fromMusic21Object(d) match = '<p/>' self.assertTrue(xmlout.find(match) != -1)
def write(self, obj, fmt, fp=None, subformats=None, **keywords): from music21.musicxml import m21ToString dataStr = m21ToString.fromMusic21Object(obj) fp = self.writeDataStream(fp, dataStr) if subformats is not None and 'png' in subformats: fp = self.runThroughMusescore(fp, **keywords) return fp
def noteflightEmbed(outputStream): """ Takes in a stream outputStream, and a string title. Returns the HTML for a page containing a noteflight flash embed of the stream and the title title TODO: Change javascript and noteflight embed to relate to be server-specific >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = alpha.webapps.templates.noteflightEmbed(sc) >>> contentType 'text/html; charset=utf-8' """ from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) musicxmlString = musicxmlString.replace("\n", "") musicxmlString = musicxmlString.replace("'", "\\'") htmlStr = """ <html> <head> <title>Music21 URL App Response</title> <script language="javascript" src="http://web.mit.edu/music21/webapps/client/javascript/music21.js"></script> <script> // Event handling function function noteflightEventHandler(e) { if(e.type == 'scoreDataLoaded') { m21.noteflight.sendMusicXMLToNoteflightEmbed('nfscore', '$musicxml') } } </script> <script language="javascript"> m21 = new Music21interface(); function setup() { m21.noteflight.createNoteflightEmbed('noteflightembed', 'nfscore', 'fc79df30896da6aa03f90ff771015913ca6880be',800,450,1.0); } </script> </head> <body onload="setup()"> <h1>Music21 Output</h1> <div id="noteflightembed"> </div> </body> </html> """ htmlData = Template(htmlStr) htmlData = htmlData.safe_substitute(musicxml=musicxmlString) return (htmlData.encode("utf-8"), "text/html; charset=utf-8")
def noteflightEmbed(outputStream): ''' Takes in a stream outputStream, and a string title. Returns the HTML for a page containing a noteflight flash embed of the stream and the title title TODO: Change javascript and noteflight embed to relate to be server-specific >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = alpha.webapps.templates.noteflightEmbed(sc) >>> contentType 'text/html; charset=utf-8' ''' from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) musicxmlString = musicxmlString.replace('\n', '') musicxmlString = musicxmlString.replace('\'', '\\\'') htmlStr = """ <html> <head> <title>Music21 URL App Response</title> <script language="javascript" src="http://web.mit.edu/music21/webapps/client/javascript/music21.js"></script> <script> // Event handling function function noteflightEventHandler(e) { if(e.type == 'scoreDataLoaded') { m21.noteflight.sendMusicXMLToNoteflightEmbed('nfscore', '$musicxml') } } </script> <script language="javascript"> m21 = new Music21interface(); function setup() { m21.noteflight.createNoteflightEmbed('noteflightembed', 'nfscore', 'fc79df30896da6aa03f90ff771015913ca6880be',800,450,1.0); } </script> </head> <body onload="setup()"> <h1>Music21 Output</h1> <div id="noteflightembed"> </div> </body> </html> """ htmlData = Template(htmlStr) htmlData = htmlData.safe_substitute(musicxml=musicxmlString) return (htmlData.encode('utf-8'), 'text/html; charset=utf-8')
def testBasic(self): from music21 import abc from music21.abc import translate from music21.musicxml import m21ToString af = abc.ABCFile() for tf in ALL: ah = af.readstr(tf) environLocal.printDebug([ah.getTitle()]) s = translate.abcToStreamScore(ah) # run musicxml processing to look for internal errors unused_out = m21ToString.fromMusic21Object(s)
def testBasic(self): from music21 import abcFormat from music21.abcFormat import translate from music21.musicxml import m21ToString af = abcFormat.ABCFile() for tf in ALL: ah = af.readstr(tf) environLocal.printDebug([ah.getTitle()]) s = translate.abcToStreamScore(ah) # run musicxml processing to look for internal errors unused_out = m21ToString.fromMusic21Object(s)
def musicxmlText(outputStream): ''' Takes in a stream outputStream and returns its musicxml with content-type 'text/plain' for displaying in a browser >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = webapps.templates.musicxmlText(sc) >>> contentType 'text/plain; charset=utf-8' >>> 'score-partwise' in output True ''' from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) return (musicxmlString.encode('utf-8'), 'text/plain; charset=utf-8')
def musicxmlText(outputStream): ''' Takes in a stream outputStream and returns its musicxml with content-type 'text/plain' for displaying in a browser >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = alpha.webapps.templates.musicxmlText(sc) >>> contentType 'text/plain; charset=utf-8' >>> b'score-partwise' in output True ''' from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) return (musicxmlString.encode('utf-8'), 'text/plain; charset=utf-8')
def musicxmlFile(outputStream): ''' Takes in a stream outputStream and returns its musicxml with content-type 'application/vnd.recordare.musicxml+xml' for downloading >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = alpha.webapps.templates.musicxmlFile(sc) >>> contentType 'application/vnd.recordare.musicxml+xml; charset=utf-8' >>> b'score-partwise' in output True ''' from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) return (musicxmlString.encode('utf-8'), 'application/vnd.recordare.musicxml+xml; charset=utf-8')
def testTrillExtensionA(self): '''Test basic wave line creation and output, as well as passing objects through make measure calls. ''' from music21 import stream, note, chord, expressions from music21.musicxml import m21ToString s = stream.Stream() s.repeatAppend(note.Note(), 12) n1 = s.notes[0] n2 = s.notes[-1] sp1 = expressions.TrillExtension(n1, n2) s.append(sp1) raw = m21ToString.fromMusic21Object(s) self.assertEqual(raw.count('wavy-line'), 2) s = stream.Stream() s.repeatAppend(chord.Chord(['c-3', 'g4']), 12) n1 = s.notes[0] n2 = s.notes[-1] sp1 = expressions.TrillExtension(n1, n2) s.append(sp1) raw = m21ToString.fromMusic21Object(s) #s.show() self.assertEqual(raw.count('wavy-line'), 2)
def musicxmlFile(outputStream): ''' Takes in a stream outputStream and returns its musicxml with content-type 'application/vnd.recordare.musicxml+xml' for downloading >>> sc = corpus.parse('bwv7.7').measures(0,2) >>> (output, contentType) = webapps.templates.musicxmlFile(sc) >>> contentType 'application/vnd.recordare.musicxml+xml; charset=utf-8' >>> 'score-partwise' in output True ''' from music21.musicxml import m21ToString musicxmlString = m21ToString.fromMusic21Object(outputStream) return (musicxmlString.encode('utf-8'), 'application/vnd.recordare.musicxml+xml; charset=utf-8')
def write(self, obj, fmt, fp=None, subformats=None, **keywords): from music21.musicxml import m21ToString ### hack to make musescore excerpts -- fix with a converter class in MusicXML if subformats is not None and 'png' in subformats: savedDefaultTitle = defaults.title savedDefaultAuthor = defaults.author defaults.title = '' defaults.author = '' dataStr = m21ToString.fromMusic21Object(obj) fp = self.writeDataStream(fp, dataStr) if subformats is not None and 'png' in subformats: defaults.title = savedDefaultTitle defaults.author = savedDefaultAuthor if subformats is not None and 'png' in subformats: fp = self.runThroughMusescore(fp, **keywords) return fp