/[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 1142 by iliev, Mon Aug 7 18:25:58 2006 UTC revision 1143 by iliev, Mon Apr 2 21:18:31 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) {          getAudioDeviceModel(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 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) {          removeAudioDevice(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) {          getMidiDeviceModel(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 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) {          removeMidiDevice(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             * Adds the specified MIDI instrument map.
422             * @param map The MIDI instrument map to be added.
423             * @throws IllegalArgumentException If <code>map</code> is <code>null</code>.
424             */
425            public void
426            addMidiInstrumentMap(MidiInstrumentMap map) {
427                    if(map == null) throw new IllegalArgumentException("map should be non-null!");
428                    
429                    midiInstrMaps.add(map);
430                    fireMidiInstrumentMapAdded(map);
431            }
432            
433            /**
434             * Schedules a new task for creating a new MIDI instrument map on the backend side.
435             * @param name The name of the MIDI instrument map.
436             * @throws IllegalArgumentException If <code>name</code> is <code>null</code>.
437             */
438            public void
439            addBackendMidiInstrumentMap(String name) {
440                    if(name == null) throw new IllegalArgumentException("name should be non-null!");
441                    
442                    CC.getTaskQueue().add(new Midi.AddInstrumentMap(name));
443            }
444            
445            /**
446             * Removes the specified MIDI instrument map.
447             * @param mapId The ID of the MIDI instrument map to be removed.
448             * @return <code>true</code> if the MIDI instrument map is removed successfully,
449             * <code>false</code> if the MIDI instrument map's list does not contain
450             * MIDI instrument map with ID <code>mapId</code>.
451             */
452            public boolean
453            removeMidiInstrumentMap(int mapId) {
454                    for(int i = 0; i < midiInstrMaps.size(); i++) {
455                            MidiInstrumentMap m = getMidiInstrumentMap(i);
456                            if(m.getMapId() == mapId) {
457                                    midiInstrMaps.remove(i);
458                                    fireMidiInstrumentMapRemoved(m);
459                                    return true;
460                            }
461                    }
462                    
463                    return false;
464            }
465            
466            /**
467             * Removes the specified MIDI instrument map.
468             * @param map The MIDI instrument map to remove.
469             * @return <code>true</code> if the specified MIDI instrument map was in the list,
470             * <code>false</code> otherwise.
471             */
472            public boolean
473            removeMidiInstrumentMap(MidiInstrumentMap map) {
474                    boolean b = midiInstrMaps.removeElement(map);
475                    if(b) fireMidiInstrumentMapRemoved(map);
476                    return b;
477            }
478            
479            /** Removes all MIDI instrument maps. */
480            public void
481            removeAllMidiInstrumentMaps() {
482                    for(int i = midiInstrMaps.size() - 1; i >= 0; i--) {
483                            MidiInstrumentMap map = midiInstrMaps.get(i);
484                            midiInstrMaps.removeElementAt(i);
485                            fireMidiInstrumentMapRemoved(map);
486                    }
487            }
488            
489            /**
490             * Schedules a new task for removing the
491             * specified MIDI instrument map on the backend side.
492             * @param mapId The numerical ID of the MIDI instrument map to remove.
493             */
494            public void
495            removeBackendMidiInstrumentMap(int mapId) {
496                    CC.getTaskQueue().add(new Midi.RemoveInstrumentMap(mapId));
497            }
498            
499            /**
500             * Schedules a new task for changing the name of
501             * the specified MIDI instrument map on the backend side.
502             * @param mapId The numerical ID of the MIDI instrument map.
503             * @param name The new name for the specified MIDI instrument map.
504             */
505            public void
506            setBackendMidiInstrumentMapName(final int mapId, String name) {
507                    final Task t = new Midi.SetInstrumentMapInfo(mapId, name);
508                    
509                    t.addTaskListener(new TaskListener() {
510                            public void
511                            taskPerformed(TaskEvent e) {
512                                    /*
513                                     * Because with the invokation of the method the task is considered
514                                     * to be done, if the task fails, we must update the settings.
515                                     */
516                                    if(t.doneWithErrors()) {
517                                            Task t2 = new Midi.UpdateInstrumentMapInfo(mapId);
518                                            CC.getTaskQueue().add(t2);
519                                    }
520                            }
521                    });
522                    CC.getTaskQueue().add(t);
523            }
524            
525            /**
526             * Gets the default MIDI instrument map.
527             * @return The default MIDI instrument map or <code>null</code>
528             * if there are no maps created.
529             */
530            public MidiInstrumentMap
531            getDefaultMidiInstrumentMap() {
532                    return defaultMidiInstrumentMap;
533            }
534            
535            /**
536             * Gets the default MIDI instrument map.
537             * @return The default MIDI instrument map or <code>null</code>
538             * if there are no maps created.
539             */
540            private MidiInstrumentMap
541            findDefaultMidiInstrumentMap() {
542                    for(int i = 0; i < getMidiInstrumentMapCount(); i++) {
543                            MidiInstrumentMap m = getMidiInstrumentMap(i);
544                            if(m.getInfo().isDefault()) return m;
545                    }
546                    
547                    return null;
548            }
549            
550            /**
551             * Schedules a new task for mapping a MIDI instrument on the backend side.
552             * @param mapId The id of the MIDI instrument map.
553             * @param bank The index of the MIDI bank, which shall contain the instrument.
554             * @param program The MIDI program number of the new instrument.
555             * @param instrInfo Provides the MIDI instrument settings.
556             */
557            public void
558            mapBackendMidiInstrument(int mapId, int bank, int program, MidiInstrumentInfo instrInfo) {
559                    CC.getTaskQueue().add(new Midi.MapInstrument(mapId, bank, program, instrInfo));
560            }
561            
562            /**
563             * Schedules a new task for removing a MIDI instrument on the backend side.
564             * @param mapId The id of the MIDI instrument map containing the instrument to be removed.
565             * @param bank The index of the MIDI bank containing the instrument to be removed.
566             * @param program The MIDI program number of the instrument to be removed.
567             */
568            public void
569            unmapBackendMidiInstrument(int mapId, int bank, int program) {
570                    CC.getTaskQueue().add(new Midi.UnmapInstrument(mapId, bank, program));
571            }
572            
573            /**
574           * Gets a list of all available engines.           * Gets a list of all available engines.
575           * @return A list of all available engines.           * @return A list of all available engines.
576           */           */
# Line 329  public class DefaultSamplerModel impleme Line 585  public class DefaultSamplerModel impleme
585          setEngines(SamplerEngine[] engines) { this.engines = engines; }          setEngines(SamplerEngine[] engines) { this.engines = engines; }
586                    
587          /**          /**
588           * Gets the model of the sampler channel with ID <code>channelID</code>.           * Gets the model of the sampler channel with ID <code>channelId</code>.
589           * @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.
590           * @return The model of the specified sampler channel or <code>null</code>           * @return The model of the specified sampler channel or <code>null</code>
591           * if there is no channel with ID <code>channelID</code>.           * if there is no channel with ID <code>channelId</code>.
592           */           */
593          public SamplerChannelModel          public SamplerChannelModel
594          getChannelModel(int channelID) {          getChannelModel(int channelId) {
595                  for(SamplerChannelModel m : channelModels)                  for(SamplerChannelModel m : channelModels)
596                          if(m.getChannelID() == channelID) return m;                          if(m.getChannelId() == channelId) return m;
597                                    
598                  return null;                  return null;
599          }          }
# Line 359  public class DefaultSamplerModel impleme Line 615  public class DefaultSamplerModel impleme
615          }          }
616                    
617          /**          /**
618           * 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
619           * when the back-end notifies for its creation.           * backend side. The channel will be actually added to this model
620             * when the backend notifies for its creation.
621           * @see #addChannel           * @see #addChannel
622           */           */
623          public void          public void
624          createChannel() {          addBackendChannel() {
625                  CC.getTaskQueue().add(new AddChannel());                  CC.getTaskQueue().add(new Channel.Add());
626                  // We leave this event to be notified by the LinuxSampler notification system.                  // We leave this event to be notified by the LinuxSampler notification system.
627          }          }
628                    
# Line 386  public class DefaultSamplerModel impleme Line 643  public class DefaultSamplerModel impleme
643           * for the channel.           * for the channel.
644           */           */
645          public void          public void
646          changeChannel(SamplerChannel channel) {          updateChannel(SamplerChannel channel) {
647                  for(SamplerChannelModel m : channelModels) {                  for(SamplerChannelModel m : channelModels) {
648                          if(m.getChannelID() == channel.getChannelID()) {                          if(m.getChannelId() == channel.getChannelId()) {
649                                  m.setChannelInfo(channel);                                  m.setChannelInfo(channel);
650                                  return;                                  return;
651                          }                          }
652                  }                  }
653                                    
654                  CC.getLogger().log (                  CC.getLogger().log (
655                          Level.WARNING, "DefaultSamplerModel.unknownChannel!", channel.getChannelID()                          Level.WARNING, "DefaultSamplerModel.unknownChannel!", channel.getChannelId()
656                  );                  );
657          }          }
658                    
659          /**          /**
660           * Removes the specified sampler channel.           * Removes the specified sampler channel.
661           * @param channelID The ID of the channel to be removed.           * @param channelId The ID of the channel to be removed.
662           * @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>
663           * 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>.
664           */           */
665          public boolean          public boolean
666          removeChannel(int channelID) {          removeChannel(int channelId) {
667                  for(int i = 0; i < channelModels.size(); i++) {                  for(int i = 0; i < channelModels.size(); i++) {
668                          SamplerChannelModel m = channelModels.get(i);                          SamplerChannelModel m = channelModels.get(i);
669                          if(m.getChannelID() == channelID) {                          if(m.getChannelId() == channelId) {
670                                  channelModels.remove(i);                                  channelModels.remove(i);
671                                  fireSamplerChannelRemoved(m);                                  fireSamplerChannelRemoved(m);
672                                  return true;                                  return true;
# Line 420  public class DefaultSamplerModel impleme Line 677  public class DefaultSamplerModel impleme
677          }          }
678                    
679          /**          /**
680             * Schedules a new task for removing the specified sampler channel on the backend side.
681             * @param channelId The ID of the channel to be removed.
682             */
683            public void
684            removeBackendChannel(int channelId) {
685                    CC.getTaskQueue().add(new org.jsampler.task.Channel.Remove(channelId));
686            }
687            
688            /**
689           * 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
690           * of sampler channels.           * of sampler channels.
691           * @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 754  public class DefaultSamplerModel impleme
754          getTotalVoiceCountMax() { return totalVoiceCountMax; }          getTotalVoiceCountMax() { return totalVoiceCountMax; }
755                    
756          /**          /**
757             * Gets the golobal volume of the sampler.
758             * @return The golobal volume of the sampler.
759             */
760            public float
761            getVolume() { return volume; }
762            
763            /**
764             * Sets the global volume.
765             * @param volume The new volume value.
766             */
767            public void
768            setVolume(float volume) {
769                    if(this.volume == volume) return;
770                    
771                    this.volume = volume;
772                    fireVolumeChanged();
773            }
774            
775            /**
776             * Schedules a new task for setting the global volume on the backend side.
777             * @param volume The new volume value.
778             */
779            public void
780            setBackendVolume(float volume) {
781                    CC.getTaskQueue().add(new Global.SetVolume(volume));
782            }
783            
784            /**
785             * Schedules a new task for resetting the sampler.
786             */
787            public void
788            resetBackend() { CC.getTaskQueue().add(new org.jsampler.task.ResetSampler()); }
789            
790            /**
791           * 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.
792           * @param count The new number of active voices.           * @param count The new number of active voices.
793           * @param countMax The maximum number of active voices.           * @param countMax The maximum number of active voices.
# Line 503  public class DefaultSamplerModel impleme Line 803  public class DefaultSamplerModel impleme
803                    
804          /**          /**
805           * Notifies listeners that a sampler channel has been added.           * Notifies listeners that a sampler channel has been added.
806             * This method can be invoked outside the event-dispatching thread.
807           * @param channelModel A <code>SamplerChannelModel</code> instance.           * @param channelModel A <code>SamplerChannelModel</code> instance.
808           */           */
809          private void          private void
# Line 516  public class DefaultSamplerModel impleme Line 817  public class DefaultSamplerModel impleme
817          }          }
818          /**          /**
819           * 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.  
820           */           */
821          private void          private void
822          fireSamplerChannelAdded(SamplerChannelListEvent e) {          fireSamplerChannelAdded(SamplerChannelListEvent e) {
# Line 531  public class DefaultSamplerModel impleme Line 831  public class DefaultSamplerModel impleme
831                    
832          /**          /**
833           * Notifies listeners that a sampler channel has been removed.           * Notifies listeners that a sampler channel has been removed.
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 545  public class DefaultSamplerModel impleme Line 846  public class DefaultSamplerModel impleme
846                    
847          /**          /**
848           * 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.  
849           */           */
850          private void          private void
851          fireSamplerChannelRemoved(SamplerChannelListEvent e) {          fireSamplerChannelRemoved(SamplerChannelListEvent e) {
# Line 560  public class DefaultSamplerModel impleme Line 860  public class DefaultSamplerModel impleme
860                    
861          /**          /**
862           * Notifies listeners that a MIDI device has been added.           * Notifies listeners that a MIDI device has been added.
863             * This method can be invoked outside the event-dispatching thread.
864           * @param model A <code>MidiDeviceModel</code> instance.           * @param model A <code>MidiDeviceModel</code> instance.
865           */           */
866          private void          private void
# Line 573  public class DefaultSamplerModel impleme Line 874  public class DefaultSamplerModel impleme
874          }          }
875          /**          /**
876           * 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.  
877           */           */
878          private void          private void
879          fireMidiDeviceAdded(MidiDeviceListEvent e) {          fireMidiDeviceAdded(MidiDeviceListEvent e) {
# Line 588  public class DefaultSamplerModel impleme Line 888  public class DefaultSamplerModel impleme
888                    
889          /**          /**
890           * Notifies listeners that a MIDI device has been removed.           * Notifies listeners that a MIDI device has been removed.
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 602  public class DefaultSamplerModel impleme Line 903  public class DefaultSamplerModel impleme
903                    
904          /**          /**
905           * 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.  
906           */           */
907          private void          private void
908          fireMidiDeviceRemoved(MidiDeviceListEvent e) {          fireMidiDeviceRemoved(MidiDeviceListEvent e) {
# Line 617  public class DefaultSamplerModel impleme Line 917  public class DefaultSamplerModel impleme
917                    
918          /**          /**
919           * Notifies listeners that an audio device has been added.           * Notifies listeners that an audio device has been added.
920             * This method can be invoked outside the event-dispatching thread.
921           * @param model A <code>AudioDeviceModel</code> instance.           * @param model A <code>AudioDeviceModel</code> instance.
922           */           */
923          private void          private void
924          fireAudioDeviceAdded(AudioDeviceModel model) {          fireAudioDeviceAdded(AudioDeviceModel model) {
925                  final AudioDeviceListEvent e = new AudioDeviceListEvent(this, model);                  final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model);
926                                                    
927                  SwingUtilities.invokeLater(new Runnable() {                  SwingUtilities.invokeLater(new Runnable() {
928                          public void                          public void
# Line 631  public class DefaultSamplerModel impleme Line 932  public class DefaultSamplerModel impleme
932                    
933          /**          /**
934           * 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.  
935           */           */
936          private void          private void
937          fireAudioDeviceAdded(AudioDeviceListEvent e) {          fireAudioDeviceAdded(ListEvent<AudioDeviceModel> e) {
938                  Object[] listeners = listenerList.getListenerList();                  Object[] listeners = listenerList.getListenerList();
939                                    
940                  for(int i = listeners.length - 2; i >= 0; i -= 2) {                  for(int i = listeners.length - 2; i >= 0; i -= 2) {
941                          if(listeners[i] == AudioDeviceListListener.class) {                          if(listeners[i] == ListListener.class) {
942                                  ((AudioDeviceListListener)listeners[i + 1]).deviceAdded(e);                                  ((ListListener<AudioDeviceModel>)listeners[i + 1]).entryAdded(e);
943                          }                          }
944                  }                  }
945          }          }
946                    
947          /**          /**
948           * Notifies listeners that an audio device has been removed.           * Notifies listeners that an audio device has been removed.
949             * This method can be invoked outside the event-dispatching thread.
950           * @param model A <code>AudioDeviceModel</code> instance.           * @param model A <code>AudioDeviceModel</code> instance.
951           */           */
952          private void          private void
953          fireAudioDeviceRemoved(AudioDeviceModel model) {          fireAudioDeviceRemoved(AudioDeviceModel model) {
954                  final AudioDeviceListEvent e = new AudioDeviceListEvent(this, model);                  final ListEvent<AudioDeviceModel> e = new ListEvent<AudioDeviceModel>(this, model);
955                                                    
956                  SwingUtilities.invokeLater(new Runnable() {                  SwingUtilities.invokeLater(new Runnable() {
957                          public void                          public void
# Line 659  public class DefaultSamplerModel impleme Line 960  public class DefaultSamplerModel impleme
960          }          }
961                    
962          /**          /**
963             * Notifies listeners that a MIDI instrument map has been added to the list.
964             * This method can be invoked outside the event-dispatching thread.
965             */
966            private void
967            fireMidiInstrumentMapAdded(MidiInstrumentMap map) {
968                    final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map);
969                    
970                    SwingUtilities.invokeLater(new Runnable() {
971                            public void
972                            run() { fireMidiInstrumentMapAdded(e); }
973                    });
974            }
975            
976            /** Notifies listeners that a MIDI instrument map has been added to the list. */
977            private void
978            fireMidiInstrumentMapAdded(ListEvent<MidiInstrumentMap> e) {
979                    for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryAdded(e);
980            }
981            
982            /**
983             * Notifies listeners that a MIDI instrument map has been removed from the list.
984             * This method can be invoked outside the event-dispatching thread.
985             */
986            private void
987            fireMidiInstrumentMapRemoved(MidiInstrumentMap map) {
988                    final ListEvent<MidiInstrumentMap> e = new ListEvent<MidiInstrumentMap>(this, map);
989                    
990                    SwingUtilities.invokeLater(new Runnable() {
991                            public void
992                            run() { fireMidiInstrumentMapRemoved(e); }
993                    });
994            }
995            /** Notifies listeners that a MIDI instrument map has been removed from the list. */
996            private void
997            fireMidiInstrumentMapRemoved(ListEvent<MidiInstrumentMap> e) {
998                    for(ListListener<MidiInstrumentMap> l : mapsListeners) l.entryRemoved(e);
999            }
1000            
1001            
1002            /**
1003           * Notifies listeners that an audio device has been removed.           * Notifies listeners that an audio device has been removed.
1004           * This method should be invoked from the event-dispatching thread.           * This method should be invoked from the event-dispatching thread.
1005           */           */
1006          private void          private void
1007          fireAudioDeviceRemoved(AudioDeviceListEvent e) {          fireAudioDeviceRemoved(ListEvent<AudioDeviceModel> e) {
1008                  Object[] listeners = listenerList.getListenerList();                  Object[] listeners = listenerList.getListenerList();
1009                                    
1010                  for(int i = listeners.length - 2; i >= 0; i -= 2) {                  for(int i = listeners.length - 2; i >= 0; i -= 2) {
1011                          if(listeners[i] == AudioDeviceListListener.class) {                          if(listeners[i] == ListListener.class) {
1012                                  ((AudioDeviceListListener)listeners[i + 1]).deviceRemoved(e);                                  ((ListListener<AudioDeviceModel>)listeners[i + 1]).entryRemoved(e);
1013                          }                          }
1014                  }                  }
1015          }          }
1016                    
1017          /** Notifies listeners that the total number of active voices has changed. */          /**
1018             * Notifies listeners that the global volume has changed.
1019             * This method can be invoked outside the event-dispatching thread.
1020             */
1021            private void
1022            fireVolumeChanged() {
1023                    final SamplerEvent e = new SamplerEvent(this);
1024                            
1025                    SwingUtilities.invokeLater(new Runnable() {
1026                            public void
1027                            run() { fireVolumeChanged(e); }
1028                    });
1029            }
1030            
1031            /**
1032             * Notifies listeners that the global volume has changed.
1033             */
1034            private void
1035            fireVolumeChanged(SamplerEvent e) {
1036                    for(SamplerListener l : listeners) l.volumeChanged(e);
1037            }
1038            
1039            /*
1040             * Notifies listeners that the total number of active voices has changed.
1041             * This method can be invoked outside the event-dispatching thread.
1042             */
1043          private void          private void
1044          fireTotalVoiceCountChanged() {          fireTotalVoiceCountChanged() {
1045                  final SamplerEvent e = new SamplerEvent(this);                  final SamplerEvent e = new SamplerEvent(this);
# Line 686  public class DefaultSamplerModel impleme Line 1052  public class DefaultSamplerModel impleme
1052                    
1053          /**          /**
1054           * 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.  
1055           */           */
1056          private void          private void
1057          fireTotalVoiceCountChanged(SamplerEvent e) {          fireTotalVoiceCountChanged(SamplerEvent e) {
1058                  for(SamplerListener l : listeners) l.totalVoiceCountChanged(e);                  for(SamplerListener l : listeners) l.totalVoiceCountChanged(e);
1059          }          }
1060            
1061            /**
1062             * Notifies listeners that the global volume has changed.
1063             */
1064            private void
1065            fireDefaultMapChanged() {
1066                    SamplerEvent e = new SamplerEvent(this);
1067                    for(SamplerListener l : listeners) l.defaultMapChanged(e);
1068            }
1069            
1070            private final Handler handler = new Handler();
1071            
1072            private Handler
1073            getHandler() { return handler; }
1074            
1075            private class Handler implements ListListener<MidiInstrumentMap> {
1076                    /** Invoked when a new map is added to a list. */
1077                    public void
1078                    entryAdded(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); }
1079                    
1080                    /** Invoked when a map is removed from a list. */
1081                    public void
1082                    entryRemoved(ListEvent<MidiInstrumentMap> e) { updateDefaultMap(); }
1083                    
1084                    private void
1085                    updateDefaultMap() {
1086                            if(getDefaultMidiInstrumentMap() != findDefaultMidiInstrumentMap()) {
1087                                    defaultMidiInstrumentMap = findDefaultMidiInstrumentMap();
1088                                    fireDefaultMapChanged();
1089                            }
1090                    }
1091            }
1092  }  }

Legend:
Removed from v.1142  
changed lines
  Added in v.1143

  ViewVC Help
Powered by ViewVC