Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 78

Thread: midi bytes

  1. #41
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default Oracle of Delphi

    Last night, in my dreams, an angel appeared. He or she (I couldn´t figure out the gender) spoke to me saying: take a flight to Greece and go to Delphi. At the Oracle you´ll find an answer. The Oracle spoke (of course) in code to me. Once back home I fed the code to my computer:

    Java Code:
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        System.out.println (" info lenght " + infos.length);
        System.out.println (" info all " + infos);
        for (int i = 0; i < infos.length; i++)  {
            MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
            System.out.println (" info device " + i + " name "+ device);
                if (device.getMaxReceivers() > 0)  {
                    outDevices.add(device);
                    System.out.println (" info out " + i + " name " + infos[i].getDescription());
                }
                if (device.getMaxTransmitters() > 0)  {
                    inDevices.add(device);
                }   System.out.println (" info in " + i + " name " + infos[i].getDescription());
        }
    What is its deeper meaning?
    (those who understand please speak, those who don´t be silence)

    info lenght 2
    info all [Ljavax.sound.midi.MidiDevice$Info;@2d263f
    info device 0 name com.sun.media.sound.MixerSynth@34a7d8
    info in 0 name Software wavetable synthesizer and receiver
    info device 1 name com.sun.media.sound.MixerSequencer@c88440
    info in 1 name Software sequencer / synthesizer module

  2. #42
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default code warriors heed the call to glory

    Quote Originally Posted by willemjav View Post
    What is its deeper meaning?
    That is telling you what midi devices are available on your computer.
    Quote Originally Posted by willemjav View Post
    Java Code:
    info all [Ljavax.sound.midi.MidiDevice$Info;@2d263f
    Java Code:
     
     info device 0 name com.sun.media.sound.MixerSynth@34a7d8
     info in 0 name Software wavetable synthesizer and receiver
     info device 1 name com.sun.media.sound.MixerSequencer@c88440
     info in 1 name Software sequencer / synthesizer module
    I do not have the skills to read that code, it looks like info on the devices available. Code you showed should come up with something such as we see here.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #43
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    why is there no info out?

  4. #44
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    I asked the comp
    System.out.println (" midi out what's there " + device.getMaxTransmitters());
    the answer is -1
    how come?

  5. #45
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    So I can not transmit midi out? Is that what it means?

  6. #46
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    Nick, we still are heading in the wrong direction. The computer should send out midi, only midi and NOT audio. The second (fbo1) device will take care of the audio (if the midi codes are lined up correctly). So please forget about buffers, speed issues, files, synchronization and audio: because the synthesizer will take care of that all! The computer should relax it “just” midi to take care of.

  7. #47
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    The api says

    Returns:
    maximum number of MIDI OUT connections, or -1 if an unlimited number of connections is available.

    what do I do with an "unlimited number of connections"?
    How do I choose from eternity?

  8. #48
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    further exploring eternity I found

    Available MIDI Devices:
    0 IN OUT Java Sound Synthesizer, Sun Microsystems, Version 1.0, Software wavetable synthesizer and receiver
    1 IN OUT Java Sound Sequencer, Sun Microsystems, Version 1.0, Software sequencer / synthesizer module
    BUILD SUCCESSFUL (total time: 5 seconds)

    My Delta midi audio card doe not get listed here.
    Does that mean that I need some kind of connection from sun to delta?

  9. #49
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default long post thread okay with me

    This is why we are in a weak point by having lost a systems programmer. This is still not the shock I warned you about but it is the roll cloud on the horizon, I will simplifiy: The drivers you found may be able to run midi
    what do I do with an "unlimited number of connections"?
    Find a bridge between Java and the physical sound card. There is one or two drivers that comes with Java Sound API that are supposed to be able to run a sound card. They are limited to 8-khz, I do not know what the packet size is. If your sound card will not run off of it that is an issue with the device vendor and system details. Sometimes, all too often the arena is remarkable for it's lack of engineering expertise. Sometimes they work.
    How do I choose from eternity?
    Well it's easy, I do it all the time. See paragraph above. I wll be working on Servets today, buried....
    Nick, we still are heading in the wrong direction. The computer should send out midi, only midi and NOT audio. The second (fbo1) device will take care of the audio (if the midi codes are lined up correctly). So please forget about buffers, speed issues, files, synchronization and audio: because the synthesizer will take care of that all! The computer should relax it “just” midi to take care of.
    No, this is where we need to be going. What you need to do, based on the problem assesment you provide is find a pre-packaged solution. I can and will help look if I have the time. Do not stop at twenty candidate packages. Unless you are prepared to dig throught a 37 pound bench manual, you will be using a pre-packaged solution.
    So I can not transmit midi out? Is that what it means?
    As given above.

    We are going nowhere without studying some code, devote several hours to exploring:
    Java Code:
    import javax.sound.midi.MidiFileFormat;
    import javax.sound.midi.Sequence;
    import javax.sound.midi.InvalidMidiDataException;
    My Delta midi audio card doe not get listed here.
    We both have some reading to do. I will be busy but try to get to it.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  10. #50
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default getting there?

    I´v got hold of some listed midi devices grabbed in midinfo. I believe by putting some legal index I reach a output device.... looking for the next step



    Java Code:
    public static void midin (int index)   {
                m_in=null; 
                
            try {
                device = MidiSystem.getMidiDevice(midinfo[index]); 
            } catch (MidiUnavailableException ex) {
                ex.printStackTrace();
            }
            
            try {
                m_in = device.getReceiver();
            } catch (MidiUnavailableException ex) {
                ex.printStackTrace();
            }
                if (m_in == null)
                System.out.println (device + ".getReceiver() == null");
                System.out.println("the input device is " + device);
            }
            
            
            
            public static void midiout (int index)   {
                
                m_out=null;
            try {
                device = MidiSystem.getMidiDevice(midinfo[index]); 
            } catch (MidiUnavailableException ex) {
                ex.printStackTrace();
            }
            
            try {
                m_out = device.getTransmitter();
            } catch (MidiUnavailableException ex) {
                ex.printStackTrace();
            }
                if (m_out == null)
                System.out.println (device + ".getTransmitter() == null");
                System.out.println("the output device is " + device);
            }

  11. #51
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    have to find a way to push some midi stuff out

  12. #52
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default Midi Dot Org

    Quote Originally Posted by willemjav View Post
    have to find a way to push some midi stuff out
    Your belief is just that, a belief and nothing more.

    Your first point of reference should be the MIDI Manufacturer's Web-site, MIDI Manufacturers Association

    The bridge between a Sound Card and Java has several tiers, any of which may contain ( easily ) ten thousand lines of code. By digging in the cited website, you should be able to find something with which you can push some sound out the midi port. This is gonna be laughs some of the Masters here, Mac user, sitting under a tree in Europe ~ gonna push some midi out the sound port by banging on the keyboard.

    Nobody rip any rails here, ok?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  13. #53
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    I am making some progress, but how to take the next obstacle
    Exception in thread "main" java.lang.IllegalArgumentException: Requested device not installed: Delta-AP MIDI - Delta-AP MIDI
    at javax.sound.midi.MidiSystem.getGenericDevice(MidiS ystem.java:1046)
    at javax.sound.midi.MidiSystem.getMidiDevice(MidiSyst em.java:96)

  14. #54
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Post That is telling you "Delta-AP Midi" is not installed.

    Java Code:
    package midi;
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.MidiDevice.Info;
    
    public class LitteBeanTestSuite
    {
        public static void main(String[] args)
        {
            // Remember, don't pick scorpions up by their tail!
            Info[] zyglDorfer = MidiSystem.getMidiDeviceInfo() ;//
            if(zyglDorfer != null)
            {
                int index = zyglDorfer.length;//
                if(index > 0x0000)
                {
                    do
                    {
                        Info informatic = zyglDorfer[--index];
                        System.out.println(informatic.getDescription());
                        System.out.println(informatic.getName());
                        System.out.println(informatic.getVendor());
                        System.out.println(informatic.getVersion());
                    }
                    while(index > 0x0000);
                }
            }
        }
    }
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  15. #55
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default almost there?

    Okay installed the correct drivers and found a plugin, pushing midi out over the delta card to the yamaha fbo1: Amazing it all works!
    Found the following code of Nils Peters. Next, fase is understanding the code and find the midi out to midi port:


    Java Code:
    package miditry;
    
    
    
    /**
     *
     *
     */
    //
    //  Simple mmj demo
    //
    //  Created by Nils Peters on 1/13/07.
    //  Copyright (c) 2007 __humatic__. All rights reserved.
    //
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.File;
    
    
    import de.humatic.mmj.*;
    import javax.sound.midi.*;
    import java.util.Vector;
    
    public class miditest implements MidiListener, MidiSystemListener {
    	
    	private JComboBox ib,
    					  ob;
    					  
    	private String[] hexChars = new String[]{"0","1", "2", "3", "4", "5","6","7","8","9","A", "B","C","D","E","F"};
    
    	MidiInput mi;
    	MidiOutput mo;
    	MidiDevice myInPort, myOutPort;
    	
    	
    	JFrame frame;
    	private JCheckBox mouseOverCB = new JCheckBox();
    	
    	private Receiver receiver;
    	
    	private boolean java = true,
    					outputEnabled,
    					hex = true;
    					
    	private int ch = 0,
    				ctrl = 7;
       
    	javax.sound.midi.MidiDevice.Info[] ins;
    	javax.sound.midi.MidiDevice.Info[] outs;
    			
    			
        public miditest() {
            
    		frame = new JFrame("mmj");
    		
    		Object[] options = { "javax.sound.midi", "mmj" };
    
    		int result = JOptionPane.showOptionDialog(null, "Use javax.sound.midi.spi or mmj api?", "Select demo mode!",
    								 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    								 null, options, options[1]);
    		
    		java = result == 0;
    		
    		buildMMJDemo();
    			
    		frame.pack();
    		
    		frame.setLocation((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2-frame.getWidth()/2), 40);
    	
    		frame.setVisible(true);
    			
    			
    	}
    	
    	private void buildMMJDemo() {
    		
    		
    		if (!java){ 
    		
    			de.humatic.mmj.MidiSystem.initMidiSystem("mmj src", "mmj dest");
    		
    			de.humatic.mmj.MidiSystem.addSystemListener(this);
    		
    		} else {
    		
    			javax.sound.midi.MidiDevice.Info[] dev = javax.sound.midi.MidiSystem.getMidiDeviceInfo();
    			int numIns = 0;
    			int numOuts = 0;
    			for (int i = 0; i < dev.length; i++) {
    				try{
    					if (javax.sound.midi.MidiSystem.getMidiDevice(dev[i]).getMaxTransmitters() != 0) numIns++;
    					if (javax.sound.midi.MidiSystem.getMidiDevice(dev[i]).getMaxReceivers() != 0) numOuts++;
    				} catch (javax.sound.midi.MidiUnavailableException me){}
    			}
    			
    			ins = new javax.sound.midi.MidiDevice.Info[numIns];
    			outs = new javax.sound.midi.MidiDevice.Info[numOuts];
    			numIns = 0;
    			numOuts = 0;
    			for (int i = 0; i < dev.length; i++) {
    				try{
    					if (javax.sound.midi.MidiSystem.getMidiDevice(dev[i]).getMaxTransmitters() != 0) ins[numIns++] = javax.sound.midi.MidiSystem.getMidiDeviceInfo()[i];
    					if (javax.sound.midi.MidiSystem.getMidiDevice(dev[i]).getMaxReceivers() != 0) outs[numOuts++] = javax.sound.midi.MidiSystem.getMidiDeviceInfo()[i];
    				} catch (javax.sound.midi.MidiUnavailableException me){}
    			}
    			
    		}
    		
    		frame.getContentPane().setLayout(new BorderLayout());
    		JPanel upper = new JPanel(new BorderLayout());
    		upper.setPreferredSize(new Dimension(400, 90));
    		JPanel upper1 = new JPanel();
    		JPanel upper2 = new JPanel();
    
    		
    		if (!java) ib = new JComboBox(de.humatic.mmj.MidiSystem.getInputs());
    		else ib =  new JComboBox(ins);
    		ib.addItem("input");
    		ib.setSelectedIndex(ib.getItemCount()-1);
    		ib.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e) {
    				if (ib.getSelectedIndex() >= ib.getItemCount()-1) return;
    				if (!java) {
    					if (mi != null) {
    						mi.close();
    						mi = null;
    					}
    					mi = openInput(ib.getSelectedIndex());
    					System.out.println(mi.getDeviceInfo());
    				} else {
    					try{
    						if (myInPort != null) {
    							myInPort.close();
    							myInPort = null;
    						}
    						System.out.println("opening "+ins[ib.getSelectedIndex()]);
    						myInPort = javax.sound.midi.MidiSystem.getMidiDevice(ins[ib.getSelectedIndex()]);
    						myInPort.open();
    						Transmitter t = myInPort.getTransmitter();
    						t.setReceiver(new MidiIn(ins[ib.getSelectedIndex()].toString()));
    					}catch (MidiUnavailableException mue){
    						System.out.println("can't open MidiIn : " +mue.toString());
    					}
    				}
    					
    			}
    		});
    		
    		upper1.add(ib);
    		
    		final JButton send = new JButton("send sysEx");
    		send.setEnabled(false);
    		
    		if (!java) ob = new JComboBox(de.humatic.mmj.MidiSystem.getOutputs());
    		else ob =  new JComboBox(outs);
    		
    
    		ob.addItem("output");
    		ob.setSelectedIndex(ob.getItemCount()-1);
    		ob.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e) {
    				if (ob.getSelectedIndex() >= ob.getItemCount()-1) return;
    				
    				if (!java) {
    					if (mo != null) {
    						mo.close();
    						mo = null;
    					}
    					mo = openOutput(ob.getSelectedIndex());
    					System.out.println(mo.getDeviceInfo());	
    				} else {
    					try{
    						if (myOutPort != null) {
    							myOutPort.close();
    							myOutPort = null;
    						}
    						System.out.println("opening "+outs[ob.getSelectedIndex()]);
    						myOutPort = javax.sound.midi.MidiSystem.getMidiDevice(outs[ob.getSelectedIndex()]);
    						myOutPort.open();
    						receiver = myOutPort.getReceiver();
    						send.setEnabled(true);
    						outputEnabled = true;
    					}catch (MidiUnavailableException mue){
    						System.out.println("can't open MidiOut : " +mue.toString());
    					}
    				}
    
    				send.setEnabled(true);
    				outputEnabled = true;
    			}
    		});
    
    		upper1.add(ob);
    		
    		send.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e) {
    				try{
    					
    					
    					FileDialog fd = new FileDialog(new Frame(), "Select sysEx file", FileDialog.LOAD);
    					fd.setVisible(true);
    					File f = new File(fd.getDirectory()+fd.getFile());
    					java.io.FileInputStream fis = new java.io.FileInputStream(f.getAbsoluteFile());
    					byte[] data = new byte[(int)(f.length())];
    					int offset = 0;
    					while(offset < data.length) {
    						int num = fis.read(data, offset, fis.available());
    						offset+= num;
    					}
    					
    					if (!java) {
    						if ((data[0] & 0xFF) != 0xF0) {
    							byte[] outData = new byte[data.length+1];
    							outData[0] = (byte)0xF0;
    							for (int i = 1; i < outData.length; i++) outData[i] = data[i-1];
    							mo.sendMidi(outData);
    						} else mo.sendMidi(data); 
    					} else {
    						if ((data[0] & 0xFF) == 0xF0) {
    							byte[] outData = new byte[data.length-1];
    							for (int i = 1; i < data.length; i++) outData[i-1] = data[i];
    							sendJavaMidi(240, outData);
    						} else sendJavaMidi(240, data);
    					}
    				} catch (Exception ex){ex.printStackTrace();}
    			}
    		});
    
    		upper1.add(send);
    		upper.add("North", upper1);
    		frame.getContentPane().add("North", upper);
    		
    		upper2 = new JPanel(new GridLayout(1,0));
    		upper2.add(createSlider("Pitch", 8192, 224, 0));
    		upper2.add(createSlider("Modulation", 0, 176, 1));
    		upper2.add(createControllerSlider( 128, 176));
    		
    		upper.add("Center", upper2);
    		
    		JPanel p = new JPanel(new BorderLayout());
    		
    		frame.getContentPane().add("Center", new Piano());
    		
    		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    		
    	}
    	
    	    
        public static void main (String args[]) {
            
    		miditest test = new miditest();
        
    	}
    	
    	private MidiInput openInput(int index) {
    		
    		MidiInput mi = de.humatic.mmj.MidiSystem.openMidiInput(index);
    		
    		MidiInputListener mil = new MidiInputListener(mi);
    		
    		return mi;
    		
    	}
    		
    	private MidiOutput openOutput(int index) {
    	
    		return de.humatic.mmj.MidiSystem.openMidiOutput(index);
    		
    	}	
    	
    	public void midiInput(byte[] data){
    		
    		for (int i = 0; i < data.length; i++) {
    			//System.out.print((data[i] & 0xFF)+"  ");
    			System.out.print(hexChars[(data[i] & 0xFF) / 16] );
    			System.out.print(hexChars[(data[i] & 0xFF) % 16]+"  ");
    			if (data.length > 5 && i % 15 == 0) System.out.println("");
    		}
    		System.out.println("");
    		
    	}
    	
    	public void systemChanged() {
    		
    		try{
    			ib.removeAllItems();
    			for (int i = 0; i < de.humatic.mmj.MidiSystem.getInputs().length; i++) ib.addItem(de.humatic.mmj.MidiSystem.getInputs()[i]);
    		
    			ob.removeAllItems();
    			for (int i = 0; i < de.humatic.mmj.MidiSystem.getOutputs().length; i++) ob.addItem(de.humatic.mmj.MidiSystem.getOutputs()[i]);
    		} catch (Exception e){}
    		
    		System.out.println("MIDI SYSTEM CHANGED");
    		
    	}
    	
    	void sendJavaMidi(int status, byte[] data) { 
    		
    		if (receiver == null) return;
    		
    		try{
    
    			MidiMessage msg = null;
    
    			if (status == 0xF0) {
    
    				msg = new javax.sound.midi.SysexMessage();
    
    				try{ ((SysexMessage)msg).setMessage(0xF0, data, data.length); }catch (InvalidMidiDataException imde){return;}
    
    			} else if (status >= 250) {
    
    				msg = new ShortMessage();
    
    				try{((ShortMessage)msg).setMessage(status); }catch (InvalidMidiDataException imde){return;}
    
    			} else {
    			
    				msg = new ShortMessage(); 
    
    				try{((ShortMessage)msg).setMessage(status, data[0], data[1]); }catch (InvalidMidiDataException imde){return;}
    			
    			}
    
    			if (msg == null) return;
    
    			receiver.send(msg, 0); 
    
    		}catch (Exception e){}
    
    	}
    
    
    	private class MidiIn implements Receiver{
    		
    		private String name;
    		
    		private MidiIn(String portName) { name = portName; }
    
    		public void close(){}
    
    		public void send(MidiMessage msg, long timeStamp) {
    
    			if (msg.getStatus() == 254) return;
    			
    			System.out.println("Input from: "+name);
    			
    			for (int i = 0; i < msg.getMessage().length; i++) {
    				if (!hex) System.out.print(msg.getMessage()[i]+" ");
    				else {
    					System.out.print(hexChars[(msg.getMessage()[i] & 0xFF) / 16] );
    					System.out.print(hexChars[(msg.getMessage()[i] & 0xFF) % 16]+"  ");
    					if (msg.getLength() > 4 && (i+1) % 16 == 0) System.out.println("");
    				}
    			}
    			System.out.println("");
    		
    		}
    		
    	}
    	
    	private JSlider createSlider(String name, final int def, final int status, final int cNr) {
    		
    		final JSlider slider = new JSlider(0, status < 224 ? 128 : 16384, def);
    		slider.setBorder(new javax.swing.border.TitledBorder(name));
    		slider.addChangeListener(new javax.swing.event.ChangeListener() {
    			public void stateChanged(javax.swing.event.ChangeEvent e) {
    				try{
    					if (status < 224) {
    						if (java) sendJavaMidi(status+ch, new byte[]{(byte)cNr, (byte)(slider.getValue())}); 
    						else mo.sendMidi(new byte[]{(byte)(status+ch), (byte)cNr, (byte)(slider.getValue())}, de.humatic.mmj.MidiSystem.getHostTime());
    					} else { 
    						if (java) sendJavaMidi(status+ch, new byte[]{(byte)(slider.getValue() % 0x7F), (byte)(slider.getValue() / 128)}); 
    						else mo.sendMidi(new byte[]{(byte)(status+ch), (byte)(slider.getValue() % 0x7F), (byte)(slider.getValue() / 128)}, de.humatic.mmj.MidiSystem.getHostTime());
    					} 
    				} catch (Exception ex){}
    			}
    		});
    		return slider;
    	}
    	
    	private JPanel createControllerSlider(final int def, final int status) {
    		
    		final JPanel cp = new JPanel(new BorderLayout());
    		cp.setBorder(new javax.swing.border.TitledBorder("Controller"));
    		final JSlider slider = new JSlider(0, 128, def);
    		slider.addChangeListener(new javax.swing.event.ChangeListener() {
    			public void stateChanged(javax.swing.event.ChangeEvent e) {
    				try{
    					if (java) sendJavaMidi(status+ch, new byte[]{(byte)ctrl, (byte)(slider.getValue())}); 
    					else mo.sendMidi(new byte[]{(byte)(status+ch), (byte)ctrl, (byte)(slider.getValue())}, de.humatic.mmj.MidiSystem.getHostTime());
    				} catch (Exception ex){}
    			}
    		});
    		final JTextField tf = new JTextField("  7  ");
    		tf.addActionListener(new java.awt.event.ActionListener() {
    			public void actionPerformed(java.awt.event.ActionEvent e) {
    				try{ ctrl = new Integer(tf.getText().trim()).intValue(); } catch (Exception ex){ ctrl = 7; }
    			}
    		});
     
    		cp.add("Center", slider);
    		cp.add("East", tf);
    		return cp;
    	}
    	
    	/** Piano & Key code basics taken from javasound demos (c) Sun Microsystems **/
         
    	 class Key extends Rectangle {
            int noteState = 0;
            int kNum;
            boolean isBlack;
    
            public Key(int x, int y, int width, int height, int num, boolean black) {
                super(x, y, width, height);
                kNum = num;
                isBlack = black;
            }
            public boolean isNoteOn() {
                return noteState == 1;
            }
            public void on(int vel) {
    		   try {
    			   if (isBlack) vel = vel*2;
    			   setNoteState(1);
    			   if (java) sendJavaMidi(144, new byte[]{(byte)kNum, (byte)vel}); 
    			   else mo.sendMidi(new byte[]{(byte)144, (byte)kNum, (byte)vel}, de.humatic.mmj.MidiSystem.getHostTime());
    		   
    			}catch (Exception me) {}
            }
            public void off() {
    			try {
    			    setNoteState(0);
    				if (java) sendJavaMidi(128, new byte[]{(byte)kNum, (byte)0});
    				else mo.sendMidi(new byte[]{(byte)128, (byte)kNum, (byte)0}, de.humatic.mmj.MidiSystem.getHostTime());
    				
    		   }catch (Exception me) {}
            }
            public void setNoteState(int state) {
                noteState = state;
            }
    
            public void transpose(int oct) {
    			kNum += oct*12;
    		}
        }
    
    
    
        /**
    	 * Piano renders black & white keys and plays the notes for a MIDI
         * channel.
         */
        class Piano extends JPanel implements MouseListener {
    
            Vector keys = new Vector();
    		Vector whiteKeys = new Vector();
    		Vector blackKeys = new Vector();
            Key prevKey;
            java.util.Vector permanents = new Vector();
            final int kw = 18, kh = 128;
    		final Color jfcBlue = new Color(204, 204, 255);
    		final Color pink = new Color(255, 175, 175);
    		boolean record;
    
            public Piano() {
                setLayout(new BorderLayout());
                setPreferredSize(new Dimension(42*kw, kh+1));
                int transpose = 36;
                int whiteIDs[] = { 0, 2, 4, 5, 7, 9, 11 };
    
                for (int i = 0, x = 0; i < 6; i++) {
                    for (int j = 0; j < 7; j++, x += kw) {
                        int keyNum = i * 12 + whiteIDs[j] + transpose;
                        whiteKeys.add(new Key(x, 0, kw, kh, keyNum, false));
                       /* if (j == 0) {
    						Key C = (Key)whiteKeys.elementAt(whiteKeys.size()-1);
    						this.getGraphics().setColor(Color.black);
    						this.getGraphics().drawString(("c"+new Integer(i).toString()), x+2, 100);
    					}*/
                    }
                }
                for (int i = 0, x = 0; i < 6; i++, x += kw) {
                    int keyNum = i * 12 + transpose;
                    blackKeys.add(new Key((x += kw)-4, 0, kw/2, kh/2, keyNum+1, true));
                    blackKeys.add(new Key((x += kw)-4, 0, kw/2, kh/2, keyNum+3, true));
                    x += kw;
                    blackKeys.add(new Key((x += kw)-4, 0, kw/2, kh/2, keyNum+6, true));
                    blackKeys.add(new Key((x += kw)-4, 0, kw/2, kh/2, keyNum+8, true));
                    blackKeys.add(new Key((x += kw)-4, 0, kw/2, kh/2, keyNum+10, true));
                }
                keys.addAll(blackKeys);
                keys.addAll(whiteKeys);
    
                addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseMoved(MouseEvent e) {
                        if (mouseOverCB.isSelected()) {
                            Key key = getKey(e.getPoint());
                            if (prevKey != null && prevKey != key) {
                                prevKey.off();
                            }
                            if (key != null && prevKey != key) {
                                key.on(e.getY());
                            }
                            prevKey = key;
                            repaint();
                        }
                    }
                });
                addMouseListener(this);
            }
    
            public void mousePressed(MouseEvent e) {
    			if (!outputEnabled) return;
                prevKey = getKey(e.getPoint());
    
                for (int i = 0; i < permanents.size(); i++) {
    				if (permanents.elementAt(i).equals(prevKey)) {
    				prevKey.off();
                    repaint();
                    permanents.removeElementAt(i);
                    break;
    				}
    			}
                if (prevKey != null) {
    				prevKey.on(e.getY());
                    repaint();
                }
            }
            public void mouseReleased(MouseEvent e) {
    			if (!outputEnabled) return;
                if (e.getButton() == MouseEvent.BUTTON3) {
    				permanents.add(prevKey);
    				return;
    			}
                if (prevKey != null) {
                    prevKey.off();
                    repaint();
                    //prevKey = null;
                }
            }
            public void mouseExited(MouseEvent e) {
               /* if (prevKey != null) {
                    prevKey.off();
                    repaint();
                    prevKey = null;
                }*/
            }
            public void mouseClicked(MouseEvent e) { }
            public void mouseEntered(MouseEvent e) { }
    
    
            public Key getKey(Point point) {
                for (int i = 0; i < keys.size(); i++) {
                    if (((Key) keys.get(i)).contains(point)) {
                        return (Key) keys.get(i);
                    }
                }
                return null;
            }
    
            public void paint(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                Dimension d = getSize();
    
                g2.setBackground(getBackground());
                g2.clearRect(0, 0, d.width, d.height);
    
                g2.setColor(Color.white);
                g2.fillRect(0, 0, 42*kw, kh);
    
                for (int i = 0; i < whiteKeys.size(); i++) {
                    Key key = (Key) whiteKeys.get(i);
                    if (key.isNoteOn()) {
                        g2.setColor(record ? pink : jfcBlue);
                        g2.fill(key);
                    }
                    g2.setColor(Color.black);
                    g2.draw(key);
                }
                for (int i = 0; i < blackKeys.size(); i++) {
                    Key key = (Key) blackKeys.get(i);
                    if (key.isNoteOn()) {
                        g2.setColor(record ? pink : jfcBlue);
                        g2.fill(key);
                        g2.setColor(Color.black);
                        g2.draw(key);
                    } else {
                        g2.setColor(Color.black);
                        g2.fill(key);
                    }
                }
            }
        } // End class Piano
    	
    	private class MidiInputListener implements MidiListener {
    		
    		private MidiInput myInput;
    		
    		private MidiInputListener(MidiInput in) {
    			
    			myInput = in;
    			
    			in.addMidiListener(this);
    			
    		}
    		
    		public void midiInput(byte[] data){
    			
    			System.out.println("Input from: "+myInput.getName());
    			for (int i = 0; i < data.length; i++) {
    				System.out.print(hexChars[(data[i] & 0xFF) / 16] );
    				System.out.print(hexChars[(data[i] & 0xFF) % 16]+"  ");
    				if (data.length > 5 && (i+1) % 16 == 0) System.out.println("");
    			}
    			System.out.println("");
    		
    		}
    
    	}		
    			
    }

  16. #56
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default The key to midiout

    Finaly this class might do the work see link
    MidiOutput
    take a look at void
    sendMidi(byte[] data) Sends raw Midi bytes immediately.
    This might be the key to it all?
    I have to go in conclave among myself and figure out how this fits into my pascal to java application.

    thanks

  17. #57
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Thumbs up promising

    Quote Originally Posted by willemjav View Post
    .....This might be the key to it all?
    I have to go in conclave among myself and figure out how this fits into my pascal to java application.
    Might be, I will have to look at it and the code you posted, I just got here. There are ways of converting one language to another, but many of them are un-reliable ( concepts in one language do not work well in the other and so on ) I have never worked with Pascal, but I can tell you from experience the place to start looking is 100% academic search and no other, until at least you find someting that makes some sense.

    Sendiing raw bytes to the midi port depends on issues deep in computer science and resolves to available buffer size in the physical device as well as buffer size in the code ( in the card ) Coding at this level reaches a barrier where ususally it is a matter of who wrote the driver. I have a contact who wrote drivers, I will email him this morning with the link to this discussion.

    Do you know the difference betweeen Java and C? There is an even lower level where the actual instructions that drive the physical device are written, and even then it is a matter of the what processor and on and on. See if you can find any documentation, no matter how slight, from the vendor of the board.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  18. #58
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Thumbs up yes, this is what you need

    " a series of specialized applications and JNI libraries "

    Thats exactly what is needed.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  19. #59
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    The code uses AWT and or Swing as the user interface. How did you select notes when you used Pascal? In other words, where's the keyboard?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  20. #60
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    9

    Default

    Nick, thanks for you effort, I am pretty confident that this link might work and help to find the key to the problem. I have to study the info of the classes and interfaces. Than I should find the midi devices present, select one midi out device that reaches the card (I all tried that part) and finally make the midi out to work. When I have the function-call midi_out(byte), I can proceed writing the java conversion.

    To your question of note selection, there is no keyboard. One of the basic ideas of the electronic component of the work Cités (text apollinaire) is to send midi notes as fast as possible to the synth module (there is a physical limit concerning the fbo1 swallowing notes, not for the comp to generate them) The idea is similar to Ligeti´s work continuum (which, by the way never worked because of human limitations).

    Keyboards do basically “pitch selections” (I have a grand piano and do not like keyboards, said I arrogantly). The electronic component is not always pitch orientated (I also used midi exclusives to generate “not tuned pitches” the cello plays some ¼ tones as well).

    I will write a class that basically does the stuff I said above…. Probably need a helping hand. By the way you´ll find a mp3 excerpt (Dutch radio, program Musica Nova) of the work at my web-page WILLEM DRAGSTRA WEB SITE it´ll give you an idea of the electronic part of the work (kicks in some later) under recordings (Cités, sorry for some clipping)

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. DES algorithm (Read and Write bytes to file)
    By JoaoPe in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 04:46 PM
  2. Reading bytes from InputStream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-25-2007, 08:51 PM
  3. how to know the number of bytes
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 06:13 PM
  4. help with midi files
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •