/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/Client.java
ViewVC logotype

Diff of /jlscp/trunk/src/org/linuxsampler/lscp/Client.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1765 by iliev, Tue Apr 29 16:04:42 2008 UTC revision 1766 by iliev, Mon Sep 8 00:16:17 2008 UTC
# Line 178  public class Client { Line 178  public class Client {
178          public synchronized boolean          public synchronized boolean
179          getExtendedCharacterEscaping() { return extendedCharacterEscaping; }          getExtendedCharacterEscaping() { return extendedCharacterEscaping; }
180                    
181            /**
182             * @see java.net.Socket#setSoTimeout
183             */
184            public synchronized void
185            setSoTimeout(int timeout) {
186                    soTimeout = timeout;
187                    
188                    try { if(sock != null) sock.setSoTimeout(timeout); }
189                    catch(Exception x) { this.getLogger().log(Level.INFO, "Unable to set timeout", x); }
190            }
191            
192          private String          private String
193          toEscapedText(String s) {          toEscapedText(String s) {
194                  s = toEscapedString(s);                  s = toEscapedString(s);
# Line 384  public class Client { Line 395  public class Client {
395                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");                  if(!llMIMI.isEmpty()) subscribe("MIDI_INSTRUMENT_MAP_INFO");
396                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");                  if(!llMIC.isEmpty()) subscribe("MIDI_INSTRUMENT_COUNT");
397                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");                  if(!llMII.isEmpty()) subscribe("MIDI_INSTRUMENT_INFO");
398                    if(!llDMD.isEmpty()) subscribe("DEVICE_MIDI");
399                    if(!llCMD.isEmpty()) subscribe("CHANNEL_MIDI");
400                  if(!llID.isEmpty()) {                  if(!llID.isEmpty()) {
401                          subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");                          subscribe("DB_INSTRUMENT_DIRECTORY_COUNT");
402                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");                          subscribe("DB_INSTRUMENT_DIRECTORY_INFO");
# Line 534  public class Client { Line 547  public class Client {
547          /** MIDI instrument info listeners */          /** MIDI instrument info listeners */
548          private final Vector<MidiInstrumentInfoListener> llMII =          private final Vector<MidiInstrumentInfoListener> llMII =
549                  new Vector<MidiInstrumentInfoListener>();                  new Vector<MidiInstrumentInfoListener>();
550            private final Vector<DeviceMidiDataListener> llDMD = new Vector<DeviceMidiDataListener>();
551            private final Vector<ChannelMidiDataListener> llCMD = new Vector<ChannelMidiDataListener>();
552          private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();          private final Vector<InstrumentsDbListener> llID = new Vector<InstrumentsDbListener>();
553          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();          private final Vector<GlobalInfoListener> llGI = new Vector<GlobalInfoListener>();
554                    
# Line 565  public class Client { Line 580  public class Client {
580                          !llMIMI.isEmpty() ||                          !llMIMI.isEmpty() ||
581                          !llMIC.isEmpty()  ||                          !llMIC.isEmpty()  ||
582                          !llMII.isEmpty()  ||                          !llMII.isEmpty()  ||
583                            !llDMD.isEmpty()  ||
584                            !llCMD.isEmpty()  ||
585                          !llID.isEmpty()   ||                          !llID.isEmpty()   ||
586                          !llGI.isEmpty();                          !llGI.isEmpty();
587          }          }
588                    
589          private synchronized void          private synchronized void
590            fireDeviceMidiDataEvent(String s) {
591                    try {
592                            String[] list = parseStringList(s, ' ');
593                            if(list.length != 5) {
594                                    getLogger().warning("Unknown DEVICE_MIDI format");
595                                    return;
596                            }
597                            
598                            int dev = parseInt(list[0]);
599                            int port = parseInt(list[1]);
600                            
601                            MidiDataEvent.Type type = parseMidiDataType(list[2]);
602                            if(type == null) return;
603                            
604                            int note = parseInt(list[3]);
605                            int velocity = parseInt(list[4]);
606                            
607                            DeviceMidiDataEvent e = new DeviceMidiDataEvent(this, type, note, velocity);
608                            e.setDeviceId(dev);
609                            e.setPortId(port);
610                            for(DeviceMidiDataListener l : llDMD) l.midiDataArrived(e);
611                    } catch(LscpException x) {
612                            getLogger().log (
613                                    Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x
614                            );
615                    }
616            }
617            
618            private synchronized void
619            fireChannelMidiDataEvent(String s) {
620                    try {
621                            String[] list = parseStringList(s, ' ');
622                            if(list.length != 4) {
623                                    getLogger().warning("Unknown CHANNEL_MIDI format");
624                                    return;
625                            }
626                            
627                            int channel = parseInt(list[0]);
628                            
629                            MidiDataEvent.Type type = parseMidiDataType(list[1]);
630                            if(type == null) return;
631                            
632                            int note = parseInt(list[2]);
633                            int velocity = parseInt(list[3]);
634                            
635                            ChannelMidiDataEvent e = new ChannelMidiDataEvent(this, type, note, velocity);
636                            e.setChannelId(channel);
637                            for(ChannelMidiDataListener l : llCMD) l.midiDataArrived(e);
638                    } catch(LscpException x) {
639                            getLogger().log (
640                                    Level.WARNING, LscpI18n.getLogMsg("CommandFailed!"), x
641                            );
642                    }
643            }
644            
645            private MidiDataEvent.Type
646            parseMidiDataType(String s) {
647                    if("NOTE_ON".equals(s)) return MidiDataEvent.Type.NOTE_ON;
648                    if("NOTE_OFF".equals(s)) return MidiDataEvent.Type.NOTE_OFF;
649                    
650                    getLogger().warning("Unknown MIDI data type: " + s);
651                    return null;
652            }
653            
654            private synchronized void
655          fireEvent(String s) {          fireEvent(String s) {
656                   if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {                  // Sort by priority
657                    
658                     if(s.startsWith("CHANNEL_MIDI:")) {
659                            s = s.substring("CHANNEL_MIDI:".length());
660                            fireChannelMidiDataEvent(s);
661                    } else if(s.startsWith("DEVICE_MIDI:")) {
662                            s = s.substring("DEVICE_MIDI:".length());
663                            fireDeviceMidiDataEvent(s);
664                    } else if(s.startsWith("DB_INSTRUMENT_DIRECTORY_COUNT:")) {
665                          s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());                          s = s.substring("DB_INSTRUMENT_DIRECTORY_COUNT:".length());
666                          InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);                          InstrumentsDbEvent e = new InstrumentsDbEvent(this, s);
667                          for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);                          for(InstrumentsDbListener l : llID) l.directoryCountChanged(e);
# Line 1315  public class Client { Line 1405  public class Client {
1405          /**          /**
1406           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
1407           * Listeners can be registered regardless of the connection state.           * Listeners can be registered regardless of the connection state.
1408             * @param l The <code>DeviceMidiDataListener</code> to register.
1409             */
1410            public synchronized void
1411            addDeviceMidiDataListener(DeviceMidiDataListener l) {
1412                    if(llDMD.isEmpty()) subscribe("DEVICE_MIDI");
1413                    llDMD.add(l);
1414            }
1415            
1416            /**
1417             * Removes the specified listener.
1418             * Listeners can be removed regardless of the connection state.
1419             * @param l The <code>DeviceMidiDataListener</code> to remove.
1420             */
1421            public synchronized void
1422            removeDeviceMidiDataListener(DeviceMidiDataListener l) {
1423                    boolean b = llDMD.remove(l);
1424                    if(b && llDMD.isEmpty()) unsubscribe("DEVICE_MIDI");
1425            }
1426            
1427            /**
1428             * Registers the specified listener for receiving event messages.
1429             * Listeners can be registered regardless of the connection state.
1430             * @param l The <code>ChannelMidiDataListener</code> to register.
1431             */
1432            public synchronized void
1433            addChannelMidiDataListener(ChannelMidiDataListener l) {
1434                    if(llCMD.isEmpty()) subscribe("CHANNEL_MIDI");
1435                    llCMD.add(l);
1436            }
1437            
1438            /**
1439             * Removes the specified listener.
1440             * Listeners can be removed regardless of the connection state.
1441             * @param l The <code>ChannelMidiDataListener</code> to remove.
1442             */
1443            public synchronized void
1444            removeChannelMidiDataListener(ChannelMidiDataListener l) {
1445                    boolean b = llCMD.remove(l);
1446                    if(b && llCMD.isEmpty()) unsubscribe("CHANNEL_MIDI");
1447            }
1448            
1449            /**
1450             * Registers the specified listener for receiving event messages.
1451             * Listeners can be registered regardless of the connection state.
1452           * @param l The <code>InstrumentsDbListener</code> to register.           * @param l The <code>InstrumentsDbListener</code> to register.
1453           */           */
1454          public synchronized void          public synchronized void
# Line 4933  public class Client { Line 5067  public class Client {
5067                    
5068          /**          /**
5069           * Returns a list of all instrument files in the database           * Returns a list of all instrument files in the database
5070           * that that doesn't exist in the filesystem.           * that that don't exist in the filesystem.
5071           * @throws IOException If some I/O error occurs.           * @throws IOException If some I/O error occurs.
5072           * @throws LscpException If LSCP protocol corruption occurs.           * @throws LscpException If LSCP protocol corruption occurs.
5073           * @throws LSException If other error occurs.           * @throws LSException If other error occurs.

Legend:
Removed from v.1765  
changed lines
  Added in v.1766

  ViewVC Help
Powered by ViewVC