Questions tagged [music21]

1

votes
1

answer
30

Views

What is difference between “duration” and “offset” in MIDI files?

I'm using 'music21' library to process MIDI files. Unfortunately, the provided documentation is not so clear for ones who don't understand much about how music is composed. What is the difference between 'duration' and 'offset'? For what I understand, the first note/chord have offset 0.0, and let's...
demo
1

votes
0

answer
38

Views

Run music21 on full processor power

I am trying to create dataset by extracting only specific songs from larger dataset . By specific I mean songs only with two instruments where one is from keyboard family and another is from string family. Simplified code looks like this: for midi_file_path in Path(dir_path).glob('**/*.mid'): try:...
Konrāds Bušs
1

votes
0

answer
65

Views

Music21 and D3.js for music feature extraction and visualization?

I am looking for suggestions on what tools could be used for the following scenarios about music feature extraction and visualization (on my Mac): identify and group notes in a score (from different voices/instruments) that sound concurrently (even if they are attacked in different time offsets, tho...
Ilias Kyriazis
1

votes
0

answer
151

Views

split midi file for each bar in python

I want to divide the MIDI file in python into bars and get the notes in that bars. So I use music21 library and I can get the notes but I can't split it up by bar. I want to know what kind of notes are in bar 1 and what are in bar 2. I hope I can get some help with this problem.Thank you.
sudal
1

votes
0

answer
85

Views

Extracted all information from midi file usign music21

I'm trying to extract notes, chords and rests from a midi file with 10 instruments using music21, following this post i'm able to get these for each instruments: file = 'example.mid' midi = converter.parse(file) parts = instrument.partitionByInstrument(midi) notes_for_instruments = [] for i in r...
Giuseppe Angora
1

votes
0

answer
65

Views

Saving image files from Music21

I've downloaded a bunch of .krn files, and I'd like to convert them into images - either pngs or jpgs - using music21. I've tried this: When I do this: from music21 import * op = krnfile s = converter.parse(op) s.show() I see a great image file in the Jupyter Notebook I'm using, but when I try to...
Alex S
1

votes
1

answer
104

Views

Check which label or name a part (from krn) has in music21

I want to extract 2 parts from 4 voice krn score and save them as a midi file. I can load the files: s = converter.parse('/something.krn') I can get some basic info like this: s.metadata.title In v2, I want to store the part of s that has a label 'Cantus'. Any idea how to check for a label? They...
dorien
1

votes
1

answer
138

Views

Finding notes sounding at the same time in a different voice in a midi file

I have a midi file consisting of two parts. Now I need to print out, for each note in part 0 (including rests), which note sounds at the same time in part 1 (and the note that proceeds this). I can go through all of the notes in part 0 with music21, but how do I find the note at that time in part 1....
dorien
1

votes
1

answer
123

Views

Multiprocess tasks in python that can't be pickled?

I'm trying to use multiprocessing in python (2.7.8) on a Mac OSX. After reading Velimir Mlaker's answer to this question, I was able to use multiprocessing.Pool() to multiprocess a trivially simple function but it doesn't work with my actual function. I get the right results but it executes serially...
Alex
1

votes
1

answer
59

Views

Why is music21 using pitch attributes in an unexpected way?

Consider the following testing code. from music21 import pitch C0 = 16.35 for f in [261, 130, 653, 64, 865]: p = pitch.Pitch() p.frequency = f # Compare manual frequency with music21 frequency f1 = p.frequency f2 = C0 * pow(2, p.octave) * pow(2, p.pitchClass / 12) * pow(2, p.microtone.cents / 1200)...
1

votes
2

answer
52

Views

Does music21 include a note transition counter?

I'm trying to get transition rates between note pitches (just name, no octave) in a given melody. For example, if my melody pitches are (in order) C D E D F C B C, I should get that the C-D transition occurs with 0.5 rate, B-C has rate 1, etc. I should be able to write a function in Python to do thi...
VR_1312
1

votes
1

answer
261

Views

music21: How to append a chord to a stream simultaneously?

I have a stream object with notes (pitch and duration). I want to add chords to -for example - the first note of each 4 times. But I want them to sound at the same time. The problem is that the only related stuff I found was how to append a chord to a stream but sequentially. So... Any suggestions?
VR_1312
1

votes
3

answer
591

Views

music21: picking out melody track

I'm processing a bulk of midi files that are made for existing pop songs using music21. While channel 10 is reserved for percussions, melodic tracks are all over different channels, so I was wondering if there is an efficient way to pick out the main melody (vocal) track. I'm guessing one way to do...
ytrewq
1

votes
1

answer
302

Views

Music21 Manipulating Specific Instrument

I am using Music21 in Python to read from a MIDI file and I want to only deal with the tracks that use a certain instrument. For example, if, in my MIDI file I have two tracks that use piano I want to be able to print the notes, change the instrument, etc. Right now I have a file with multiple track...
FatUglyProud
1

votes
1

answer
56

Views

cannot divide file into parts using partitionByInstrument

Using music21 cannot divide file into parts using partitionByInstrument. from music21 import * song = converter.parse('/Nottingham/train/ashover_simple_chords_12.mid') print(len(song.parts)) # prints 2 parts = instrument.partitionByInstrument(song) print(parts.parts[0].id) Shows fallowing error pri...
Konrāds Bušs
1

votes
2

answer
0

Views

Unable to .show scores in Music21

I'm working in Jupyter Notebook. I've installed music21, musescore, set the xml path as below: us = environment.UserSettings() us['musicxmlPath'] ='Applications/musescore.app' I've also run config, and see that musescore is being detected by music21. However, when I use the show method, I get the fo...
Rachael Saxby
1

votes
1

answer
0

Views

How to (automatically) difference Opus and Score objects?

I'm working with the 1850 O'Neills Folksong corpus, as it comes on music21 corpus. I need to iterate over all the songs. I tried using the following code songs = corpus.getComposer('oneills1850') for ruta in songs: op = converter.parse(ruta) numbers = op.getNumbers() ...and then iterate on numbers....
VR_1312
1

votes
3

answer
0

Views

Import where subfolder is same as outer folder

I want to use this framework called Music21. In the shell everything works fine. For example, the command: from music21 import corpus works perfectly. In the IDE there is an import error. the music21 path is: >>> music21.__file__ '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site...
iddober
1

votes
2

answer
247

Views

Extracting measure number of key change in MusicXML

I am working a lot with MusicXML files and am trying to compile a list of the bars in which there are key changes in a number of pieces. I am in need of some help using python to first identify where the tags occur in the XML file, and then extracting the number from the tag above. Here is an exam...
user2025161
1

votes
1

answer
154

Views

music21 --> stream.chordify() not working

total newbie with music21 here. I'm trying to use chordify(): http://web.mit.edu/music21/doc/usersGuide/usersGuide_09_chordify.html How do you obtain a stream object (on which you can call chordify()) from a midi file? I tried two approaches: 1: s = converter.parse(fn) for el in s.recurse(): print...
Nick463
1

votes
1

answer
0

Views

How to make MIDI file from notes with Flute instrument in Python (music21 library)

I have some notes and what I want is create the MIDI file with Flute instrument. But what happens is that the output MIDI file plays Piano, instead of Flute. I tried other instruments, but it's always the same, Piano. What is going on? (...) new_note = note.Note(pattern) new_note.offset = offset new...
demo
1

votes
1

answer
745

Views

Music21 Getting All notes with Durations

Im trying to get all notes with their durations(measures). from music21 import * allBach = corpus.search('bach') x = allBach[0] p = x.parse() partStream = p.parts.stream() for n in p.pitches: print 'Pitch: ' + str(n) print '*************' for n in p.notes: print 'Note: ' + str(n) #print 'Duration '...
Nerzid
1

votes
1

answer
339

Views

music21: writing notes to MIDI file by note position

I am using music21 to write midi file from the note values. Following code writes three notes sequentially. However, how do I insert an 'empty' space between the notes? It would be very easy if I could just insert the notes by their 'position' so that I wouldn't have to calculate the position/length...
ytrewq
1

votes
1

answer
736

Views

How to Extract Individual Chords, Rests, and Notes from a midi file?

I am making a program that should be able to extract the notes, rests, and chords from a certain midi file and write the respective pitch (in midi tone numbers - they go from 0-127) of the notes and chords to a csv file for later use. For this project, I am using the Python Library 'Music21'. from m...
Ikechukwu Anude
1

votes
1

answer
170

Views

data exchange between R and python (music21)

My goal is to take a text file with a number list generated by R (e.g 1 2 3 4), and 'translate' the numbers into music21 notes (that is, to compose a melody when each note is identified with a number). Having the number list, one idea I had was creating a R vector with strings that matches with mus...
VR_1312
3

votes
2

answer
4.7k

Views

Music21 Midi Error: type object '_io.StringIO' has no attribute 'StringIO'. How to fix it?

So, I've followed this question in order to get some sound playing with Music21, and here's the code: from music21 import * import random def main(): # Set up a detuned piano # (where each key has a random # but consistent detuning from 30 cents flat to sharp) # and play a Bach Chorale on it i...
5

votes
2

answer
1.8k

Views

Creating images of notes in music21

I get an error when running: from music21 import * n1 = note.Note('C4', quarterLength=1) n2 = note.Note('A4', quarterLength=1) s = stream.Stream() s.append(n1) s.append(n2) s.show('lily.svg') Traceback (most recent call last): File 'C:\Python34\test.py', line 7, in s.show('lily.svg') File 'C:\Pytho...
Christian
6

votes
2

answer
2.4k

Views

How can I produce real-time audio output from music made with Music21?

How can I produce real-time audio output from music made with Music21. Failing that, how can i produce ANY audio output from music made with Music21 via open-source software? Thanks for the help.
5

votes
3

answer
137

Views

Install by default, “optional” dependencies in Python (setuptools)

Is there a way to specify optional dependencies for a Python package that should be installed by default from pip but for which an install should not be considered a failure if they cannot be installed? I know that I can specify install_requires so that the packages will be installed for the 90% of...
2

votes
1

answer
454

Views

music21: parsing notes and durations per track

I'm trying to use music21 to convert multi-track midi files into array of notes and durations per each track. For example, given a midi file test.mid with 16 tracks in it, I would like to get 16 arrays of tuples, consisting of (pitch, duration (plus maybe position of the note)). Documentation for mu...
ytrewq
2

votes
1

answer
324

Views

Extract acoustic bass drum from midi file by using music21 library

I downloaded the midi file from here: Taylor Swift - You Belong With Me.mid Then I want to only extract the acoustic bass drum part, which means I want the output acoustic bass drum.mid of this song. I used music21 library to parse the midi file, below is my code: from music21 import * import os fp...
pc101
2

votes
1

answer
488

Views

How to set application path in music21

I'm using Ubuntu 14.04 64bit. I don't know what to set on path to application. I have installed music21 in anaconda3, but I got output as follows: music21.converter.subConverters.SubConverterException: Cannot find a valid application path for format midi. Specify this in your Environment by calling...
Július Marko
2

votes
3

answer
240

Views

Is it possible to analyze mp3 file using music21?

I am looking for python library to find out a key and tempo of the song recorded in MP3 format. I've found the music21 lib that allows doing that. But it seems like it works only with midi files. Does somebody know how to parse MP3 files using music21 and get the required sound characteristics? If...
Kirill Liubun
2

votes
0

answer
642

Views

music21: read MIDI file's BPM and instrument info and write it back to file

I'm trying to implement a code that reads MIDI file and writes it back. I have the following code to parse the duration,pitch,and position. import music21 from music21 import * piece=converter.parse('input.mid') all_parts=[] for part in piece.parts: part_tuples=[] try: track_name = part[0].bestName(...
ytrewq
3

votes
1

answer
1.4k

Views

Generating pdf & midi from musicxml

I've been trying to load a MusicXML file, edit it (removing several parts), and create a PDF sheet document + midi/mp3, all of this using Python. I've first looked at music21, that would load my MusicXML file right, but as far as I could find, would not output a proper file (all the details in the o...
Joachim Jablon
2

votes
1

answer
1k

Views

Music21: Get all Notes per Instrument from a MIDI File

I am parsing a MIDI file as instructed here. My code looks like this: from music21 import converter,instrument # or import * file = converter.parse('sample.mid') components = [] for element in file.recurse(): components.append(element) The components list now contains data as follows: , , , , , , ,...
sri
4

votes
4

answer
1.3k

Views

Display of music21, musicXML PNG objects using iPython Notebook/Enthought Canopy

I am experimenting with the music21 library, in preparation for a Machine Learning project that involves genre classification and categorization. I and following some tutorials available here. I am using MuseScore as my MusicXML program, and I am trying to run the whole thing from iPython. Although...
Luis Miguel
1

votes
1

answer
230

Views

How to replace pitches in a music21 Score

I'm trying to replace one pitch in a score with another pitch (the end goal being to generate harmony parts). >>> from music21 import * >>> score = converter.parse('test.mid') >>> type(score) >>> p0 = score.parts[0].pitches[0] >>> p0sharp = p0.transpose(1) >>> print p0 A3 >>> print p0sharp B-3 >>>...
AndyP
2

votes
2

answer
124

Views

Python music21 library create png from stream

I have a problem with generate png file from stream object in music21. I read documentation and I use ConverterLilypond to do this. chords = stream.Stream() d7 = chord.Chord(['D4', 'F4', 'A4', 'C5']) dmin7 = chord.Chord(['D4', 'F-4', 'A4', 'C5']) dmaj7 = chord.Chord(['D4', 'F#4', 'A4', 'C#5']) chor...
lukassz
2

votes
1

answer
154

Views

How can I display an empty staff using music21?

I am trying to produce a quick reworking of some educational materials on music showing how it may be able to create the associated media assets (images, audio files) from 'code' in a Jupyter notebook using the Python music21 package. It seems the simplest steps are the hardest. For example, how d...
psychemedia

View additional questions