0

Following this Midi player and wanted to add a Custom Control (CC) to reduce Channel 0 and 1 volume to 10% using ShortMessage: http://www.jsresources.org/examples/MidiPlayer.html

I find it didn't reduce the volume right after the midi song start playing.

ShortMessage volMessage = new ShortMessage();
  for(int i=0;i<2;i++) {
    try{
      volMessage.setMessage(ShortMessage.CONTROL_CHANGE,i, 7, 10);
    } catch(InvalidMidiDataException e) {}
      midiReceiver.send(volMessage,-1); 
    }

Has anyone done using ShortMessage to control MIDI channels?

James ONG
  • 47
  • 1
  • 7
  • You've already asked this question, but in a more confusing way: http://stackoverflow.com/q/9092261/362536 Please delete your old question. – Brad Feb 02 '12 at 15:06

2 Answers2

1

You're attempting to end the message in the catch block - it should be immediately after the .setMessage() call in the try block!

Alnitak
  • 334,560
  • 70
  • 407
  • 495
0

MIDI CC 7 will only act as a volume control if the instrument conforms to the GM (General MIDI) standard. If you want to control the volume, you should do it in the mixer with the rendered audio output.

Also, if I'm not mistaken, the 2nd data byte is a value between 0-127, not 0-100. So if you want 10% volume, that would be a value of 12 or 13. ;)

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • actually in my experience most instruments recognise CC7 even if they're not GM compatible. I'm pretty sure the convention that CC7 is for volume predates the GM standard. – Alnitak Feb 02 '12 at 10:27
  • 1
    you're mostly right on the second point, except that perception of volume isn't really a linear scale anyway. – Alnitak Feb 02 '12 at 11:01
  • Yup, CC7 is volume for each channels which is looking at. I'm not sure why it won't work, could you try my code with the example? It work with another way (not using the example above) but I will need to use sleep function after the sequence is start, this will introduce race condition in some case and is a bad idea. – James ONG Feb 02 '12 at 11:28