grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
557 stars 60 forks source link

How to set/calculate Tempo value? #12

Closed shivrajsa closed 8 years ago

shivrajsa commented 8 years ago

I checked basic demos with MIDI.js & it works well. I played with example "chopin-prelude-e-minor", & tried to play this melody with different tempo, but it always play with same tempo, for example tracks[0].setTempo(x); x=120 or 240 or 480.

Am I missing some information about usage of tempo? please guide

lplume commented 8 years ago

setTempo parameters has been changed recently; it depends if you install/download MidiWriterJS after or before the change. Checkout #11 Feel free to ask more, or provide some sample code to debug

shivrajsa commented 8 years ago

I downloaded it today, so I think it is latest one. Here is my scenario

  1. Integrate (install) midi-writer-js.js file in MIDIPlayer example
  2. Change line "player.loadFile(song[songid++ % song.length], player.start);" to "player.loadFile(userFunctionDataUri(), player.start);", here "userFunctionDataUri()" is a user function returning MIDI String of melody created by MidiWriterJS function "dataUri()"
  3. Try different tempo parameter Result : It plays with same tempo even after different tempo inputs
grimmdude commented 8 years ago

Hi @shivrajsa,

This could be an issue with MIDI.js. Have you tried testing it in another MIDI player?

-Garrett

shivrajsa commented 8 years ago

Could you please suggest a good & stable MIDI player, I will try. It should take DataUri() output as input as per scenario.

grimmdude commented 8 years ago

When I'm working on this library this I typically use GarageBand for MIDI playback since it has good visualization of notes and meta events. For online playback I've had some trouble finding a bug free MIDI player (and actually considered writing one of my own). I did find, however, this one to work pretty well:

https://github.com/chenx/MidiPlayer

It's the same one I'm using on the example page for this repo. You'll have to check to see if it accepts Uint8 array as an input, I know it takes a dataURI though.

-G

lplume commented 8 years ago

Hi @shivrajsa, for my midi test and work i usually rely on MuseScore. You said you started from the chopin example (btw @grimmdude examples should be updated to new setTempo parameters) is it right? Just want to understand if there is some ¨bug¨ in MidiWriterJS or not.

Also @shivrajsa i took some time to introduce myself about indian music and let me say it´s very awesome (well.. actually VERY awesome.... considering i come from western music studies); now I understand your request about giving note times in seconds. I thought of few ways to do so with MidiWriterJS, but it´s still a forced way to do things... Do you know of any software specific to work with indian music (MIDI related)?

@grimmdude I used to compare MIDI files generated from this library and the same partiture composed in other software with hex editors; it´s a good meter of comparsion.

Thanks to both =)

-M

shivrajsa commented 8 years ago

Hi @lplume, In my app there is an option to export melody as MIDI file, you can check this option above each melody (table) at this link. Instead of "Devnagari" you can select option "Western" to see notations of melody in western format.

Just drag drop exported MIDI file at this link, an app mentioned as 'Color Piano' in MIDI.js demos. It works well even in Windows Media Player.

I generate MIDI using library jsmidi where it is possible to manipulate delay in seconds.

Some month back I tried to generate string using jsmidi & given it as input to MIDI.js player & it did not work well.

You can check MIDI generated using my app for further analysis.

Also here is one more app to check http://ragapedia.com/, I did not try it but there is option to export MIDI file.

lplume commented 8 years ago

Hi @shivrajsa,

I took some time to try midi generated by this library with both MuseScore and color piano you mentioned and everything is fine (setting diffrents tempo).

I also try to take a look to an exported of yours at vishwamohini music notation and cannot find the midi meta event to set tempo (FF 51), so I think the player try a guess.

lplume commented 8 years ago

Edit: and I think the guess is based on the delta time for each events and the total songs duration. I'm still searching on the topic MIDI-Indian like music. I'm gonna ask to some music schools and alike, you could try to do the same in the meantime

-M

grimmdude commented 8 years ago

I believe if the tempo event doesn't exist then MIDI players will default to 120 bpm.

-Garrett

lplume commented 8 years ago

this could be closed in favor of #13

shivrajsa commented 8 years ago

Hi @lplume @grimmdude, as said by @grimmdude it could be issue of MIDI.js, could you please also check this issue with MIDI.js because exported MIDI works well with MIDI.js player but datauri does not work well with MIDI.js player.

Using MIDI.js to play MIDI files generated by this library will be very useful because we can use soundfont in MIDI.js, take a look at my app where I am playing Tabla (Indian classical percussion instrument) using this library. Also we can easily set animations

grimmdude commented 8 years ago

Hi @shivrajsa ,

Could you download a fresh copy of this library and see if you still have the same issues with MIDI.js? Just put in a small fix on the tempo setup.

-Garrett