Author: Tomas Rutkauskas
How can I control the MIDI speaker output volume? If that's not directly possible:
how can I programmatically open the volume control?
Answer:
First you need to ID the device
1 tmpreg := TRegistry.Create;
2 tmpreg.RootKey := HKEY_CURRENT_USER;
3 tmpreg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Multimedia\MIDIMap',
4 false);
5 6 7 { ... }8 if tmpreg.ValueExists('CurrentInstrument') then9 begin10 MidiOutPutDev := tmpreg.ReadString('CurrentInstrument');
11 end;
12 tmpreg.destroy;
13 { ... }14 15 then get a handle of the device
16 17 18 amt := MidiOutGetNumDevs;
19 MidiOutputDevid := -1;
20 for t := 1 to amt do21 begin22 MidiOutGetDevCaps(t - 1, @Midicap, Sizeof(Midicap));
23 if Strpas(@MidiCap.szPName) = MidiOutPutDev then24 begin25 MidiOutputDevid := t - 1;
26 end;
27 end;
28 29 30 //Then set the volume either master or seperate31 32 33 procedure SetVolumeMidi(RVolume, LVolume: Cardinal);
34 begin35 midiOutSetVolume(MidiOutputDevid, (RVolume * 256 * 256) + LVolume);
36 end;
37 38 procedure SetMVolumeWave(Volume: Cardinal);
39 var40 pl, pr: Cardinal;
41 begin42 pr := (WRPan * Volume) div 100;
43 pl := (WLPan * Volume) div 100;
44 waveOutSetVolume(WaveOutputDevid, (pr * 256 * 256) + pl);
45 end;
Include mmsystem in your Uses clause