/[svn]/jsampler/trunk/src/org/jsampler/DefaultSamplerModel.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/DefaultSamplerModel.java

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

revision 911 by iliev, Mon Aug 7 18:25:58 2006 UTC revision 1341 by iliev, Mon Sep 10 22:29:09 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005 Grigor Kirilov Iliev   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 30  import javax.swing.SwingUtilities; Line 30  import javax.swing.SwingUtilities;
30    
31  import javax.swing.event.EventListenerList;  import javax.swing.event.EventListenerList;
32    
33  import org.jsampler.event.AudioDeviceListEvent;  import net.sf.juife.Task;
34  import org.jsampler.event.AudioDeviceListListener;  import net.sf.juife.event.TaskEvent;
35    import net.sf.juife.event.TaskListener;
36    
37    import org.jsampler.event.ListEvent;
38    import org.jsampler.event.ListListener;
39  import org.jsampler.event.MidiDeviceListEvent;  import org.jsampler.event.MidiDeviceListEvent;
40  import org.jsampler.event.MidiDeviceListListener;  import org.jsampler.event.MidiDeviceListListener;
41  import org.jsampler.event.SamplerChannelListEvent;  import org.jsampler.event.SamplerChannelListEvent;
# Line 39  import org.jsampler.event.SamplerChannel Line 43  import org.jsampler.event.SamplerChannel
43  import org.jsampler.event.SamplerEvent;  import org.jsampler.event.SamplerEvent;
44  import org.jsampler.event.SamplerListener;  import org.jsampler.event.SamplerListener;
45    
46  import org.jsampler.task.AddChannel;  import org.jsampler.task.Audio;
47    import org.jsampler.task.Channel;
48    import org.jsampler.task.Global;
49    import org.jsampler.task.Midi;
50    
51  import org.linuxsampler.lscp.*;  import org.linuxsampler.lscp.*;
52    
53    
54  /**  /**
55   * This class provides default implementation of the <code>SamplerModel</code> interface.   * This class provides default implementation of the <code>SamplerModel</code> interface.
56     * Note that the setter methods of this class does <b>not</b> alter any settings
57     * on the backend side unless otherwise specified.
58   * @author Grigor Iliev   * @author Grigor Iliev
59   */   */
60  public class DefaultSamplerModel implements SamplerModel {  public class DefaultSamplerModel implements SamplerModel {
# Line 57  public class DefaultSamplerModel impleme Line 66  public class DefaultSamplerModel impleme
66          private int totalVoiceCount = 0;          private int totalVoiceCount = 0;
67          private int totalVoiceCountMax = 0;          private int totalVoiceCountMax = 0;
68                    
69            private float volume = 1;
70            private MidiInstrumentMap defaultMidiInstrumentMap;
71            
72          private final Vector<SamplerChannelModel> channelModels = new Vector<SamplerChannelModel>();          private final Vector<SamplerChannelModel> channelModels = new Vector<SamplerChannelModel>();
73          private final Vector<AudioDeviceModel> audioDeviceModels = new Vector<AudioDeviceModel>();          private final Vector<AudioDeviceModel> audioDeviceModels = new Vector<AudioDeviceModel>();
74          private final Vector<MidiDeviceModel> midiDeviceModels = new Vector<MidiDeviceModel>();          private final Vector<MidiDeviceModel> midiDeviceModels = new Vector<MidiDeviceModel>();
75            private final Vector<MidiInstrumentMap> midiInstrMaps = new Vector<MidiInstrumentMap>();
76                    
77          private final Vector<SamplerListener> listeners = new Vector<SamplerListener>();          private final Vector<SamplerListener> listeners = new Vector<SamplerListener>();
78            private final Vector<ListListener<MidiInstrumentMap>> mapsListeners =
79                    new Vector<ListListener<MidiInstrumentMap>>();
80            
81          private final EventListenerList listenerList = new EventListenerList();          private final EventListenerList listenerList = new EventListenerList();
82                    
83                    
84          /** Creates a new instance of DefaultSamplerModel */          /** Creates a new instance of DefaultSamplerModel */
85          public          public
86          DefaultSamplerModel() {          DefaultSamplerModel() {
87                    addMidiInstrumentMapListListener(getHandler());
88          }          }
89                    
90          /**          /**
# Line 89  public class DefaultSamplerModel impleme Line 106  public class DefaultSamplerModel impleme
106           * @param listener The <code>AudioDeviceListListener</code> to register.           * @param listener The <code>AudioDeviceListListener</code> to register.
107           */           */
108          public void          public void
109          addAudioDeviceListListener(AudioDeviceListListener listener) {          addAudioDeviceListListener(ListListener<AudioDeviceModel> listener) {
110                  listenerList.add(AudioDeviceListListener.class, listener);                  listenerList.add(ListListener.class, listener);
111          }          }
112                    
113          /**          /**
# Line 98  public class DefaultSamplerModel impleme Line 115  public class DefaultSamplerModel impleme
115           * @param listener The <code>AudioDeviceListListener</code> to remove.           * @param listener The <code>AudioDeviceListListener</code> to remove.
116           */           */
117          public void          public void
118          removeAudioDeviceListListener(AudioDeviceListListener listener) {          removeAudioDeviceListListener(ListListener<AudioDeviceModel> listener) {
119                  listenerList.remove(AudioDeviceListListener.class, listener);                  listenerList.remove(ListListener.class, listener);
120          }          }
121                    
122          /**          /**
# Line 122  public class DefaultSamplerModel impleme Line 139  public class DefaultSamplerModel impleme
139                    
140          /**          /**
141           * Registers the specified listener for receiving event messages.           * Registers the specified listener for receiving event messages.
142             * @param listener The <code>ListListener</code> to register.
143             */
144            public void
145            addMidiInstrumentMapListListener(ListListener<MidiInstrumentMap> listener) {
146                    mapsListeners.add(listener);
147            }
148            
149            /**
150             * Removes the specified listener.
151             * @param listener The <code>ListListener</code> to remove.
152             */
153            public void
154            removeMidiInstrumentMapListListener(ListListener<MidiInstrumentMap> listener) {
155                    mapsListeners.remove(listener);
156            }
157            
158            /**
159             * Registers the specified listener for receiving event messages.
160           * @param listener The <code>SamplerChannelListListener</code> to register.           * @param listener The <code>SamplerChannelListListener</code> to register.
161           */           */
162          public void          public void
# Line 175  public class DefaultSamplerModel impleme Line 210  public class DefaultSamplerModel impleme
210          setAudioOutputDrivers(AudioOutputDriver[] drivers) { aoDrvS = drivers; }          setAudioOutputDrivers(AudioOutputDriver[] drivers) { aoDrvS = drivers; }
211                    
212          /**          /**
213           * Gets the model of the audio device with ID <code>deviceID</code>.           * Gets the model of the audio device with ID <code>deviceId</code>.
214           * @param deviceID The ID of the audio device whose model should be obtained.           * @param deviceId The ID of the audio device whose model should be obtained.
215           * @return The model of the specified audio device or <code>null</code>           * @return The model of the specified audio device or <code>null</code>
216           * if there is no audio device with ID <code>deviceID</code>.           * if there is no audio device with ID <code>deviceId</code>.
217           */           */
218          public AudioDeviceModel          public AudioDeviceModel
219          getAudioDeviceModel(int deviceID) {          getAudioDeviceById(int deviceId) {
220                  for(AudioDeviceModel m : audioDeviceModels)                  for(AudioDeviceModel m : audioDeviceModels)
221                          if(m.getDeviceID() == deviceID) return m;                          if(m.getDeviceId() == deviceId) return m;
222                                    
223                  return null;                  return null;
224          }          }
# Line 200  public class DefaultSamplerModel impleme Line 235  public class DefaultSamplerModel impleme
235           * @return The current list of audio device models.           * @return The current list of audio device models.
236           */           */
237          public AudioDeviceModel[]          public AudioDeviceModel[]
238          getAudioDeviceModels() {          getAudioDevices() {
239                  return audioDeviceModels.toArray(new AudioDeviceModel[audioDeviceModels.size()]);                  return audioDeviceModels.toArray(new AudioDeviceModel[audioDeviceModels.size()]);
240          }          }
241                    
# Line 217  public class DefaultSamplerModel impleme Line 252  public class DefaultSamplerModel impleme
252                    
253          /**          /**
254           * Removes the specified audio device.           * Removes the specified audio device.
255           * @param deviceID The ID of the audio device to be removed.           * @param deviceId The ID of the audio device to be removed.
256           * @return <code>true</code> if the audio device is removed successfully, <code>false</code>           * @return <code>true</code> if the audio device is removed successfully, <code>false</code>
257           * if the device list does not contain audio device with ID <code>deviceID</code>.           * if the device list does not contain audio device with ID <code>deviceId</code>.
258           */           */
259          public boolean          public boolean
260          removeAudioDevice(int deviceID) {          removeAudioDeviceById(int deviceId) {
261                  for(int i = 0; i < audioDeviceModels.size(); i++) {                  for(int i = 0; i < audioDeviceModels.size(); i++) {
262                          AudioDeviceModel m = audioDeviceModels.get(i);                          AudioDeviceModel m = audioDeviceModels.get(i);
263                          if(m.getDeviceID() == deviceID) {                          if(m.getDeviceId() == deviceId) {
264                                  audioDeviceModels.remove(i);                                  audioDeviceModels.remove(i);
265                                  fireAudioDeviceRemoved(m);                                  fireAudioDeviceRemoved(m);
266                                  return true;                                  return true;
# Line 236  public class DefaultSamplerModel impleme Line 271  public class DefaultSamplerModel impleme
271          }          }
272                    
273          /**          /**
274             * Schedules a new task for removing the specified audio device on the backend side.
275             * @param deviceId The ID of the audio device to be removed.
276             */
277            public void
278            removeBackendAudioDevice(int deviceId) {
279                    CC.getTaskQueue().add(new Audio.DestroyDevice(deviceId));
280            }
281            
282            /**
283           * Gets all MIDI input drivers currently available for the LinuxSampler instance.           * Gets all MIDI input drivers currently available for the LinuxSampler instance.
284           *           *
285           * @return <code>MidiInputDriver</code> array containing all MIDI input drivers currently           * @return <code>MidiInputDriver</code> array containing all MIDI input drivers currently
# Line 254  public class DefaultSamplerModel impleme Line 298  public class DefaultSamplerModel impleme
298          setMidiInputDrivers(MidiInputDriver[] drivers) { miDrvS = drivers; }          setMidiInputDrivers(MidiInputDriver[] drivers) { miDrvS = drivers; }
299                    
300          /**          /**
301           * Gets the model of the MIDI device with ID <code>deviceID</code>.           * Gets the model of the MIDI device with ID <code>deviceId</code>.
302           * @param deviceID The ID of the MIDI device whose model should be obtained.           * @param deviceId The ID of the MIDI device whose model should be obtained.
303           * @return The model of the specified MIDI device or <code>null</code>           * @return The model of the specified MIDI device or <code>null</code>
304           * if there is no MIDI device with ID <code>deviceID</code>.           * if there is no MIDI device with ID <code>deviceId</code>.
305           */           */
306          public MidiDeviceModel          public MidiDeviceModel
307          getMidiDeviceModel(int deviceID) {          getMidiDeviceById(int deviceId) {
308                  for(MidiDeviceModel m : midiDeviceModels)                  for(MidiDeviceModel m : midiDeviceModels)
309                          if(m.getDeviceID() == deviceID) return m;                          if(m.getDeviceId() == deviceId) return m;
310                                    
311                  return null;                  return null;
312          }          }
# Line 279  public class DefaultSamplerModel impleme Line 323  public class DefaultSamplerModel impleme
323           * @return The current list of MIDI device models.           * @return The current list of MIDI device models.
324           */           */
325          public MidiDeviceModel[]          public MidiDeviceModel[]
326          getMidiDeviceModels() {          getMidiDevices() {
327                  return midiDeviceModels.toArray(new MidiDeviceModel[midiDeviceModels.size()]);                  return midiDeviceModels.toArray(new MidiDeviceModel[midiDeviceModels.size()]);
328          }          }
329                    
# Line 295  public class DefaultSamplerModel impleme Line 339  public class DefaultSamplerModel impleme
339          }          }
340                    
341          /**          /**
342             * Schedules a new task for adding new MIDI device.
343             * @param driver The desired MIDI input system.
344             * @param parameters An optional list of driver specific parameters.
345             */
346            public void
347            addBackendMidiDevice(String driver, Parameter... parameters) {
348                    CC.getTaskQueue().add(new Midi.CreateDevice(driver, parameters));
349            }
350            
351            /**
352           * Removes the specified MIDI device.           * Removes the specified MIDI device.
353           * @param deviceID The ID of the MIDI device to be removed.           * @param deviceId The ID of the MIDI device to be removed.
354           * @return <code>true</code> if the MIDI device is removed successfully, <code>false</code>           * @return <code>true</code> if the MIDI device is removed successfully, <code>false</code>
355           * if the device list does not contain MIDI device with ID <code>deviceID</code>.           * if the device list does not contain MIDI device with ID <code>deviceId</code>.
356           */           */
357          public boolean          public boolean
358          removeMidiDevice(int deviceID) {          removeMidiDeviceById(int deviceId) {
359                  for(int i = 0; i < midiDeviceModels.size(); i++) {                  for(int i = 0; i < midiDeviceModels.size(); i++) {
360                          MidiDeviceModel m = midiDeviceModels.get(i);                          MidiDeviceModel m = midiDeviceModels.get(i);
361                          if(m.getDeviceID() == deviceID) {                          if(m.getDeviceId() == deviceId) {
362                                  midiDeviceModels.remove(i);                                  midiDeviceModels.remove(i);
363                                  fireMidiDeviceRemoved(m);                                  fireMidiDeviceRemoved(m);
364                                  return true;                                  return true;
# Line 315  public class DefaultSamplerModel impleme Line 369  public class DefaultSamplerModel impleme
369          }          }
370                    
371          /**          /**
372             * Schedules a new task for removing the specified MIDI device.
373             * @param deviceId The ID of the MIDI input device to be destroyed.
374             */
375            public void
376            removeBackendMidiDevice(int deviceId) {
377                    CC.getTaskQueue().add(new Midi.DestroyDevice(deviceId));
378            }
379            
380            /**
381             * Gets the MIDI instrument map with ID <code>mapId</code>.
382             * @param mapId The ID of the MIDI instrument map to obtain.
383             * @return The MIDI instrument map with the specified ID or <code>null</code>
384             * if there is no MIDI instrument map with ID <code>mapId</code>.
385             */
386            public MidiInstrumentMap
387            getMidiInstrumentMapById(int mapId) {
388                    for(MidiInstrumentMap m : midiInstrMaps)
389                            if(m.getMapId() == mapId) return m;
390                    
391                    return null;
392            }
393            
394            /**
395             * Gets the MIDI instrument map at the specified position.
396             * @param index The position of the MIDI instrument map to return.
397             * @return The MIDI instrument map at the specified position.
398             */
399            public MidiInstrumentMap
400            getMidiInstrumentMap(int index) {
401                    return midiInstrMaps.get(index);
402            }
403            
404            /**
405             * Gets the current number of MIDI instrument maps.
406             * @return The current number of MIDI instrument maps.
407             */
408            public int
409            getMidiInstrumentMapCount() { return midiInstrMaps.size(); }
410            
411            /**
412             * Gets the current list of MIDI instrument maps.
413             * @return The current list of MIDI instrument maps.
414             */
415            public MidiInstrumentMap[]
416            getMidiInstrumentMaps() {
417                    return midiInstrMaps.toArray(new MidiInstrumentMap[midiInstrMaps.size()]);
418            }
419            
420            /**
421             * Gets the position of the specified MIDI instrument map in the list.
422             * @param map The map whose index should be returned.
423             * @return The position of the specified map in the list,
424             * or -1 if <code>map</code> is <code>null</code> or
425             * the map list does not contain the specified map.
426             */
427            public int
428            getMidiInstrumentMapIndex(MidiInstrumentMap map) {
429                    if(map == null) return -1;
430                    
431                    for(int i = 0; i < getMidiInstrumentMapCount(); i++) {
432                            if(getMidiInstrumentMap(i) == map) return i;
433                    }
434                    
435                    return -1;
436            }
437            
438            /**
439             * Adds the specified MIDI instrument map.
440             * @param map The MIDI instrument map to be added.
441             * @throws IllegalArgumentException If <code>map</code> is <code>null</code>.
442             */
443            public void
444            addMidiInstrumentMap(MidiInstrumentMap map) {
445                    if(map == null) throw new IllegalArgumentException("map should be non-null!");
446                    
447                    midiInstrMaps.add(map);
448                    fireMidiInstrumentMapAdded(map);
449            }
450            
451            /**
452             * Schedules a new task for creating a new MIDI instrument map on the backend side.
453             * @param name The name of the MIDI instrument map.
454             * @throws IllegalArgumentException If <code>name</code> is <code>null</code>.
455             */
456            public void
457            addBackendMidiInstrumentMap(String name) {
458                    if(name == null) throw new IllegalArgumentException("name should be non-null!");
459                    
460                    CC.getTaskQueue().add(new Midi.AddInstrumentMap(name));
461            }
462            
463            /**
464             * Removes the specified MIDI instrument map.
465             * @param mapId The ID of the MIDI instrument map to be removed.
466             * @return <code>true</code> if the MIDI instrument map is removed successfully,
467             * <code>false</code> if the MIDI instrument map's list does not contain
468             * MIDI instrument map with ID <code>mapId</code>.
469             */
470            public boolean
471            removeMidiInstrumentMapById(int mapId) {
472                    for(int i = 0; i < midiInstrMaps.size(); i++) {
473                            MidiInstrumentMap m = getMidiInstrumentMap(i);
474                            if(m.getMapId() == mapId) {
475                                    midiInstrMaps.remove(i);
476                                    fireMidiInstrumentMapRemoved(m);
477                                    return true;
478                            }
479                    }
480                    
481                    return false;
482            }
483            
484            /**
485             * Removes the specified MIDI instrument map.
486             * @param map The MIDI instrument map to remove.
487             * @return <code>true</code> if the specified MIDI instrument map was in the list,
488             * <code>false</code> otherwise.
489             */
490            public boolean
491            removeMidiInstrumentMap(MidiInstrumentMap map) {
492                    boolean b = midiInstrMaps.removeElement(map);
493                    if(b) fireMidiInstrumentMapRemoved(map);
494                    return b;
495            }
496            
497            /** Removes all MIDI instrument maps. */
498            public void
499            removeAllMidiInstrumentMaps() {
500                    for(int i = midiInstrMaps.size() - 1; i >= 0; i--) {
501                            MidiInstrumentMap map = midiInstrMaps.get(i);
502                            midiInstrMaps.removeElementAt(i);
503                            fireMidiInstrumentMapRemoved(map);
504                    }
505            }
506            
507            /**
508             * Schedules a new task for removing the
509             * specified MIDI instrument map on the backend side.
510             * @param mapId The numerical ID of the MIDI instrument map to remove.
511             */
512            public void
513            removeBackendMidiInstrumentMap(int mapId) {
514                    CC.getTaskQueue().add(new Midi.RemoveInstrumentMap(mapId));
515            }
516            
517            /**
518             * Schedules a new task for changing the name of
519             * the specified MIDI instrument map on the backend side.
520             * @param mapId The numerical ID of the MIDI instrument map.
521             * @param name The new name for the specified MIDI instrument map.
522             */
523            public void
524            setBackendMidiInstrumentMapName(final int mapId, String name) {
525                    final Task t = new Midi.SetInstrumentMapInfo(mapId, name);
526                    
527                    t.addTaskListener(new TaskListener() {
528                            public void
529                            taskPerformed(TaskEvent e) {
530                                    /*
531                                     * Because with the invokation of the method the task is considered
532                                     * to be done, if the task fails, we must update the settings.
533                                     */
534                                    if(t.doneWithErrors()) {
535                                            Task t2 = new Midi.UpdateInstrumentMapInfo(mapId);
536                                            CC.getTaskQueue().add(t2);
537                                    }
538                            }
539                    });
540                    CC.getTaskQueue().add(t);
541            }
542            
543            /**
544             * Gets the default MIDI instrument map.
545             * @return The default MIDI instrument map or <code>null</code>
546             * if there are no maps created.
547             */
548            public MidiInstrumentMap
549            getDefaultMidiInstrumentMap() {
550                    return defaultMidiInstrumentMap;
551            }
552            
553            /**
554             * Gets the default MIDI instrument map.
555             * @return The default MIDI instrument map or <code>null</code>
556             * if there are no maps created.
557             */
558            private MidiInstrumentMap
559            findDefaultMidiInstrumentMap() {
560                    for(int i = 0; i < getMidiInstrumentMapCount(); i++) {
561                            MidiInstrumentMap m = getMidiInstrumentMap(i);
562                            if(m.getInfo().isDefault()) return m;
563                    }
564                    
565                    return null;
566            }
567            
568            /**
569             * Schedules a new task for mapping a MIDI instrument on the backend side.
570             * @param mapId The id of the MIDI instrument map.
571             * @param bank The index of the MIDI bank, which shall contain the instrument.
572             * @param program The MIDI program number of the new instrument.
573             * @param instrInfo Provides the MIDI instrument settings.
574             */
575            public void
576            mapBackendMidiInstrument(int mapId, int bank, int program, MidiInstrumentInfo instrInfo) {
577                    CC.getTaskQueue().add(new Midi.MapInstrument(mapId, bank, program, instrInfo));
578            }
579            
580            /**
581             * Schedules a new task for removing a MIDI instrument on the backend side.
582             * @param mapId The id of the MIDI instrument map containing the instrument to be removed.
583             * @param bank The index of the MIDI bank containing the instrument to be removed.
584             * @param program The MIDI program number of the instrument to be removed.
585             */
586            public void
587            unmapBackendMidiInstrument(int mapId, int bank, int program) {
588                    CC.getTaskQueue().add(new Midi.UnmapInstrument(mapId, bank, program));
589            }
590            
591            /**
592           * Gets a list of all available engines.           * Gets a list of all available engines.
593           * @return A list of all available engines.           * @return A list of all available engines.
594           */           */
# Line 329  public class DefaultSamplerModel impleme Line 603  public class DefaultSamplerModel impleme
603          setEngines(SamplerEngine[] engines) { this.engines = engines; }          setEngines(SamplerEngine[] engines) { this.engines = engines; }
604                    
605          /**          /**
606           * Gets the model of the sampler channel with ID <code>channelID</code>.           * Gets the model of the sampler channel with ID <code>channelId</code>.
607           * @param channelID The ID of the sampler channel whose model should be obtained.           * @param channelId The ID of the sampler channel whose model should be obtained.
608           * @return The model of the specified sampler channel or <code>null</code>           * @return The model of the specified sampler channel or <code>null</code>
609           * if there is no channel with ID <code>channelID</code>.           * if there is no channel with ID <code>channelId</code>.
610           */           */
611          public SamplerChannelModel          public SamplerChannelModel
612          getChannelModel(int channelID) {          getChannelById(int channelId) {
613                  for(SamplerChannelModel m : channelModels)                  for(SamplerChannelModel m : channelModels)
614                          if(m.getChannelID() == channelID) return m;                          if(m.getChannelId() == channelId) return m;
615                                    
616                  return null;                  return null;
617          }          }
# Line 354  public class DefaultSamplerModel impleme Line 628  public class DefaultSamplerModel impleme
628           * @return The current list of sampler channel models.           * @return The current list of sampler channel models.
629           */           */
630          public SamplerChannelModel[]          public SamplerChannelModel[]
631          getChannelModels() {          getChannels() {
632                  return channelModels.toArray(new SamplerChannelModel[channelModels.size()]);                  return channelModels.toArray(new SamplerChannelModel[channelModels.size()]);
633          }          }
634                    
635          /**          /**
636           * Creates a new sampler channel. The channel will be actually added to this model           * Schedules a new task for adding a new sampler channel on the
637           * when the back-end notifies for its creation.           * backend side. The channel will be actually added to this model
638             * when the backend notifies for its creation.
639           * @see #addChannel           * @see #addChannel
640           */           */
641          public void          public void
642          createChannel() {          addBackendChannel() {
643                  CC.getTaskQueue().add(new AddChannel());                  CC.getTaskQueue().add(new Channel.Add());
644                  // We leave this event to be notified by the LinuxSampler notification system.                  // We leave this event to be notified by the LinuxSampler notification system.
645          }          }
646                    
# Line 386  public class DefaultSamplerModel impleme Line 661  public class DefaultSamplerModel impleme
661           * for the channel.           * for the channel.
662           */           */
663          public void          public void
664          changeChannel(SamplerChannel channel) {          updateChannel(SamplerChannel channel) {
665                  for(SamplerChannelModel m : channelModels) {                  for(SamplerChannelModel m : channelModels) {
666                          if(m.getChannelID() == channel.getChannelID()) {                          if(m.getChannelId() == channel.getChannelId()) {
667                                  m.setChannelInfo(channel);                                  m.setChannelInfo(channel);
668                                  return;                                  return;
669                          }                          }
670                  }                  }
671                                    
672                  CC.getLogger().log (                  CC.getLogger().log (
673                          Level.WARNING, "DefaultSamplerModel.unknownChannel!", channel.getChannelID()                          Level.WARNING, "DefaultSamplerModel.unknownChannel!", channel.getChannelId()
674                  );                  );
675          }          }
676                    
677          /**          /**
678           * Removes the specified sampler channel.           * Removes the specified sampler channel.
679           * @param channelID The ID of the channel to be removed.           * @param channelId The ID of the channel to be removed.
680           * @return <code>true</code> if the channel is removed successfully, <code>false</code>           * @return <code>true</code> if the channel is removed successfully, <code>false</code>
681           * if the channel's list does not contain channel with ID <code>channelID</code>.           * if the channel's list does not contain channel with ID <code>channelId</code>.
682           */           */
683          public boolean          public boolean
684          removeChannel(int channelID) {          removeChannelById(int channelId) {
685                  for(int i = 0; i < channelModels.size(); i++) {                  for(int i = 0; i < channelModels.size(); i++) {
686                          SamplerChannelModel m = channelModels.get(i);                          SamplerChannelModel m = channelModels.get(i);
687                          if(m.getChannelID() == channelID) {                          if(m.getChannelId() == channelId) {
688                                  channelModels.remove(i);                                  channelModels.remove(i);
689                                  fireSamplerChannelRemoved(m);                                  fireSamplerChannelRemoved(m);
690                                  return true;                                  return true;
# Line 420  public class DefaultSamplerModel impleme Line 695  public class DefaultSamplerModel impleme
695          }          }
696                    
697          /**          /**
698             * Schedules a new task for removing the specified sampler channel on the backend side.
699             * @param channelId The ID of the channel to be removed.
700             */
701            public void
702            removeBackendChannel(int channelId) {
703                    CC.getTaskQueue().add(new Channel.Remove(channelId));
704            }
705            
706            /**
707             * Schedules a new task for starting an instrument editor for editing
708             * the loaded instrument on the specified sampler channel.
709             * @param channelId The sampler channel number.
710             */
711            public void
712            editBackendInstrument(int channelId) {
713                    CC.getTaskQueue().add(new Channel.EditInstrument(channelId));
714            }
715            
716            /**
717           * Determines whether there is at least one solo channel in the current list           * Determines whether there is at least one solo channel in the current list
718           * of sampler channels.           * of sampler channels.
719           * @return <code>true</code> if there is at least one solo channel in the current list of           * @return <code>true</code> if there is at least one solo channel in the current list of
# Line 488  public class DefaultSamplerModel impleme Line 782  public class DefaultSamplerModel impleme
782          getTotalVoiceCountMax() { return totalVoiceCountMax; }          getTotalVoiceCountMax() { return totalVoiceCountMax; }
783                    
784          /**          /**
785             * Gets the golobal volume of the sampler.
786             * @return The golobal volume of the sampler.
787             */
788            public float
789            getVolume() { return volume; }
790            
791            /**
792             * Sets the global volume.
793             * @param volume The new volume value.
794             */
795            public void
796            setVolume(float volume) {
797                    if(this.volume == volume) return;
798                    
799                    this.volume = volume;
800                    fireVolumeChanged();
801            }
802            
803            /**
804             * Schedules a new task for setting the global volume on the backend side.
805             * @param volume The new volume value.
806             */
807            public void
808            setBackendVolume(float volume) {
809                    CC.getTaskQueue().add(new Global.SetVolume(volume));
810            }
811            
812            /**
813             * Schedules a new task for resetting the sampler.
814             */
815            public void
816            resetBackend() { CC.getTaskQueue().add(new org.jsampler.task.Global.ResetSampler()); }
817            
818            /**
819           * Updates the current and the maximum number of active voices in the sampler.           * Updates the current and the maximum number of active voices in the sampler.
820           * @param count The new number of active voices.           * @param count The new number of active voices.
821           * @param countMax The maximum number of active voices.           * @param countMax The maximum number of active voices.
# Line 503  public class DefaultSamplerModel impleme Line 831  public class DefaultSamplerModel impleme
831                    
832          /**          /**
833           * Notifies listeners that a sampler channel has been added.           * Notifies listeners that a sampler channel has been added.
834             * This method can be invoked outside the event-dispatching thread.
835           * @param channelModel A <code>SamplerChannelModel</code> instance.           * @param channelModel A <code>SamplerChannelModel</code> instance.
836           */           */
837          private void          private void
# Line 516  public class DefaultSamplerModel impleme Line 845  public class DefaultSamplerModel impleme
845          }          }
846          /**          /**
847           * Notifies listeners that a sampler channel has been added.           * Notifies listeners that a sampler channel has been added.
          * This method should be invoked from the event-dispatching thread.  
848           */           */
849          private void          private void
850          fireSamplerChannelAdded(SamplerChannelListEvent e) {          fireSamplerChannelAdded(SamplerChannelListEvent e) {
# Line 531  public class DefaultSamplerModel impleme Line 859  public class DefaultSamplerModel impleme
859                    
860          /**          /**
861           * Notifies listeners that a sampler channel has been removed.           * Notifies listeners that a sampler channel has been removed.
862             * This method can be invoked outside the event-dispatching thread.
863           * @param channelModel A <code>SamplerChannelModel</code> instance.           * @param channelModel A <code>SamplerChannelModel</code> instance.
864           */           */
865          private void          private void
# Line 545  public class DefaultSamplerModel impleme Line 874  public class DefaultSamplerModel impleme
874                    
875          /**          /**
876           * Notifies listeners that a sampler channel has been removed.           * Notifies listeners that a sampler channel has been removed.
          * This method should be invoked from the event-dispatching thread.  
877           */           */
878          private void          private void
879          fireSamplerChannelRemoved(SamplerChannelListEvent e) {          fireSamplerChannelRemoved(SamplerChannelListEvent e) {
# Line 560  public class DefaultSamplerModel impleme Line 888  public class DefaultSamplerModel impleme
888                    
889          /**          /**
890           * Notifies listeners that a MIDI device has been added.           * Notifies listeners that a MIDI device has been added.
891             * This method can be invoked outside the event-dispatching thread.
892           * @param model A <code>MidiDeviceModel</code> instance.           * @param model A <code>MidiDeviceModel</code> instance.
893           */           */
894          private void          private void
# Line 573  public class DefaultSamplerModel impleme Line 902  public class DefaultSamplerModel impleme
902          }          }
903          /**          /**
904           * Notifies listeners that a MIDI device has been added.           * Notifies listeners that a MIDI device has been added.
          * This method should be invoked from the event-dispatching thread.  
905           */           */
906          private void          private void
907          fireMidiDeviceAdded(MidiDeviceListEvent e) {          fireMidiDeviceAdded(MidiDeviceListEvent e) {
# Line 588  public class DefaultSamplerModel impleme Line 916  public class DefaultSamplerModel impleme
916                    
917          /**          /**
918           * Notifies listeners that a MIDI device has been removed.           * Notifies listeners that a MIDI device has been removed.
919             * This method can be invoked outside the event-dispatching thread.
920           * @param model A <code>MidiDeviceModel</code> instance.           * @param model A <code>MidiDeviceModel</code> instance.
921           */           */
922          private void          private void
# Line 602  public class DefaultSamplerModel impleme Line 931  public class DefaultSamplerModel impleme
931                    
932          /**          /**
933           * Notifies listeners that a MIDI device has been removed.           * Notifies listeners that a MIDI device has been removed.
          * This method should be invoked from the event-dispatching thread.  
934           */           */
935          private void          private void
936          fireMidiDeviceRemoved(MidiDeviceListEvent e) {          fireMidiDeviceRemoved(MidiDeviceListEvent e) {
# Line 617  public class DefaultSamplerModel impleme Line 945  public class DefaultSamplerModel impleme
945                    
946          /**          /**
947           * Notifies listeners that an audio device has been added.           * Notifies listeners that an audio device has been added.
948             * This method can be invoked outside the event-dispatching thread.
949           * @param model A <code>AudioDeviceModel</code> instance.           * @param model A <code>AudioDeviceModel</code> instance.
950           */           */
951          private void          private void
952          fireAudioDeviceAdded(AudioDeviceModel model) {          fireAudioDeviceAdded(AudioDeviceModel model) {
953                  final AudioDeviceListEvent e = new AudioDeviceListEvent(this, model);                  final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model);
954                                                    
955                  SwingUtilities.invokeLater(new Runnable() {                  SwingUtilities.invokeLater(new Runnable() {
956                          public void                          public void
# Line 631  public class DefaultSamplerModel impleme Line 960  public class DefaultSamplerModel impleme
960                    
961          /**          /**
962           * Notifies listeners that an audio device has been added.           * Notifies listeners that an audio device has been added.
          * This method should be invoked from the event-dispatching thread.  
963           */           */
964          private void          private void
965          fireAudioDeviceAdded(AudioDeviceListEvent e) {          fireAudioDeviceAdded(ListEvent<AudioDeviceModel> e) {
966                  Object[] listeners = listenerList.getListenerList();                  Object[] listeners = listenerList.getListenerList();
967                                    
968                  for(int i = listeners.length - 2; i >= 0; i -= 2) {                  for(int i = listeners.length - 2; i >= 0; i -= 2) {
969                          if(listeners[i] == AudioDeviceListListener.class) {                          if(listeners[i] == ListListener.class) {
970                                  ((AudioDeviceListListener)listeners[i + 1]).deviceAdded(e);                                  ((ListListener<AudioDeviceModel>)listeners[i + 1]).entryAdded(e);
971                          }                          }
972                  }                  }
973          }          }
974                    
975          /**          /**
976           * Notifies listeners that an audio device has been removed.           * Notifies listeners that an audio device has been removed.
977             * This method can be invoked outside the event-dispatching thread.
978           * @param model A <code>AudioDeviceModel</code> instance.           * @param model A <code>AudioDeviceModel</code> instance.
979           */           */
980          private void          private void
981          fireAudioDeviceRemoved(AudioDeviceModel model) {          fireAudioDeviceRemoved(AudioDeviceModel model) {
982                  final AudioDeviceListEvent e = new AudioDeviceListEvent(this, model);                  final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model);
983                                                    
984                  SwingUtilities.invokeLater(new Runnable() {                  SwingUtilities.invokeLater(new Runnable() {
985                          public void                          public void
# Line 659  public class DefaultSamplerModel impleme Line 988  public class DefaultSamplerModel impleme
988          }          }
989                    
990          /**          /**
991             * Notifies listeners that a MIDI instrument map has been added to the list.
992             * This method can be invoked outside the event-dispatching thread.
993             */
994            private void
995            fireMidiInstrumentMapAdded(MidiInstrumentMap map) {
996                    final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map);
997                    
998                    SwingUtilities.invokeLater(new Runnable() {
999                            public void
1000                            run() { fireMidiInstrumentMapAdded(e); }
1001                    });
1002            }
1003            
1004            /** Notifies listeners that a MIDI instrument map has been added to the list. */
1005            private void
1006            fireMidiInstrumentMapAdded(ListEvent<MidiInstrumentMap> e) {
1007                    for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryAdded(e);
1008            }
1009            
1010            /**
1011             * Notifies listeners that a MIDI instrument map has been removed from the list.
1012             * This method can be invoked outside the event-dispatching thread.
1013             */
1014            private void
1015            fireMidiInstrumentMapRemoved(MidiInstrumentMap map) {
1016                    final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map);
1017                    
1018                    SwingUtilities.invokeLater(new Runnable() {
1019                            public void
1020                            run() { fireMidiInstrumentMapRemoved(e); }
1021                    });
1022            }
1023            /** Notifies listeners that a MIDI instrument map has been removed from the list. */
1024            private void
1025            fireMidiInstrumentMapRemoved(ListEvent<MidiInstrumentMap> e) {
1026                    for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryRemoved(e);
1027            }
1028            
1029            
1030            /**
1031           * Notifies listeners that an audio device has been removed.           * Notifies listeners that an audio device has been removed.
1032           * This method should be invoked from the event-dispatching thread.           * This method should be invoked from the event-dispatching thread.
1033           */           */
1034          private void          private void
1035          fireAudioDeviceRemoved(AudioDeviceListEvent e) {          fireAudioDeviceRemoved(ListEvent<AudioDeviceModel> e) {
1036                  Object[] listeners = listenerList.getListenerList();                  Object[] listeners = listenerList.getListenerList();
1037                                    
1038                  for(int i = listeners.length - 2; i >= 0; i -= 2) {                  for(int i = listeners.length - 2; i >= 0; i -= 2) {
1039                          if(listeners[i] == AudioDeviceListListener.class) {                          if(listeners[i] == ListListener.class) {
1040                                  ((AudioDeviceListListener)listeners[i + 1]).deviceRemoved(e);                                  ((ListListener<AudioDeviceModel>)listeners[i + 1]).entryRemoved(e);
1041                          }                          }
1042                  }                  }
1043          }          }
1044                    
1045          /** Notifies listeners that the total number of active voices has changed. */          /**
1046             * Notifies listeners that the global volume has changed.
1047             * This method can be invoked outside the event-dispatching thread.
1048             */
1049            private void
1050            fireVolumeChanged() {
1051                    final SamplerEvent e = new SamplerEvent(this);
1052                            
1053                    SwingUtilities.invokeLater(new Runnable() {
1054                            public void
1055                            run() { fireVolumeChanged(e); }
1056                    });
1057            }
1058            
1059            /**
1060             * Notifies listeners that the global volume has changed.
1061             */
1062            private void
1063            fireVolumeChanged(SamplerEvent e) {
1064                    for(SamplerListener l : listeners) l.volumeChanged(e);
1065            }
1066            
1067            /*
1068             * Notifies listeners that the total number of active voices has changed.
1069             * This method can be invoked outside the event-dispatching thread.
1070             */
1071          private void          private void
1072          fireTotalVoiceCountChanged() {          fireTotalVoiceCountChanged() {
1073                  final SamplerEvent e = new SamplerEvent(this);                  final SamplerEvent e = new SamplerEvent(this);
# Line 686  public class DefaultSamplerModel impleme Line 1080  public class DefaultSamplerModel impleme
1080                    
1081          /**          /**
1082           * Notifies listeners that the total number of active voices has changed.           * Notifies listeners that the total number of active voices has changed.
          * This method should be invoked from the event-dispatching thread.  
1083           */           */
1084          private void          private void
1085          fireTotalVoiceCountChanged(SamplerEvent e) {          fireTotalVoiceCountChanged(SamplerEvent e) {
1086                  for(SamplerListener l : listeners) l.totalVoiceCountChanged(e);                  for(SamplerListener l : listeners) l.totalVoiceCountChanged(e);
1087          }          }
1088            
1089            /**
1090             * Notifies listeners that the global volume has changed.
1091             */
1092            private void
1093            fireDefaultMapChanged() {
1094                    SamplerEvent e = new SamplerEvent(this);
1095                    for(SamplerListener l : listeners) l.defaultMapChanged(e);
1096            }
1097            
1098            private final Handler handler = new Handler();
1099            
1100            private Handler
1101            getHandler() { return handler; }
1102            
1103            private class Handler implements ListListener<MidiInstrumentMap> {
1104                    /** Invoked when a new map is added to a list. */
1105                    public void
1106                    entryAdded(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); }
1107                    
1108                    /** Invoked when a map is removed from a list. */
1109                    public void
1110                    entryRemoved(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); }
1111                    
1112                    private void
1113                    updateDefaultMap() {
1114                            if(getDefaultMidiInstrumentMap() != findDefaultMidiInstrumentMap()) {
1115                                    defaultMidiInstrumentMap = findDefaultMidiInstrumentMap();
1116                                    fireDefaultMapChanged();
1117                            }
1118                    }
1119            }
1120  }  }

Legend:
Removed from v.911  
changed lines
  Added in v.1341

  ViewVC Help
Powered by ViewVC