Source for gnu.javax.sound.midi.alsa.AlsaMidiSequencerDevice

   1: /* AlsaMidiSequencerDevice.java -- The ALSA MIDI sequencer device
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package gnu.javax.sound.midi.alsa;
  40: 
  41: import java.io.IOException;
  42: import java.io.InputStream;
  43: 
  44: import javax.sound.midi.ControllerEventListener;
  45: import javax.sound.midi.InvalidMidiDataException;
  46: import javax.sound.midi.MetaEventListener;
  47: import javax.sound.midi.MidiUnavailableException;
  48: import javax.sound.midi.Receiver;
  49: import javax.sound.midi.Sequence;
  50: import javax.sound.midi.Sequencer;
  51: import javax.sound.midi.Track;
  52: import javax.sound.midi.Transmitter;
  53: 
  54: // FIXME: These next two imports are only required by gcj it seems.
  55: import javax.sound.midi.MidiDevice.Info;
  56: import javax.sound.midi.Sequencer.SyncMode;
  57: 
  58: /**
  59:  * The ALSA MIDI sequencer device.  This is a singleton device.
  60:  * 
  61:  * @author green@redhat.com
  62:  *
  63:  */
  64: public class AlsaMidiSequencerDevice implements Sequencer
  65: {
  66:   // The singleton instance.
  67:   public final static AlsaMidiSequencerDevice instance = new AlsaMidiSequencerDevice();
  68:   
  69:   // A pointer to a native chunk of memory
  70:   private long nativeState;
  71:   
  72:   // The sequence to process
  73:   private Sequence sequence;
  74:   
  75:   /**
  76:    * A private constructor.  There should only be one instance of this
  77:    * device. 
  78:    */
  79:   private AlsaMidiSequencerDevice()
  80:   {
  81:     super();
  82:   }
  83: 
  84:   /**
  85:    * Return the sequencer singleton.
  86:    * 
  87:    * @return the sequencer singleton
  88:    */
  89:   public static AlsaMidiSequencerDevice getInstance()
  90:   {
  91:     return instance;
  92:   }
  93:   
  94:   /* (non-Javadoc)
  95:    * @see javax.sound.midi.Sequencer#setSequence(javax.sound.midi.Sequence)
  96:    */
  97:   public void setSequence(Sequence seq) throws InvalidMidiDataException
  98:   {
  99:     sequence = seq;
 100:   }
 101: 
 102:   /* (non-Javadoc)
 103:    * @see javax.sound.midi.Sequencer#setSequence(java.io.InputStream)
 104:    */
 105:   public void setSequence(InputStream istream) throws IOException,
 106:       InvalidMidiDataException
 107:   {
 108:     // TODO Auto-generated method stub
 109:   }
 110: 
 111:   /* (non-Javadoc)
 112:    * @see javax.sound.midi.Sequencer#getSequence()
 113:    */
 114:   public Sequence getSequence()
 115:   {
 116:     return sequence;
 117:   }
 118: 
 119:   /* (non-Javadoc)
 120:    * @see javax.sound.midi.Sequencer#start()
 121:    */
 122:   public void start()
 123:   {
 124:     // TODO Auto-generated method stub
 125:   }
 126: 
 127:   /* (non-Javadoc)
 128:    * @see javax.sound.midi.Sequencer#stop()
 129:    */
 130:   public void stop()
 131:   {
 132:     // TODO Auto-generated method stub
 133: 
 134:   }
 135: 
 136:   /* (non-Javadoc)
 137:    * @see javax.sound.midi.Sequencer#isRunning()
 138:    */
 139:   public boolean isRunning()
 140:   {
 141:     // TODO Auto-generated method stub
 142:     return false;
 143:   }
 144: 
 145:   /* (non-Javadoc)
 146:    * @see javax.sound.midi.Sequencer#startRecording()
 147:    */
 148:   public void startRecording()
 149:   {
 150:     // TODO Auto-generated method stub
 151: 
 152:   }
 153: 
 154:   /* (non-Javadoc)
 155:    * @see javax.sound.midi.Sequencer#stopRecording()
 156:    */
 157:   public void stopRecording()
 158:   {
 159:     // TODO Auto-generated method stub
 160: 
 161:   }
 162: 
 163:   /* (non-Javadoc)
 164:    * @see javax.sound.midi.Sequencer#isRecording()
 165:    */
 166:   public boolean isRecording()
 167:   {
 168:     // TODO Auto-generated method stub
 169:     return false;
 170:   }
 171: 
 172:   /* (non-Javadoc)
 173:    * @see javax.sound.midi.Sequencer#recordEnable(javax.sound.midi.Track, int)
 174:    */
 175:   public void recordEnable(Track track, int channel)
 176:   {
 177:     // TODO Auto-generated method stub
 178: 
 179:   }
 180: 
 181:   /* (non-Javadoc)
 182:    * @see javax.sound.midi.Sequencer#recordDisable(javax.sound.midi.Track)
 183:    */
 184:   public void recordDisable(Track track)
 185:   {
 186:     // TODO Auto-generated method stub
 187: 
 188:   }
 189: 
 190:   /* (non-Javadoc)
 191:    * @see javax.sound.midi.Sequencer#getTempoInBPM()
 192:    */
 193:   public float getTempoInBPM()
 194:   {
 195:     // TODO Auto-generated method stub
 196:     return 0;
 197:   }
 198: 
 199:   /* (non-Javadoc)
 200:    * @see javax.sound.midi.Sequencer#setTempoInBPM(float)
 201:    */
 202:   public void setTempoInBPM(float bpm)
 203:   {
 204:     // TODO Auto-generated method stub
 205: 
 206:   }
 207: 
 208:   /* (non-Javadoc)
 209:    * @see javax.sound.midi.Sequencer#getTempoInMPQ()
 210:    */
 211:   public float getTempoInMPQ()
 212:   {
 213:     // TODO Auto-generated method stub
 214:     return 0;
 215:   }
 216: 
 217:   /* (non-Javadoc)
 218:    * @see javax.sound.midi.Sequencer#setTempoInMPQ(float)
 219:    */
 220:   public void setTempoInMPQ(float mpq)
 221:   {
 222:     // TODO Auto-generated method stub
 223: 
 224:   }
 225: 
 226:   /* (non-Javadoc)
 227:    * @see javax.sound.midi.Sequencer#setTempoFactor(float)
 228:    */
 229:   public void setTempoFactor(float factor)
 230:   {
 231:     // TODO Auto-generated method stub
 232: 
 233:   }
 234: 
 235:   /* (non-Javadoc)
 236:    * @see javax.sound.midi.Sequencer#getTempoFactor()
 237:    */
 238:   public float getTempoFactor()
 239:   {
 240:     // TODO Auto-generated method stub
 241:     return 0;
 242:   }
 243: 
 244:   /* (non-Javadoc)
 245:    * @see javax.sound.midi.Sequencer#getTickLength()
 246:    */
 247:   public long getTickLength()
 248:   {
 249:     // TODO Auto-generated method stub
 250:     return 0;
 251:   }
 252: 
 253:   /* (non-Javadoc)
 254:    * @see javax.sound.midi.Sequencer#getTickPosition()
 255:    */
 256:   public long getTickPosition()
 257:   {
 258:     // TODO Auto-generated method stub
 259:     return 0;
 260:   }
 261: 
 262:   /* (non-Javadoc)
 263:    * @see javax.sound.midi.Sequencer#setTickPosition(long)
 264:    */
 265:   public void setTickPosition(long tick)
 266:   {
 267:     // TODO Auto-generated method stub
 268: 
 269:   }
 270: 
 271:   /* (non-Javadoc)
 272:    * @see javax.sound.midi.Sequencer#getMicrosecondLength()
 273:    */
 274:   public long getMicrosecondLength()
 275:   {
 276:     // TODO Auto-generated method stub
 277:     return 0;
 278:   }
 279: 
 280:   /* (non-Javadoc)
 281:    * @see javax.sound.midi.Sequencer#getMicrosecondPosition()
 282:    */
 283:   public long getMicrosecondPosition()
 284:   {
 285:     // TODO Auto-generated method stub
 286:     return 0;
 287:   }
 288: 
 289:   /* (non-Javadoc)
 290:    * @see javax.sound.midi.Sequencer#setMicrosecondPosition(long)
 291:    */
 292:   public void setMicrosecondPosition(long microsecond)
 293:   {
 294:     // TODO Auto-generated method stub
 295: 
 296:   }
 297: 
 298:   /* (non-Javadoc)
 299:    * @see javax.sound.midi.Sequencer#setMasterSyncMode(javax.sound.midi.Sequencer.SyncMode)
 300:    */
 301:   public void setMasterSyncMode(SyncMode sync)
 302:   {
 303:     // TODO Auto-generated method stub
 304: 
 305:   }
 306: 
 307:   /* (non-Javadoc)
 308:    * @see javax.sound.midi.Sequencer#getMasterSyncMode()
 309:    */
 310:   public SyncMode getMasterSyncMode()
 311:   {
 312:     // TODO Auto-generated method stub
 313:     return null;
 314:   }
 315: 
 316:   /* (non-Javadoc)
 317:    * @see javax.sound.midi.Sequencer#getMasterSyncModes()
 318:    */
 319:   public SyncMode[] getMasterSyncModes()
 320:   {
 321:     // TODO Auto-generated method stub
 322:     return null;
 323:   }
 324: 
 325:   /* (non-Javadoc)
 326:    * @see javax.sound.midi.Sequencer#setSlaveSyncMode(javax.sound.midi.Sequencer.SyncMode)
 327:    */
 328:   public void setSlaveSyncMode(SyncMode sync)
 329:   {
 330:     // TODO Auto-generated method stub
 331: 
 332:   }
 333: 
 334:   /* (non-Javadoc)
 335:    * @see javax.sound.midi.Sequencer#getSlaveSyncMode()
 336:    */
 337:   public SyncMode getSlaveSyncMode()
 338:   {
 339:     // TODO Auto-generated method stub
 340:     return null;
 341:   }
 342: 
 343:   /* (non-Javadoc)
 344:    * @see javax.sound.midi.Sequencer#getSlaveSyncModes()
 345:    */
 346:   public SyncMode[] getSlaveSyncModes()
 347:   {
 348:     // TODO Auto-generated method stub
 349:     return null;
 350:   }
 351: 
 352:   /* (non-Javadoc)
 353:    * @see javax.sound.midi.Sequencer#setTrackMute(int, boolean)
 354:    */
 355:   public void setTrackMute(int track, boolean mute)
 356:   {
 357:     // TODO Auto-generated method stub
 358: 
 359:   }
 360: 
 361:   /* (non-Javadoc)
 362:    * @see javax.sound.midi.Sequencer#getTrackMute(int)
 363:    */
 364:   public boolean getTrackMute(int track)
 365:   {
 366:     // TODO Auto-generated method stub
 367:     return false;
 368:   }
 369: 
 370:   /* (non-Javadoc)
 371:    * @see javax.sound.midi.Sequencer#setTrackSolo(int, boolean)
 372:    */
 373:   public void setTrackSolo(int track, boolean solo)
 374:   {
 375:     // TODO Auto-generated method stub
 376: 
 377:   }
 378: 
 379:   /* (non-Javadoc)
 380:    * @see javax.sound.midi.Sequencer#getTrackSolo(int)
 381:    */
 382:   public boolean getTrackSolo(int track)
 383:   {
 384:     // TODO Auto-generated method stub
 385:     return false;
 386:   }
 387: 
 388:   /* (non-Javadoc)
 389:    * @see javax.sound.midi.Sequencer#addMetaEventListener(javax.sound.midi.MetaEventListener)
 390:    */
 391:   public boolean addMetaEventListener(MetaEventListener listener)
 392:   {
 393:     // TODO Auto-generated method stub
 394:     return false;
 395:   }
 396: 
 397:   /* (non-Javadoc)
 398:    * @see javax.sound.midi.Sequencer#removeMetaEventListener(javax.sound.midi.MetaEventListener)
 399:    */
 400:   public void removeMetaEventListener(MetaEventListener listener)
 401:   {
 402:     // TODO Auto-generated method stub
 403: 
 404:   }
 405: 
 406:   /* (non-Javadoc)
 407:    * @see javax.sound.midi.Sequencer#addControllerEventListener(javax.sound.midi.ControllerEventListener, int[])
 408:    */
 409:   public int[] addControllerEventListener(ControllerEventListener listener,
 410:                                           int[] controllers)
 411:   {
 412:     // TODO Auto-generated method stub
 413:     return null;
 414:   }
 415: 
 416:   /* (non-Javadoc)
 417:    * @see javax.sound.midi.Sequencer#removeControllerEventListener(javax.sound.midi.ControllerEventListener, int[])
 418:    */
 419:   public int[] removeControllerEventListener(ControllerEventListener listener,
 420:                                              int[] controllers)
 421:   {
 422:     // TODO Auto-generated method stub
 423:     return null;
 424:   }
 425: 
 426:   /* (non-Javadoc)
 427:    * @see javax.sound.midi.MidiDevice#getDeviceInfo()
 428:    */
 429:   public Info getDeviceInfo()
 430:   {
 431:     // TODO Auto-generated method stub
 432:     return null;
 433:   }
 434: 
 435:   /* (non-Javadoc)
 436:    * @see javax.sound.midi.MidiDevice#open()
 437:    */
 438:   public void open() throws MidiUnavailableException
 439:   {
 440:     synchronized(this)
 441:     {
 442:       // Check to see if we're open already.
 443:       if (nativeState != 0)
 444:         return;
 445:      
 446:       nativeState = open_();
 447:     }
 448:   }
 449: 
 450:   /**
 451:    * Allocate the native state object, and open the sequencer.
 452:    * 
 453:    * @return a long representation of a pointer to the nativeState.
 454:    */
 455:   private native long open_();
 456:   
 457:   /**
 458:    * Close the sequencer and free the native state object.
 459:    */
 460:   private native void close_(long nativeState);
 461:   
 462:   /* (non-Javadoc)
 463:    * @see javax.sound.midi.MidiDevice#close()
 464:    */
 465:   public void close()
 466:   {
 467:     synchronized(this)
 468:     {
 469:       close_(nativeState);
 470:       nativeState = 0;
 471:     }
 472:   }
 473: 
 474:   /* (non-Javadoc)
 475:    * @see javax.sound.midi.MidiDevice#isOpen()
 476:    */
 477:   public boolean isOpen()
 478:   {
 479:     synchronized(this)
 480:     {
 481:       return (nativeState != 0);
 482:     }
 483:   }
 484: 
 485:   /* (non-Javadoc)
 486:    * @see javax.sound.midi.MidiDevice#getMaxReceivers()
 487:    */
 488:   public int getMaxReceivers()
 489:   {
 490:     return -1;
 491:   }
 492: 
 493:   /* (non-Javadoc)
 494:    * @see javax.sound.midi.MidiDevice#getMaxTransmitters()
 495:    */
 496:   public int getMaxTransmitters()
 497:   {
 498:     return -1;
 499:   }
 500: 
 501:   /* (non-Javadoc)
 502:    * @see javax.sound.midi.MidiDevice#getReceiver()
 503:    */
 504:   public Receiver getReceiver() throws MidiUnavailableException
 505:   {
 506:     // TODO Auto-generated method stub
 507:     return null;
 508:   }
 509: 
 510:   /* (non-Javadoc)
 511:    * @see javax.sound.midi.MidiDevice#getTransmitter()
 512:    */
 513:   public Transmitter getTransmitter() throws MidiUnavailableException
 514:   {
 515:     // TODO Auto-generated method stub
 516:     return null;
 517:   }
 518: 
 519: }