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

   1: /* AlsaMidiSequencerDevice.java -- The ALSA MIDI sequencer device
   2:    Copyright (C) 2005, 2006 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: /**
  55:  * The ALSA MIDI sequencer device.  This is a singleton device.
  56:  *
  57:  * @author green@redhat.com
  58:  *
  59:  */
  60: public class AlsaMidiSequencerDevice implements Sequencer
  61: {
  62:   // The singleton instance.
  63:   public final static AlsaMidiSequencerDevice instance = new AlsaMidiSequencerDevice();
  64: 
  65:   // A pointer to a native chunk of memory
  66:   private long nativeState;
  67: 
  68:   // The sequence to process
  69:   private Sequence sequence;
  70: 
  71:   /**
  72:    * A private constructor.  There should only be one instance of this
  73:    * device.
  74:    */
  75:   private AlsaMidiSequencerDevice()
  76:   {
  77:     super();
  78:   }
  79: 
  80:   /**
  81:    * Return the sequencer singleton.
  82:    *
  83:    * @return the sequencer singleton
  84:    */
  85:   public static AlsaMidiSequencerDevice getInstance()
  86:   {
  87:     return instance;
  88:   }
  89: 
  90:   /* (non-Javadoc)
  91:    * @see javax.sound.midi.Sequencer#setSequence(javax.sound.midi.Sequence)
  92:    */
  93:   public void setSequence(Sequence seq) throws InvalidMidiDataException
  94:   {
  95:     sequence = seq;
  96:   }
  97: 
  98:   /* (non-Javadoc)
  99:    * @see javax.sound.midi.Sequencer#setSequence(java.io.InputStream)
 100:    */
 101:   public void setSequence(InputStream istream) throws IOException,
 102:       InvalidMidiDataException
 103:   {
 104:     // TODO Auto-generated method stub
 105:   }
 106: 
 107:   /* (non-Javadoc)
 108:    * @see javax.sound.midi.Sequencer#getSequence()
 109:    */
 110:   public Sequence getSequence()
 111:   {
 112:     return sequence;
 113:   }
 114: 
 115:   /* (non-Javadoc)
 116:    * @see javax.sound.midi.Sequencer#start()
 117:    */
 118:   public void start()
 119:   {
 120:     // TODO Auto-generated method stub
 121:   }
 122: 
 123:   /* (non-Javadoc)
 124:    * @see javax.sound.midi.Sequencer#stop()
 125:    */
 126:   public void stop()
 127:   {
 128:     // TODO Auto-generated method stub
 129: 
 130:   }
 131: 
 132:   /* (non-Javadoc)
 133:    * @see javax.sound.midi.Sequencer#isRunning()
 134:    */
 135:   public boolean isRunning()
 136:   {
 137:     // TODO Auto-generated method stub
 138:     return false;
 139:   }
 140: 
 141:   /* (non-Javadoc)
 142:    * @see javax.sound.midi.Sequencer#startRecording()
 143:    */
 144:   public void startRecording()
 145:   {
 146:     // TODO Auto-generated method stub
 147: 
 148:   }
 149: 
 150:   /* (non-Javadoc)
 151:    * @see javax.sound.midi.Sequencer#stopRecording()
 152:    */
 153:   public void stopRecording()
 154:   {
 155:     // TODO Auto-generated method stub
 156: 
 157:   }
 158: 
 159:   /* (non-Javadoc)
 160:    * @see javax.sound.midi.Sequencer#isRecording()
 161:    */
 162:   public boolean isRecording()
 163:   {
 164:     // TODO Auto-generated method stub
 165:     return false;
 166:   }
 167: 
 168:   /* (non-Javadoc)
 169:    * @see javax.sound.midi.Sequencer#recordEnable(javax.sound.midi.Track, int)
 170:    */
 171:   public void recordEnable(Track track, int channel)
 172:   {
 173:     // TODO Auto-generated method stub
 174: 
 175:   }
 176: 
 177:   /* (non-Javadoc)
 178:    * @see javax.sound.midi.Sequencer#recordDisable(javax.sound.midi.Track)
 179:    */
 180:   public void recordDisable(Track track)
 181:   {
 182:     // TODO Auto-generated method stub
 183: 
 184:   }
 185: 
 186:   /* (non-Javadoc)
 187:    * @see javax.sound.midi.Sequencer#getTempoInBPM()
 188:    */
 189:   public float getTempoInBPM()
 190:   {
 191:     // TODO Auto-generated method stub
 192:     return 0;
 193:   }
 194: 
 195:   /* (non-Javadoc)
 196:    * @see javax.sound.midi.Sequencer#setTempoInBPM(float)
 197:    */
 198:   public void setTempoInBPM(float bpm)
 199:   {
 200:     // TODO Auto-generated method stub
 201: 
 202:   }
 203: 
 204:   /* (non-Javadoc)
 205:    * @see javax.sound.midi.Sequencer#getTempoInMPQ()
 206:    */
 207:   public float getTempoInMPQ()
 208:   {
 209:     // TODO Auto-generated method stub
 210:     return 0;
 211:   }
 212: 
 213:   /* (non-Javadoc)
 214:    * @see javax.sound.midi.Sequencer#setTempoInMPQ(float)
 215:    */
 216:   public void setTempoInMPQ(float mpq)
 217:   {
 218:     // TODO Auto-generated method stub
 219: 
 220:   }
 221: 
 222:   /* (non-Javadoc)
 223:    * @see javax.sound.midi.Sequencer#setTempoFactor(float)
 224:    */
 225:   public void setTempoFactor(float factor)
 226:   {
 227:     // TODO Auto-generated method stub
 228: 
 229:   }
 230: 
 231:   /* (non-Javadoc)
 232:    * @see javax.sound.midi.Sequencer#getTempoFactor()
 233:    */
 234:   public float getTempoFactor()
 235:   {
 236:     // TODO Auto-generated method stub
 237:     return 0;
 238:   }
 239: 
 240:   /* (non-Javadoc)
 241:    * @see javax.sound.midi.Sequencer#getTickLength()
 242:    */
 243:   public long getTickLength()
 244:   {
 245:     // TODO Auto-generated method stub
 246:     return 0;
 247:   }
 248: 
 249:   /* (non-Javadoc)
 250:    * @see javax.sound.midi.Sequencer#getTickPosition()
 251:    */
 252:   public long getTickPosition()
 253:   {
 254:     // TODO Auto-generated method stub
 255:     return 0;
 256:   }
 257: 
 258:   /* (non-Javadoc)
 259:    * @see javax.sound.midi.Sequencer#setTickPosition(long)
 260:    */
 261:   public void setTickPosition(long tick)
 262:   {
 263:     // TODO Auto-generated method stub
 264: 
 265:   }
 266: 
 267:   /* (non-Javadoc)
 268:    * @see javax.sound.midi.Sequencer#getMicrosecondLength()
 269:    */
 270:   public long getMicrosecondLength()
 271:   {
 272:     // TODO Auto-generated method stub
 273:     return 0;
 274:   }
 275: 
 276:   /* (non-Javadoc)
 277:    * @see javax.sound.midi.Sequencer#getMicrosecondPosition()
 278:    */
 279:   public long getMicrosecondPosition()
 280:   {
 281:     // TODO Auto-generated method stub
 282:     return 0;
 283:   }
 284: 
 285:   /* (non-Javadoc)
 286:    * @see javax.sound.midi.Sequencer#setMicrosecondPosition(long)
 287:    */
 288:   public void setMicrosecondPosition(long microsecond)
 289:   {
 290:     // TODO Auto-generated method stub
 291: 
 292:   }
 293: 
 294:   /* (non-Javadoc)
 295:    * @see javax.sound.midi.Sequencer#setMasterSyncMode(javax.sound.midi.Sequencer.SyncMode)
 296:    */
 297:   public void setMasterSyncMode(SyncMode sync)
 298:   {
 299:     // TODO Auto-generated method stub
 300: 
 301:   }
 302: 
 303:   /* (non-Javadoc)
 304:    * @see javax.sound.midi.Sequencer#getMasterSyncMode()
 305:    */
 306:   public SyncMode getMasterSyncMode()
 307:   {
 308:     // TODO Auto-generated method stub
 309:     return null;
 310:   }
 311: 
 312:   /* (non-Javadoc)
 313:    * @see javax.sound.midi.Sequencer#getMasterSyncModes()
 314:    */
 315:   public SyncMode[] getMasterSyncModes()
 316:   {
 317:     // TODO Auto-generated method stub
 318:     return null;
 319:   }
 320: 
 321:   /* (non-Javadoc)
 322:    * @see javax.sound.midi.Sequencer#setSlaveSyncMode(javax.sound.midi.Sequencer.SyncMode)
 323:    */
 324:   public void setSlaveSyncMode(SyncMode sync)
 325:   {
 326:     // TODO Auto-generated method stub
 327: 
 328:   }
 329: 
 330:   /* (non-Javadoc)
 331:    * @see javax.sound.midi.Sequencer#getSlaveSyncMode()
 332:    */
 333:   public SyncMode getSlaveSyncMode()
 334:   {
 335:     // TODO Auto-generated method stub
 336:     return null;
 337:   }
 338: 
 339:   /* (non-Javadoc)
 340:    * @see javax.sound.midi.Sequencer#getSlaveSyncModes()
 341:    */
 342:   public SyncMode[] getSlaveSyncModes()
 343:   {
 344:     // TODO Auto-generated method stub
 345:     return null;
 346:   }
 347: 
 348:   /* (non-Javadoc)
 349:    * @see javax.sound.midi.Sequencer#setTrackMute(int, boolean)
 350:    */
 351:   public void setTrackMute(int track, boolean mute)
 352:   {
 353:     // TODO Auto-generated method stub
 354: 
 355:   }
 356: 
 357:   /* (non-Javadoc)
 358:    * @see javax.sound.midi.Sequencer#getTrackMute(int)
 359:    */
 360:   public boolean getTrackMute(int track)
 361:   {
 362:     // TODO Auto-generated method stub
 363:     return false;
 364:   }
 365: 
 366:   /* (non-Javadoc)
 367:    * @see javax.sound.midi.Sequencer#setTrackSolo(int, boolean)
 368:    */
 369:   public void setTrackSolo(int track, boolean solo)
 370:   {
 371:     // TODO Auto-generated method stub
 372: 
 373:   }
 374: 
 375:   /* (non-Javadoc)
 376:    * @see javax.sound.midi.Sequencer#getTrackSolo(int)
 377:    */
 378:   public boolean getTrackSolo(int track)
 379:   {
 380:     // TODO Auto-generated method stub
 381:     return false;
 382:   }
 383: 
 384:   /* (non-Javadoc)
 385:    * @see javax.sound.midi.Sequencer#addMetaEventListener(javax.sound.midi.MetaEventListener)
 386:    */
 387:   public boolean addMetaEventListener(MetaEventListener listener)
 388:   {
 389:     // TODO Auto-generated method stub
 390:     return false;
 391:   }
 392: 
 393:   /* (non-Javadoc)
 394:    * @see javax.sound.midi.Sequencer#removeMetaEventListener(javax.sound.midi.MetaEventListener)
 395:    */
 396:   public void removeMetaEventListener(MetaEventListener listener)
 397:   {
 398:     // TODO Auto-generated method stub
 399: 
 400:   }
 401: 
 402:   /* (non-Javadoc)
 403:    * @see javax.sound.midi.Sequencer#addControllerEventListener(javax.sound.midi.ControllerEventListener, int[])
 404:    */
 405:   public int[] addControllerEventListener(ControllerEventListener listener,
 406:                                           int[] controllers)
 407:   {
 408:     // TODO Auto-generated method stub
 409:     return null;
 410:   }
 411: 
 412:   /* (non-Javadoc)
 413:    * @see javax.sound.midi.Sequencer#removeControllerEventListener(javax.sound.midi.ControllerEventListener, int[])
 414:    */
 415:   public int[] removeControllerEventListener(ControllerEventListener listener,
 416:                                              int[] controllers)
 417:   {
 418:     // TODO Auto-generated method stub
 419:     return null;
 420:   }
 421: 
 422:   /* (non-Javadoc)
 423:    * @see javax.sound.midi.MidiDevice#getDeviceInfo()
 424:    */
 425:   public Info getDeviceInfo()
 426:   {
 427:     // TODO Auto-generated method stub
 428:     return null;
 429:   }
 430: 
 431:   /* (non-Javadoc)
 432:    * @see javax.sound.midi.MidiDevice#open()
 433:    */
 434:   public void open() throws MidiUnavailableException
 435:   {
 436:     synchronized(this)
 437:     {
 438:       // Check to see if we're open already.
 439:       if (nativeState != 0)
 440:         return;
 441: 
 442:       nativeState = open_();
 443:     }
 444:   }
 445: 
 446:   /**
 447:    * Allocate the native state object, and open the sequencer.
 448:    *
 449:    * @return a long representation of a pointer to the nativeState.
 450:    */
 451:   private native long open_();
 452: 
 453:   /**
 454:    * Close the sequencer and free the native state object.
 455:    */
 456:   private native void close_(long nativeState);
 457: 
 458:   /* (non-Javadoc)
 459:    * @see javax.sound.midi.MidiDevice#close()
 460:    */
 461:   public void close()
 462:   {
 463:     synchronized(this)
 464:     {
 465:       close_(nativeState);
 466:       nativeState = 0;
 467:     }
 468:   }
 469: 
 470:   /* (non-Javadoc)
 471:    * @see javax.sound.midi.MidiDevice#isOpen()
 472:    */
 473:   public boolean isOpen()
 474:   {
 475:     synchronized(this)
 476:     {
 477:       return (nativeState != 0);
 478:     }
 479:   }
 480: 
 481:   /* (non-Javadoc)
 482:    * @see javax.sound.midi.MidiDevice#getMaxReceivers()
 483:    */
 484:   public int getMaxReceivers()
 485:   {
 486:     return -1;
 487:   }
 488: 
 489:   /* (non-Javadoc)
 490:    * @see javax.sound.midi.MidiDevice#getMaxTransmitters()
 491:    */
 492:   public int getMaxTransmitters()
 493:   {
 494:     return -1;
 495:   }
 496: 
 497:   /* (non-Javadoc)
 498:    * @see javax.sound.midi.MidiDevice#getReceiver()
 499:    */
 500:   public Receiver getReceiver() throws MidiUnavailableException
 501:   {
 502:     // TODO Auto-generated method stub
 503:     return null;
 504:   }
 505: 
 506:   /* (non-Javadoc)
 507:    * @see javax.sound.midi.MidiDevice#getTransmitter()
 508:    */
 509:   public Transmitter getTransmitter() throws MidiUnavailableException
 510:   {
 511:     // TODO Auto-generated method stub
 512:     return null;
 513:   }
 514: 
 515: }