moinejf / abc2svg

project moved to https://chiselapp.com/user/moinejf/repository/abc2svg
GNU Lesser General Public License v3.0
48 stars 6 forks source link

creating midi file #59

Open jisike opened 6 years ago

jisike commented 6 years ago

abc2svg is the only lib that can render and playback the my multi-part abc file. is there anyway i can create a midi/hack something similar using your lib?

moinejf commented 6 years ago

I split the audio generation into small tools. For MIDI generation, just replace util/toaudio5.js by MIDI file creation.

jisike commented 6 years ago

could you please give me more detail

moinejf commented 6 years ago

I think the interface in util/toaudio5.js is clear enough. You get this source, remove the code of the functions, and convert the play events to a binary MIDI stream. Then, you concatenate util/play.js, util/toaudio.js and your code, and you load the resulting file at the place of play-1.js.

bwl21 commented 6 years ago

I am also pulling the play events from the player in the callback get_abcmodel.

      abcplay.add(tsfirst, voice_tb)
      player_model = abcplay.clear()

where abcplay is an instance of AbcPlay.

This approach has problems for me:

  1. in order to get the player events (player_model), I need an instance of AbcPlay, even if i do not really want to play.
  2. to get an instance of AbcPlay, i need an Audio context which is not available in node.
  3. I cannot create an AbcPlay on the fly since every instance reserves an Audio context which I could not release. So I cannot do it more than six times.
  4. I have two components ABC2SVG and HarpnotePlayer (which plays the events). Now I had to pass the instance of AbcPlay from HarpnotePlayer to ABC2SVG which was pretty complicated.

Long story short:

Would it be possible to factor out the creation of the player events from AbcPlay to either another module (e.g. AbcPlayerEvents like AbcJSON) or to AbcMIDI respectively Abc (where parsing and get_abcmodel is done)

This would simplify the subsequent creation of a midi-file.


update: is it correct that such a module already exists "ToAudio"

I changed the code to the following, and it works.

          var to_audio = new ToAudio()
          to_audio.add(tsfirst, voice_tb)
          player_model = to_audio.clear()

Am I misusing ToAudio with this approach as it is not an official api?

moinejf commented 6 years ago

As told previously, the play function has been split into toaudio (play event generation) and toaudio5 (html5 audio playing engine). The file play.js is just a wrapper around these two modules. The API is simple enough:

This permits:

Normally, the APIs should not change.

bwl21 commented 6 years ago

I take this as a confirmation the the approach of using ToAudio to get the player events is ok. You mentioned that you want to change the player events from an array to a float32 array.

moinejf commented 6 years ago

All values in the play event array are numbers. Generating a standard array or a float32array does not change its usage.