Author Topic: BASSMIDI won't play sound  (Read 161 times)

Linhares

  • Posts: 3
BASSMIDI won't play sound
« on: 7 Sep '22 - 18:09 »
I'm a new user and I'm trying to play MIDI sound with BASSMIDI.
However, I don't get any sound at all.
Here's my code. I get true from all the cout's. Am I missing something?

Code: [Select]
#include <iostream>
#include "bassmidi.h"

using namespace std;

int main()
{
    cout << BASS_Init(
                -1,
                44100,
                0,
                0,
                NULL
                ) << endl;

    HSTREAM my_stream = BASS_MIDI_StreamCreate(
                1,
                0,
                0);

    HSOUNDFONT my_soundfont = BASS_MIDI_FontInit(
                ".\\debug\\FluidR3_GM_GS.sf2",
                0
                );

    cout << my_soundfont << endl;

    BASS_MIDI_FONT *my_midifont = new BASS_MIDI_FONT;
    my_midifont->font = my_soundfont;

    cout << BASS_MIDI_StreamSetFonts(my_stream, my_midifont, 1) << endl;

    cout << BASS_MIDI_StreamEvent(my_stream, 0, MIDI_EVENT_PROGRAM, 20) << endl;
    cout << BASS_MIDI_StreamEvent(my_stream, 0, MIDI_EVENT_NOTE, MAKEWORD(60, 100)) << endl;

    //cout << BASS_ErrorGetCode();

    return 0;
}


Ian @ un4seen

  • Administrator
  • Posts: 24692
Re: BASSMIDI won't play sound
« Reply #1 on: 8 Sep '22 - 12:44 »
I see a few little issues to fix there.

1) You need to set the rest of the BASS_MIDI_FONT members for the BASS_MIDI_StreamSetFonts call. For example:

Code: [Select]
    my_midifont->font = my_soundfont;
    my_midifont->preset = -1;
    my_midifont->bank = 0;

2) You need to call BASS_ChannelPlay on the MIDI stream (my_stream) to start it, eg. after the BASS_MIDI_StreamSetFonts call.

3) The process is currently exiting immediately. Try adding a "cin.get()" call to make it wait.

Linhares

  • Posts: 3
Re: BASSMIDI won't play sound
« Reply #2 on: 8 Sep '22 - 21:37 »
Thanks, Ian.
It works perfectly now!