MIDI Programming with JAVA:Yamaha PSR Not playing MIDI file Properly

Started by chikitin, March 18, 2019, 11:10:26 PM

Previous topic - Next topic

chikitin

Hi Everyone,

I know here is not for technical questions specially programming. But I know here are some very intelligent folks who are musician and at the same time programmers.


I have a midi file which is recorded with Yamaha PSR-A3000 ( external midi synth) I have saved it on my computer and would like to play it back from my computer iMac with Mojave.  I wrote the Jave code below, It shows PSR MIDI device and the input port is the 4th one. however, I cannot get MIDI file played on my Yamaha PSR.

Quoteimport javax.sound.midi.MidiSystem; 
import javax.sound.midi.Sequence; 
import javax.sound.midi.Sequencer; 
import java.io.File; 
import javax.sound.midi.MidiDevice; 
import javax.sound.midi.MidiUnavailableException; 
import javax.sound.midi.Receiver; 
import uk.co.xfactorylibrarians.coremidi4j.CoreMidiDeviceProvider; 
 
public class psrMidiPlayer { 
 
   /**
  * Play a Midi file.
  */ 
   public static void playMidiFile(String fileName, int DEVICE_NUMBER) { 
   try { 
   for (Receiver receiver : MidiSystem.getSequencer().getReceivers()) { 
  receiver.close(); 
   } 
   System.out.println("Working MIDI Devices:"); 
   for (javax.sound.midi.MidiDevice.Info device : CoreMidiDeviceProvider.getMidiDeviceInfo()) { 
   System.out.println(" " + device +" "+ device.getVendor()); 
   } 
 
   MidiDevice.Info[] MidiDeviceInfos = MidiSystem.getMidiDeviceInfo(); 
   //find the suitable device number here, based on some criteria 
   MidiDevice MidiOutDevice = MidiSystem.getMidiDevice(MidiDeviceInfos[DEVICE_NUMBER]); 
 
 
   if (!(MidiOutDevice.isOpen())) { 
   try { 
   MidiOutDevice.open(); 
   } catch (MidiUnavailableException e) { 
  e.printStackTrace(); 
   } 
   } 
 
   Receiver MidiOutReceiver = MidiOutDevice.getReceiver(); 
   Sequencer MidiOutSequencer = MidiSystem.getSequencer(); 
 
 
   System.out.println( "getMaxReceivers() =" + MidiOutDevice.getMaxReceivers()); 
   System.out.println( "getMaxTransmitters() =" + MidiOutSequencer.getMaxTransmitters()); 
 
   //Add the new MIDI out device here. 
   File myMidiFile = new File(fileName); 
   MidiOutSequencer.getTransmitter().setReceiver(MidiOutReceiver); 
 
   MidiOutSequencer.open(); 
   Sequence mySeq = MidiSystem.getSequence(myMidiFile); 
   MidiOutSequencer.setSequence(mySeq); 
 
   MidiOutSequencer.start(); 
   //MidiOutSequencer.close(); 
   } catch (Exception ex) { 
  ex.printStackTrace(); 
   } 
   } 
 
   public static void main(String args[]) { 
   int i = 3; 
  playMidiFile("/pass2midifile/bahar-martik.mid", i); 
   } 


The external Synth is using standard Yamaha USB-MIDI driver and all I hear it playing is a single note E3 on piano and when I monitor the incoming midi messages they are all on channel one and E3.

23:21:11.613    To Port 1   Note On 1   E3 
127 23:21:11.613    To Port 1   Note On 1   E3 
127 23:21:11.613    To Port 1   Note On 1   E3 
127 23:21:11.613    To Port 1   Note On 1   E3
127 23:21:11.613    To Port 1   Note On 1   E3
...

At the same time my iMac speakers plays nonstop the song using "Gervill", if I am not mistaken.

Question1: How can I discard the default synth so it does not play at the same time with my External MIDI HW? This does not work?

for (Receiver receiver : MidiSystem.getSequencer().getReceivers()) { receiver.close(); }
Question 2: How can I have my code play all 16 channels? I assume I have unlimited receivers and tramistters on my receiver and sequencer:

getMaxReceivers() =-1 getMaxTransmitters() =-1
Question 3: Later on, I need to have my MIDI file to play on particular channel? How this is possible please?

Question 4: If the midi file is recorded on PSR External Synth, do I need to do any settings in advance on my external synth to make sure it plays same instruments and program changes?


Here are my devices listed:

Working MIDI Devices: CoreMIDI4J - IAC Driver    Apple Inc.
CoreMIDI4J - PSR-A3000 Port 1    Yamaha Corporation
CoreMIDI4J - IAC Driver    Apple Inc.
CoreMIDI4J - PSR-A3000 Port 1    Yamaha Corporation
CoreMIDI4J - PSR-A3000 Port 2    Yamaha Corporation
Gervill    OpenJDK Real Time Sequencer   


Any help would be greatly appreciated.

CS

valimaties

______________________________________________
Genos(1) v2.13, Korg PA5X, Allen & Heath SQ5
My youtube channel - https://www.youtube.com/channel/UCzi9PPrMTjN8_zX9P9kelxg

Vali Maties - Genos

chikitin

Hi Vali,

I tried the code in the stack overflow. On my end it does not play at all. My keyboard is PSR-A3000 and it connected via USB-MIDI to iMac Mojave. I guess the core midi driver of Apple is not working properly. I have also Yamaha USB MIDI driver installed, however, it is used by my other devices and not the PSR.


Any clue?

Thank you very much.

CS