Author Topic: Midi Volume (Not jPCT But Java)  (Read 13266 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Midi Volume (Not jPCT But Java)
« Reply #15 on: February 05, 2009, 11:41:23 pm »
Ok, I made the applet more more verbose, so I can hopefully track down if there is a specific setup that results in volume changes not working:

MIDI Applet

Those of you who have already posted information from the last applet, if you have a chance, could you please run the applet again and grab the output.  If you had tested the applet on multiple systems, could you please let me know which output went with which system (assuming output was different for each system)?  I am most interested in the last half of output, since the first part will probably be the same for everyone running a Microsoft OS (I would like to see what Windows 7 shows for MIDI devices, though).

If anyone else wants to help out who hasn't already, please run the applet and use the arrow keys to adjust the volume all the way to 0, then back up to 127.  Please post the output, and include your operating system and hardware and a brief description of the results.  Possible results are:
1) MIDI did not play.
2) MIDI played, but volume never changed.
3) Volume changed, but did not become silent at volume=0.
or
4) Everything worked correctly.

I also posted this on several forums so I can get a variety of hardware, operating systems, and browsers.  I will update you if I notice any patterns.

Thanks again!

Offline C3R14L.K1L4

  • int
  • **
  • Posts: 54
    • View Profile
    • CK's place of many works
Re: Midi Volume (Not jPCT But Java)
« Reply #16 on: February 06, 2009, 12:02:18 am »
Nice, you corrected the volume change ;) Now I don't have to press down/up 128 times ;D
Anyway, here's the debug from my 'regular' machine:

Code: [Select]
12 MIDI Devices:
    kX Control SB0244 10k2 [a000]
    kX Uart SB0244 10k2 [a000]
    kX Uart2 SB0244 10k2 [a000]
    Microsoft MIDI Mapper
    Microsoft GS Wavetable SW Synth
    kX Control SB0244 10k2 [a000]
    kX Synth SB0244 10k2 [a000]
    kX Synth2 SB0244 10k2 [a000]
    kX Uart SB0244 10k2 [a000]
    kX Uart2 SB0244 10k2 [a000]
    Real Time Sequencer
    Java Sound Synthesizer
Using 'Real Time Sequencer' as the Sequencer.
Variable 'sequencer' is NOT an instance of Synthesizer
Using 'Java Sound Synthesizer' as the Synthesizer.
Method 'getDefaultSoundbank()' did NOT return 'null'.

And from my laptop:

Code: [Select]
4 MIDI Devices:
    Microsoft MIDI Mapper
    Microsoft GS Wavetable SW Synth
    Real Time Sequencer
    Java Sound Synthesizer
Using 'Real Time Sequencer' as the Sequencer.
Variable 'sequencer' is NOT an instance of Synthesizer
Using 'Java Sound Synthesizer' as the Synthesizer.
Method 'getDefaultSoundbank()' did NOT return 'null'.

Edit: added jdk version:

Code: [Select]
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
« Last Edit: February 06, 2009, 02:47:31 am by C3R14L.K1L4 »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Midi Volume (Not jPCT But Java)
« Reply #17 on: February 06, 2009, 03:08:01 am »
I guess the volume does change on my laptop (now that the keyboard input was improved I can tell the difference). It's just a matter of how much, and the difference isn't huge on my computer.

4 MIDI Devices:
    Microsoft MIDI Mapper
    Microsoft GS Wavetable Synth
    Real Time Sequencer
    Java Sound Synthesizer
Using 'Real Time Sequencer' as the Sequencer.
Variable 'sequencer' is NOT an instance of Synthesizer
Using 'Java Sound Synthesizer' as the Synthesizer.
Method 'getDefaultSoundbank()' did NOT return 'null'.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Midi Volume (Not jPCT But Java)
« Reply #18 on: February 06, 2009, 03:55:38 am »
I have gotten a good number of responses on various forums, and I am beginning to see a distinct pattern.  In cases where getDefaultSoundbank() does not return null (i.e. software-synthesis mode) then volume does not become silent at zero.  In cases where getDefaultSoundbank() does return null (i.e. hardware-synthesis mode) then volume becomes silent at zero.  This theory is further supported by some test cases I've done here.  When I run the test as an application, they all report that getDefaultSoundbank() does not return null, and volume does not become silent at zero.  On my laptop running Vista, the applet also reports not null for getDefaultSoundbank(), and volume does not become silent at zero.  For all my other test machines, the applet reports that getDefaultSoundbank() does return null, and volume becomes silent at zero (the same machines where volume did not become silent at zero when running as an application).

Of course I will keep looking for exceptions to this theory as more reports come in (and I haven't had anyone report yet that volume didn't change for them at all), but I can make a deduction based on the current information:
When running in hardware-synthesis mode, volume changes work properly.  The code that runs in this case is:
Code: [Select]
                Receiver receiver = MidiSystem.getReceiver();
                ShortMessage volumeMessage= new ShortMessage();
                for( int c = 0; c < 16; c++ )
                {
                    volumeMessage.setMessage( ShortMessage.CONTROL_CHANGE, c,
                                              CHANGE_VOLUME, midiVolume );
                    receiver.send( volumeMessage, -1 );
                }

On the other hand, when running in software-synthesis mode, volume changes do not work properly.  The code that runs in this case is:
Code: [Select]
            javax.sound.midi.MidiChannel[] channels = synthesizer.getChannels();
            for( int c = 0; channels != null && c < channels.length; c++ )
            {
                channels[c].controlChange( CHANGE_VOLUME, midiVolume );
            }

It would appear that using the ShortMessages method works better for changing the volume than using the synthesizer channels method.  I've tried mixing and matching the two methods, but the volume does not change at all if using the wrong method with the wrong synthesis mode.  I've also tried using both modes at the same time for both methods, and that doesn't cause any problems, but it doesn't correct the software-synthesis mode volume problem either.  I'll keep looking into this, and post some questions on various forums.  If my theory is right, then at least we have a little bit better idea on where to focus.

Oh, and we also know that the problem of volume not changing at all is not common, and since your laptop is running Windows 7, we know it is probably not an issue Windows 7.
« Last Edit: February 06, 2009, 03:58:36 am by paulscode »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Midi Volume (Not jPCT But Java)
« Reply #19 on: February 06, 2009, 07:28:48 am »
To clarify, the volume change worked. The contrast between 0 and 127 may not have been huge, but it was noticeable (now that the keyboard input was improved). And thanks again for showing that.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Midi Volume (Not jPCT But Java)
« Reply #20 on: February 06, 2009, 11:25:30 pm »
I thought I would mention that I also tried this for software-synthesis mode:

Code: [Select]
                ShortMessage volumeMessage = new ShortMessage();
                for( int i = 0; i < 16; i++ )
                {
                    volumeMessage.setMessage( ShortMessage.CONTROL_CHANGE, i,
                                              CHANGE_VOLUME, midiVolume );
                    synthesizer.getReceiver().send( volumeMessage, -1 );
                }

This behaves exactly the same way as the synthesizer getChannels method (i.e. volume changes, but doesn't become silent at zero).

Doesn't really help much, but at least it's one more thing to cross off the list.  I haven't gotten any useful responses from the various forums I've posted on yet.