Comments (4)
This is my work around method:
I parse the file with pattern= midi.read_midifile("/path/to/file"). This gives a list with the note off event.
I do a for statement that goes through the list and adds up the ticks as it goes.
When it gets to a noteOnEvent, it adds the note to a 'activenotelist' and records the current tick with it.
when it gets to a noteOffEvent, it checks the 'activenotelist' for the note and calculates the duration by subtracting the tick that was recorded with the note in the 'activenotelist' from the current tick value.
from python-midi.
_I only got the NoteOnEvent, where is the NoteOffEvent?_
Some MIDIfiles (including the provided example mary.mid) might not actually use note off commands to stop notes from playing. Check out the beginning of the track dump for mary.mid:
midi.NoteOnEvent(tick=0, channel=0, data=[64, 72]),
midi.NoteOnEvent(tick=0, channel=0, data=[55, 70]),
midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]),
Notice how note 64 (E4) plays at a velocity of 72, and then two events later it plays at a velocity of 0. Since each scale note can only be playing once (per channel/per track), this overrides the previous value and essentially turns off the note by playing again, but at 0 volume. This is technically a valid way to stop a note's sound, though it's certainly frustrating to anyone who likes clear semantic categories.
_can you show me how to get the start time and the duration of a NoteEvent?_
@flagstone78 described this pretty well already. The crux of the matter is that you'll need to keep track of what tick you're at as you traverse the file, then, if you are interested in a particular note, save its initial tick (this is the start time*). Keep traversing until you hit another NoteOn or NoteOff event with the same pitch and channel as your first one, then subtract the start time from your current tick at this second event to get the duration. Note that I check for both ons and offs because of the issue above (stopping notes by giving them 0 velocity) and because one might consider a new NoteOnEvent as a semantically distinct note from the first, regardless of whether the note was off in between or not.
* though these are all assuming you want ticks. If you want seconds/etc, you'll have to convert; the main readme has some details.
EDIT: just discovered there is a Track.make_ticks_abs() that will convert tick values for you, though there is an open issue #20 so be careful to use it only once.
from python-midi.
Can someone explain how to get the tick and channel values? In Flagstone78's example above, I can complete the "pattern= midi.read_midifile("/path/to/file")" part just fine. I can create a for loop and extract the pitches using event.get_pitch(), but I can't figure out how to access the tick or channel values.
Thanks for you help!
from python-midi.
They can be accessed directly using event.tick
and event.channel
, rather than through a getter method.
(Note that not all event types will not have a channel though.)
from python-midi.
Related Issues (20)
- Marker
- Meta
- Handling Marker Events
- Appending an event with a tick less than the last one in absolute mode results in invalid tick
- package installation issue HOT 7
- MIDI Events
- make_ticks_rel is broken
- Python2 Errors HOT 1
- The 'midi==0.2.3' distribution was not found and is required by the application
- SetTempoEvent to 120 bpm doesn't seem to align with my metronome or in my music software
- Does python-midi still work?
- The loss of generator is always negative. HOT 1
- Can't install the package in anaconda HOT 4
- Is this repo still being maintained? HOT 1
- I made it available for Windows and Python 3 HOT 11
- pip3 package doesn't work HOT 2
- Installation issue HOT 7
- Do you have a python version HOT 1
- where can i find the ref doc
- Ubuntu Studio 23.10 - Mary.mid example fails HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-midi.