Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating midi file #59

Open
jisike opened this issue Nov 25, 2017 · 7 comments
Open

creating midi file #59

jisike opened this issue Nov 25, 2017 · 7 comments

Comments

@jisike
Copy link

jisike commented Nov 25, 2017

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
Copy link
Owner

moinejf commented Nov 25, 2017

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

@jisike
Copy link
Author

jisike commented Nov 25, 2017

could you please give me more detail

@moinejf
Copy link
Owner

moinejf commented Nov 25, 2017

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
Copy link
Contributor

bwl21 commented Dec 4, 2017

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
Copy link
Owner

moinejf commented Dec 4, 2017

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:

  • toaudio gets the ABC music representation and generates the play event list
  • to audio5 gets the play event list and generates the music through the html5 audio interface
    The play event list is described in toaudio5.

This permits:

  • to replace toaudio5 by some other modules and generate music by some other mean (MIDI stream/file, csound file, ...)
  • to call toaudio5 and play music from some other format (MIDI file/device, lilypond/musicxml/pmw/cmn/guido/braillemusic/... music notations...)

Normally, the APIs should not change.

@bwl21
Copy link
Contributor

bwl21 commented Dec 4, 2017

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
Copy link
Owner

moinejf commented Dec 4, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants