Thank you for your quick update!
I have tested the new font load feature.
It loads up soundfont successfully, but sounds like crashed instruments.
I am also afraid if it is ok to allocate bytebuffer with huge size like 140MB.
We've used sampling chip which has 32MB capacity, but since we decided to use BASS MIDI and soundfont, we will make much better samplings.
The soundfont we've created is 25MB.
Below is the code for loading soundfont.
private boolean initFont(String file){
if(mSoundFont != 0)return true;
ByteBuffer bb = null;
try{
File tempFile = new File(file);
FileInputStream f = new FileInputStream( file );
FileChannel ch = f.getChannel( );
bb = ByteBuffer.allocate( (int)ch.size() );
int read = 0;
read = ch.read(bb);
System.out.println("==== read check : "+tempFile.length() + " , " + read);
}catch(Exception e){
System.out.println("========= exception on load font : " + e);
return false;
}
int newfont=BASSMIDI.BASS_MIDI_FontInit(bb, BASSMIDI.BASS_MIDI_FONT_MEM);
if (newfont==0) {
return false;
} else {
BASSMIDI.BASS_MIDI_FONT[] sf={new BASSMIDI.BASS_MIDI_FONT()};
sf[0].font=newfont;
sf[0].preset=-1; // use all presets
sf[0].bank=0; // use default bank(s)
BASSMIDI.BASS_MIDI_StreamSetFonts(0, sf, 1); // set default soundfont
BASSMIDI.BASS_MIDI_StreamSetFonts(mHandle, sf, 1); // set for current stream too
BASSMIDI.BASS_MIDI_FontFree(mSoundFont); // free old soundfont
mSoundFont=newfont;
return true;
}
}
I am curious if there is a way to protect custom soundfont.
ex.
1. encrypt a soundfont using MD5 and decrypt it when it is loaded.
2. custom soundfont has special header and check it on load.
I think that should be possible using the undocumented option of loading a soundfont from memory, ie. you could decrypt your soundfont to memory and then pass that to BASSMIDI. The BASSMIDI Java class didn't include support for that feature, but I have put an update up in the 1st post which should do. You would decrypt your soundfont to a ByteBuffer and then pass that to BASS_MIDI_FontInit along with the BASS_MIDI_FONT_MEM flag. Let me know if you have any trouble with it.
Thanks for the test soundfont. I'll check if BASSMIDI is currently doing anything wrong with it.