Giter Club home page Giter Club logo

Comments (3)

tdhsmith avatar tdhsmith commented on September 24, 2024
  1. In this line: midi.NoteOnEvent(tick=720, channel=0, data=[62, 126]), what do the list elements in the data field represent?

They are pitch and velocity. (cf. NoteEvent source code)

Pitch uses the standard MIDI note numbers:

Image of piano keys, with the corresponding "MIDI number" of each key written alongside

Velocity is a measure from 0-127 of how hard the note was struck. If your MIDI track was generated from software or recorded from an instrument without velocity control, these values might all be the same.

 2. Why are there duplicate events? this event seems identical to this event
3. Why aren't the events sorted by tick?

(There's some previous discussion here.) By default tick values are relative, so they measure how many ticks have passed since the event before it. When you have things happening at the exact same time (like playing notes in a chord, or one note ending precisely as the next one begins) it will be listed as a series of events with tick=0.

Your events aren't duplicates, it's just two instances of a particular pitch occurring at the same time as something else.

As an alternative to the relative mode, you can convert a Pattern (or Track) to absolute tick values using Pattern.make_ticks_abs(). Since you're gonna be using a formula to compare outside data with MIDI ticks, that will probably be a lot easier.

 4. [...] Where should I look for the Tempo?

Tempo isn't set directly on the Pattern/Track, it's set through the SetTempoEvent. In your example they are all set in their own track at the top, which is fairly common IIRC.

SetTempoEvent data looks pretty goofy in the dumpout because it uses 3 bytes to store one value. So the first event has data=[12, 11, 226], which sets the tempo to (12 << 16) + (11 << 8) + 226 = 789474 microseconds per quarter note. Then the song stays at that speed for quite some time, until 49200 ticks later when it starts to slow down (presumably for the big finish). Every quarter note (240 ticks) from there on out it slows, until reaching a final speed of (24 << 16) + (23 << 8) + 195 = 1578947 μspqn, which is about half the original speed.

You don't have to deal with the weird unit of measurement, by the way. The library includes a converter to/from beats per minute. Just use TempoChangeEvent.bpm.

from python-midi.

tdhsmith avatar tdhsmith commented on September 24, 2024

I should add that the meaning of the data field is always going to depend on what kind of event it is. Them being pitch and velocity is exclusive to Note events.

It's really just a simple way to handle how MIDI files are loaded and saved, while still allowing properties of events to be modified easily.

from python-midi.

tleyden avatar tleyden commented on September 24, 2024

you can convert a Pattern (or Track) to absolute tick values using Pattern.make_ticks_abs(). Since you're gonna be using a formula to compare outside data with MIDI ticks, that will probably be a lot easier.

Great tip! Yes I'll definitely need this.

Everything makes a lot more sense now. Thanks for taking the time to write this up!

from python-midi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.