def setup_musescore(musescore_path=None): if not is_ipython(): return import platform from music21 import environment from pathlib import Path system = platform.system() if system == 'Linux': import os os.environ[ 'QT_QPA_PLATFORM'] = 'offscreen' # https://musescore.org/en/node/29041 existing_path = environment.get('musicxmlPath') if existing_path: return if musescore_path is None: if system == 'Darwin': app_paths = list(Path('/Applications').glob('MuseScore *.app')) if len(app_paths): musescore_path = app_paths[-1] / 'Contents/MacOS/mscore' elif system == 'Linux': musescore_path = '/usr/bin/musescore' if musescore_path is None or not Path(musescore_path).exists(): print( 'Warning: Could not find musescore installation. Please install musescore (see README) and/or update music21 environment paths' ) else: environment.set('musicxmlPath', musescore_path) environment.set('musescoreDirectPNGPath', musescore_path)
def __init__(self): """Constructor.""" if sys.platform == "darwin": import os LILYPOND_EXEC_PATH = "/Applications/LilyPond.app/Contents/Resources/bin/lilypond" if os.path.exists(LILYPOND_EXEC_PATH): environment.set("lilypondPath", LILYPOND_EXEC_PATH)
def create_output_dir(self): self.output_dir = os.path.join(self.output_dir_parent, self.output_dir_name) # if temporary directory doesn't exist, create it if not os.path.exists(self.output_dir): os.makedirs(self.output_dir) # Set up temp file directory environment.set('directoryScratch', self.output_dir)
############################################################################## # You don't need to understand most of this yet- you can just skip to the # # large comment section below if this is all a bit daunting! # ############################################################################## # Import the libraries we need import sys from music21 import ( environment, metadata, note, stream, ) # Tell music21 what to use to play midi and display score environment.set('midiPath', '/usr/bin/timidity') environment.set('musicxmlPath', '/usr/bin/musescore') ############################################################################## # LESSON 1 STARTS HERE # ############################################################################# # This is our first lesson, so play a scale with our right hand # Create the first bar, in the default 4/4 time bar1_right = stream.Measure() # Add each note we want to play in turn to the bar bar1_right.append(note.Note('c4')) bar1_right.append(note.Note('d4')) bar1_right.append(note.Note('e4')) bar1_right.append(note.Note('f4'))
############################################################################ ND_modelFilepath = "../weights/30_note-duration_sequence20_epoch20_LLDD_WD" ND_sequenceLength = 20 NN_modelFilepath = "../weights/old_weights/3L_2LSTM1D_WD_SL15_model_epoch65_batch15" NN_sequenceLength = 15 newMelodyLength = 50 starter = Tune.Tune("../ABC/ABCChina06") inputIndex = 5 inputIndex2 = 15 ############################################################################ environment.set('musicxmlPath', '/bin/musescore3') ND_model = NeuralNetwork.NeuralNetwork() ND_model.load_model(ND_modelFilepath) starterInput, temp = starter.getTrainData(ND_sequenceLength) ND_input = starterInput[inputIndex] ND_inputShape = (1, ND_sequenceLength, 450) NN_model = NeuralNetwork.NeuralNetwork() NN_model.load_model(NN_modelFilepath) starterInput, temp = starter.getTrainData(NN_sequenceLength) NN_input = starterInput[inputIndex] NN_inputShape = (1, NN_sequenceLength, 450) melody = [] for noteIndex in range(newMelodyLength):
from music21 import environment # place the path to the installed location of musescore # if you are in windows it may be something like C:/MuseScore2/bin/MuseScore.exe" # if you are on linux you might have to set permission to musescore musescore_path = "/usr/bin/musescore" environment.set("musescoreDirectPNGPath", musescore_path) environment.set("musicxmlPath", musescore_path)
from music21 import environment MUSESCORE_PATH = '/usr/bin/musescore' if __name__ == '__main__': environment.set('musicxmlPath', MUSESCORE_PATH) environment.set('musescoreDirectPNGPath', MUSESCORE_PATH)
def ready(self): environment.set('directoryScratch', settings.MEDIA_ROOT) environment.set('musescoreDirectPNGPath', settings.BASE_DIR + '/sh/mscore.sh') environment.set('musicxmlPath', settings.BASE_DIR + '/sh/mscore.sh')
""" Constructs an EmaExp for every nanopub on the page. """ file_names = get_jsonlds(page_num) ema_exps = [] for file_name in file_names: ema_url = ema_url_from_jsonld(file_name) ema_exps.append(EmaExp(*ema_url.split("/")[:-3])) return ema_exps def print_elems_recursive(elem, i=0): print(" "*i, elem) for child in elem: print_elems_recursive(child, i+4) environment.set('autoDownload', 'allow') if __name__ == '__main__' and len(sys.argv) == 2 and sys.argv[1] == "scrape": print(os.getcwd()) if os.path.basename(os.getcwd()) == 'emaMXL': os.chdir('tst') if os.path.basename(os.getcwd()) != 'tst': print("\"scraper.py scrape\" should be run from within the emaMXL root folder or emaMXL/tst.") exit() if not os.path.exists("data"): os.mkdir('data') os.mkdir('data/selections') os.mkdir('data/scores') for p in range(1, LAST_PAGE+1):
import logging from logging.config import dictConfig from music21 import note, converter, serial, corpus, stream, analysis, environment environment.set('musicxmlPath', '/usr/bin/musescore') environment.set('midiPath', '/usr/bin/timidity') environment.set('graphicsPath', '/usr/bin/gpicview') def note_example(): n = note.Note("D#3") n.duration.type = 'half' n.show() def melody(): little_melody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#") little_melody.show() def melody_midi(): little_melody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#") little_melody.show('midi') def row_mat(): print(serial.rowToMatrix([2, 1, 9, 10, 5, 3, 4, 0, 8, 7, 6, 11])) def dicant_plot():
parser.add_argument('--infile', default='epTest_cnnseq2sample-s{}-em{}_cnnseq2seqAudio.wav'.format(sample, em_type_int), # 'set6_epTest_cnnseq2sample-s16-em1_cnnseq2seqAudio.wav', help='Filename waveform') parser.add_argument('--outfile', default='epTest_cnnseq2sample-s{}-em{}_cnnseq2seqAudio.mid'.format(sample, em_type_int), # 'set6_epTest_cnnseq2sample-s16-em1_cnnseq2seqAudio.mid', help='Filename MIDI') args = parser.parse_args() return args # For linux # Fix: "music21.environment.EnvironmentException: Cannot find a valid application path for format None. Specify this in your Environment by calling environment.set('graphicsPath', '/path/to/application')" # https://web.mit.edu/music21/doc/moduleReference/moduleEnvironment.html us = environment.UserSettings() environment.set('graphicsPath', '/usr/bin/timidity') args = init_parse() data_dir = args.data_dir # print(os.listdir(data_dir)) # Save as test.mid audio_to_midi_melodia(infile=data_dir + args.infile, outfile=data_dir + args.outfile, bpm=146, smooth=0.25, minduration=0.1) # base_midi = open_midi(concat_path(sonic_path, "green-hill-zone.mid"), True) midi_path = concat_path(data_dir, args.outfile) print(midi_path) base_midi = open_midi(midi_path, True) # print(base_midi)