Author Topic: Mute channel midi on decodifica  (Read 295 times)

Salvo

  • Posts: 132
Mute channel midi on decodifica
« on: 21 Sep '23 - 13:26 »
Hi Ian, but I've been searching to no avail and can't figure out where the error is.
I have to mute a midi channel for example channel 4 on the conversion from midi to mp3.
I wrote this code but it doesn't work.

procedure OnMidiNote(handle: HSYNC; channel, data, user: DWORD ); stdcall;
var MidiChannel:Word;
vel,note:Byte;
begin
  MidiChannel := HIWord(data);
  note:=LOBYTE(Data);
  Vel:=HIBYTE(word(Data));
  if MidiChannel=3 then ////// channel 4
     BASS_MIDI_StreamEvent(channel, MidiChannel, MIDI_EVENT_NOTE,  note);
end;

procedure convert;
begin
       ChanSF2 := BASS_MIDI_StreamCreateFile(False, PChar(Song), 0, 0, BASS_STREAM_DECODE or BASS_UNICODE or BASS_MIDI_DECAYEND,48000);
       BASS_MIDI_StreamSetFonts(ChanSF2, PBASS_MIDI_FONTEX(@fSoundfontMp3), 2 or BASS_MIDI_FONT_EX);
       BASS_ChannelSetSync(ChanSF2, BASS_SYNC_MIDI_EVENT, MIDI_EVENT_NOTE, @OnMidiNote, nil);
       handle_1 := BASS_Encode_Start(ChanSF2, PChar('lame.exe -b 128  - tempxx.mp3'), BASS_UNICODE or BASS_ENCODE_AUTOFREE, nil, nil);

       t := Bass_ChannelGetLength(ChanSF2, BASS_POS_BYTE);
      //dwGet := 0;
      ProgressBar1.Value := 0;
      dwSamples :=48000;
      BufMp3 := AllocMem(dwSamples * sizeof(Integer));


      while BASS_ChannelIsActive(ChanSF2) > 0 do
      begin
        c := BASS_ChannelGetPosition(ChanSF2, BASS_POS_BYTE); { current position }
        BASS_ChannelGetData(ChanSF2, BufMp3, dwSamples * sizeof(Integer));
        if t > 0 then
        begin
          ProgressBar1.Value := round((c * 100) / t);
          ProgressBar1.Repaint;
        end;

      end;

........ other code

the OnMidiNote procedure is called correctly but on the mp3 file channel 4 is played and not muted.
Why ?
Thank for help.



Salvo

  • Posts: 132
Re: Mute channel midi on decodifica
« Reply #1 on: 21 Sep '23 - 13:53 »
Fixed with speed at 255.
BASS_MIDI_StreamEvent(channel, MidiChannel, MIDI_EVENT_NOTE,  makeword (note, 255));
 :)

Salvo

  • Posts: 132
Re: Mute channel midi on decodifica
« Reply #2 on: 21 Sep '23 - 14:13 »
Last problem if I want to lower the volume of a channel as I do
I tried this to halve the volume to 50% but it doesn't work:

  if MidiChannel=3 then
    BASS_MIDI_StreamEvent(channel, MidiChannel, MIDI_EVENT_NOTE,  makeword (note, trunc(vel / 2)));

Ian @ un4seen

  • Administrator
  • Posts: 25595
Re: Mute channel midi on decodifica
« Reply #3 on: 21 Sep '23 - 15:19 »
Instead of overriding note-on events, a simpler way to control the level of MIDI channels is to use the MIDI_EVENT_MIXLEVEL event. For example, to mute channel 4, you can just do this:

Code: [Select]
BASS_MIDI_StreamEvent(handle, 3, MIDI_EVENT_MIXLEVEL, 0);

Salvo

  • Posts: 132
Re: Mute channel midi on decodifica
« Reply #4 on: 22 Sep '23 - 19:29 »
Ok, one last thing can you do the midi to mp3 conversion as for midi sf2 also on the VSTi channel?

Ian @ un4seen

  • Administrator
  • Posts: 25595
Re: Mute channel midi on decodifica
« Reply #5 on: 27 Sep '23 - 12:34 »
Do you want to mute channels in a VSTi? I'm not sure if VSTi has an equivalent to BASSMIDI's MIDI_EVENT_MIXLEVEL option. If it doesn't then you could instead set MIDI_EVENT_VOLUME (CC7) to 0 via BASS_VST_ProcessEvent. If you also want to be able to unmute then you will also need to retain the channel's latest CC7 value for that.

If you happen to want to mute a VSTi entirely then you can do that via its BASS_ATTRIB_VOL setting.