def test(): from music21 import instrument as j sc1 = stream.Score() # instruments = [Piccolo(), Glockenspiel(), 72, 69, 41, 27, 47, 1, 1, 1, 1, 34] instrument = [ j.Piccolo(), j.Xylophone(), j.Clarinet(), j.Oboe(), j.Violin(), j.ElectricGuitar(), j.Harp(), j.Piano(), j.Piano(), j.Piano(), j.Piano(), j.ElectricBass() ] instrumentOctave = [3, 2, 2, 2, 1, 1, 1, 2, 1, 0, -1, -2] for i in range(12): inst = instrument[i] if i < 9: inst.midiChannel = i else: inst.midiChannel = i + 1 part = addPart(instrument=inst) if instrumentOctave[i] != 0: part.transpose(12 * instrumentOctave[i], inPlace=True) sc1.insert(0, part) sc1.show()
def testMultipleInstruments(self): ''' This is a score for two woodwind players both doubling on flute and oboe. They both switch to flute and then back to oboe. There are six m21 instruments to represent this, but the <score-instrument> tags need just four, since no musicXML <part> needs two oboes in it, etc., unless there is a patch change/MIDI instrument change. ''' p1 = stream.Part([ stream.Measure([instrument.Oboe(), note.Note(type='whole')]), stream.Measure([instrument.Flute(), note.Note(type='whole')]), stream.Measure([instrument.Oboe(), note.Note(type='whole')]), ]) p2 = stream.Part([ stream.Measure([instrument.Oboe(), note.Note(type='whole')]), stream.Measure([instrument.Flute(), note.Note(type='whole')]), stream.Measure([instrument.Oboe(), note.Note(type='whole')]), ]) s = stream.Score([p1, p2]) scEx = ScoreExporter(s) tree = scEx.parse() self.assertEqual(len(tree.findall('.//score-instrument')), 4) self.assertEqual(len(tree.findall('.//measure/note/instrument')), 6) self.assertEqual( tree.find('.//score-instrument').get('id'), tree.find('.//measure/note/instrument').get('id')) self.assertNotEqual( tree.find('.//score-instrument').get('id'), tree.findall('.//measure/note/instrument')[-1].get('id'))
def get_instruments(genre, ontology): programs = [] if genre.label[0] == "Blues": programs.append(instrument.AcousticGuitar().midiProgram) programs.append(instrument.Harmonica().midiProgram) programs.append(instrument.TomTom().midiProgram) elif genre.label[0] == "Folk": programs.append(instrument.Banjo().midiProgram) programs.append(instrument.AcousticBass().midiProgram) programs.append(instrument.Piano().midiProgram) elif genre.label[0] == "Rock": programs.append(instrument.ElectricGuitar().midiProgram) programs.append(instrument.ElectricBass().midiProgram) programs.append(instrument.BassDrum().midiProgram) elif genre.label[0] == "Classical": programs.append(instrument.Violin().midiProgram) programs.append(instrument.Oboe().midiProgram) programs.append(instrument.Flute().midiProgram) programs.append(instrument.Viola().midiProgram) elif genre.label[0] == "Country": programs.append(instrument.AcousticGuitar().midiProgram) programs.append(instrument.Banjo().midiProgram) programs.append(instrument.TomTom().midiProgram) return programs