GithubHelp home page GithubHelp logo

Saving midi files as type 0? about midilib HOT 6 CLOSED

jimm avatar jimm commented on July 19, 2024
Saving midi files as type 0?

from midilib.

Comments (6)

jimm avatar jimm commented on July 19, 2024

It's certainly possible. A few different approaches are possible. You'd probably want to reuse the low-level methods in MIDI::IO::SeqWriter such as write_var_len and write16 but override/replace functions like write_to, write_header, and write_track.

To keep the public interface the same, you might want to add an optional argument to SeqWriter#initialize for the MIDI file format that defaults to 1 but can accept 0 as well. In that case you would probably end up rewriting write_to so that it calls something like write_format_0 or write_format_1 depending on the requested format.

The trick bit would be merging all of the tracks' events into one list of properly time-ordered events first so that you can write that out. Actually, it's not that tricky --- Track already has the merge function so you could create a new temporary track and merge all of the events from those tracks into that one so you can write it out.

I'm not sure what other differences there are in a MIDI file format 0, so I have probably missed something.

Does tha tall make sense?

from midilib.

rhelsing avatar rhelsing commented on July 19, 2024

@jimm Yes this does make sense. Thanks for taking the time to write that up.

from midilib.

jimm avatar jimm commented on July 19, 2024

As a side note, I just realized that reading a type 0 file is already supported! A type 0 file is just a type 1 file with a format byte of 0 and a track count of 1.

from midilib.

rhelsing avatar rhelsing commented on July 19, 2024

@jimm thats great! so if the tracks are merged, and writing with a format byte of 0, that should solve it correct?

from midilib.

jimm avatar jimm commented on July 19, 2024

Yes, I think that's it.

from midilib.

jimm avatar jimm commented on July 19, 2024

@rhelsing implemented this feature in #17 which has been merged.

from midilib.

Related Issues (17)

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.