Author Topic: Metronome in BASSMidi  (Read 1197 times)

JJS

  • Posts: 115
Metronome in BASSMidi
« on: 16 Apr '09 - 01:47 »
I'd like to play metronome clicks as a MIDI file plays without modifying the MIDI file.  Is this possible?

Ian @ un4seen

  • Administrator
  • Posts: 21185
Re: Metronome in BASSMidi
« Reply #1 on: 16 Apr '09 - 15:02 »
If you have a spare MIDI channel that the file isn't using, what you could do is use that to play a note (the metronome tick) at regular intervals via BASS_MIDI_StreamEvent, with mixtime BASS_SYNC_MIDI_TICK syncs used to trigger that. The BASS_ATTRIB_MIDI_PPQN attribute will tell you how many ticks there are per beat, ie. you would set syncs at that interval to have the metronome tick every beat. The SYNCPROC could look something like this...

Code: [Select]
void CALLBACK MetronomeSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_MIDI_StreamEvent(channel, metronome_midi_channel, MIDI_EVENT_NOTE, MAKEWORD(60, 0)); // release old note
BASS_MIDI_StreamEvent(channel, metronome_midi_channel, MIDI_EVENT_NOTE, MAKEWORD(60, 100)); // press it again
BASS_ChannelSetSync(channel, BASS_SYNC_MIDI_TICK|BASS_SYNC_MIXTIME|BASS_SYNC_ONETIME, data+ppqn, MetronomeSyncProc, NULL); // set sync for next beat
}

...

// starting playback
BASS_MIDI_StreamEvent(midi, metronome_midi_channel, MIDI_EVENT_NOTE, MAKEWORD(60, 100)); // press note
BASS_ChannelSetSync(midi, BASS_SYNC_MIDI_TICK|BASS_SYNC_MIXTIME|BASS_SYNC_ONETIME, ppqn, MetronomeSyncProc, NULL); // set sync for next beat
BASS_ChannelPlay(midi, FALSE); // start playing

norbert

  • Posts: 132
Re: Metronome in BASSMidi
« Reply #2 on: 8 Jan '18 - 07:53 »
But will  the note be heard exactly at each beat time when using BASS_SYNC_MIXTIME  ?  I tried it and it was not too accurate (I played the "click" using a separate wav file channel). When omitting the BASS_SYNC_MIXTIME the sound is played with correct timing however it does not always work because if bpm is too high then the time for the next sync event is too short and will will not take place (buffer size...?).
So is it true that the only clean way of playing a metronome along to a midi file with exact timing is to put the file channel and the metronme channel into a bassmixer channel ?
« Last Edit: 8 Jan '18 - 07:57 by norbert »

Ian @ un4seen

  • Administrator
  • Posts: 21185
Re: Metronome in BASSMidi
« Reply #3 on: 8 Jan '18 - 17:25 »
The code posted above plays the metronome sound in the MIDI stream. Since that code was posted, the BASS_ATTRIB_MIDI_CHANS option was added to BASSMIDI, so there is now no need to "have a spare MIDI channel that the file isn't using" - you can add a channel for the metronome.

If you want to use a custom sound for the metronome, you could generate a simple SFZ file for it (in memory) and load that via BASS_MIDI_FontInitUser. The SFZ file could look something like this:

Code: [Select]
<region>
sample=c:\path\metronome.wav

norbert

  • Posts: 132
Re: Metronome in BASSMidi
« Reply #4 on: 8 Jan '18 - 17:55 »
Ok,  and if it is played  on the existing (non-decoding) midi file channel, the wav sound from the new sfz will be heard in the same moment when other midi events from the file are heard at the n*ppqn tick positions ?

Ian @ un4seen

  • Administrator
  • Posts: 21185
Re: Metronome in BASSMidi
« Reply #5 on: 9 Jan '18 - 13:54 »
Yes, so long as the sync has the BASS_SYNC_MIXTIME flag set (as in the code above), the metronome should be heard exactly at the specified tick.

norbert

  • Posts: 132
Re: Metronome in BASSMidi
« Reply #6 on: 9 Jan '18 - 15:59 »
I tried it and indeed the timing is perfect (tried it with a preset of the main sf2 soundfont!)

But can't get my sfz soundfont load correctly (on ANDROID!):
The whole file content is
Code: [Select]
<region>
sample=beatHi.wav

I placed the sfz file and the wav file into /storage/emulated/0/Soundfonts.

BASS_MIDI_FontInit returns 1, so it finds the soundfont. However the BASS_MIDI_FONTINFO shows 
presets=0, samsize=0. And when sending note ons there is no sound...


So it seems it cannot locate the wav file ( I also tried with absolute path to wav file) ? 

EDIT: solved:   it seems to be case sensitive: SoundFonts instead of Soundfonts.
« Last Edit: 9 Jan '18 - 16:42 by norbert »