Question

I tell them that I'm working with a MIDlet and I can not able to change any instrument midi channel. I tried with .shortMidiEvent(0xC0 + channel, program, 0); and setProgram(channel, -1, program) without result. on my phone is a Nokia X3-02 instrument change does not work, only midlet's emulators. here is the code fragment

public final class Dmgcpu implements Runnable {
private Player player;
private static MIDIControl synth;

private void initSound() {
    try {

        player = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
        player.prefetch();
        synth = (MIDIControl) player.getControl("javax.microedition.media.control.MIDIControl");
    } catch (Exception ex) {
    }

    synth.setProgram(0, -1, instSound_a);
    //synth.shortMidiEvent(0xC0, instSound_a, 0);

   //sound test
   synth.shortMidiEvent(0x90 + channel, note[i], volume * MASTER_VOLUME);

   thread_sleep(300);

   synth.shortMidiEvent(0x80 + channel, note[i], 0);

}

is that you can change the instrument, as I have understood you use an array of player in cases like these. I try and not worked. saludos

Was it helpful?

Solution

The media player is always tricky with JavaME. Some devices requires you to prefetch() while others will crash if you do. Some likes realize() while others don't. So it's best to use multiple try/catch blocks with prefetch() and realize() etc. It's possible that your try block fails because of prefetch(). So try this:

public final class Dmgcpu implements Runnable {
private Player player = null;
private static MIDIControl synth = null;

private void initSound() {
  try {
    player = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
  } catch (Exception e) {}
  try {
    player.realize();
  } catch (Exception e) {}
  try {
    player.prefetch();
  } catch (Exception e) {}
  try {
    synth = (MIDIControl) player.getControl("javax.microedition.media.control.MIDIControl");
  } catch (Exception ex) {}

    if (synth!=null) {
    synth.setProgram(0, -1, instSound_a);

    //synth.shortMidiEvent(0xC0, instSound_a, 0);

    //sound test
    synth.shortMidiEvent(0x90 + channel, note[i], volume * MASTER_VOLUME);

    thread_sleep(300);

    synth.shortMidiEvent(0x80 + channel, note[i], 0);
  }
}

More info about media-player: http://indiegamemusic.com/help.php?id=1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top