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

Diff of /jsampler/trunk/src/org/jsampler/view/SamplerTreeModel.java

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

revision 2199 by iliev, Tue Jun 28 22:44:39 2011 UTC revision 2200 by iliev, Sun Jul 3 22:01:16 2011 UTC
# Line 21  Line 21 
21   */   */
22  package org.jsampler.view;  package org.jsampler.view;
23    
24    import java.beans.PropertyChangeEvent;
25    import java.beans.PropertyChangeListener;
26  import java.beans.PropertyChangeSupport;  import java.beans.PropertyChangeSupport;
 import java.util.ArrayList;  
27  import java.util.Enumeration;  import java.util.Enumeration;
28  import java.util.Vector;  import java.util.Vector;
29  import javax.swing.SwingConstants;  import javax.swing.SwingConstants;
30    import javax.swing.SwingUtilities;
31  import javax.swing.event.TreeModelEvent;  import javax.swing.event.TreeModelEvent;
32  import javax.swing.event.TreeModelListener;  import javax.swing.event.TreeModelListener;
33  import javax.swing.tree.TreeModel;  import javax.swing.tree.TreeModel;
# Line 36  import org.jsampler.AudioDeviceModel; Line 38  import org.jsampler.AudioDeviceModel;
38  import org.jsampler.CC;  import org.jsampler.CC;
39  import org.jsampler.EffectChain;  import org.jsampler.EffectChain;
40  import org.jsampler.EffectInstance;  import org.jsampler.EffectInstance;
41    import org.jsampler.SamplerChannelModel;
42  import org.jsampler.event.AudioDeviceEvent;  import org.jsampler.event.AudioDeviceEvent;
43  import org.jsampler.event.AudioDeviceListener;  import org.jsampler.event.AudioDeviceListener;
44  import org.jsampler.event.EffectChainEvent;  import org.jsampler.event.EffectChainEvent;
45  import org.jsampler.event.EffectChainListener;  import org.jsampler.event.EffectChainListener;
46  import org.jsampler.event.EffectInstanceEvent;  import org.jsampler.event.EffectInstanceEvent;
47  import org.jsampler.event.EffectInstanceListener;  import org.jsampler.event.EffectInstanceListener;
48    import org.jsampler.event.EffectSendsEvent;
49    import org.jsampler.event.EffectSendsListener;
50  import org.jsampler.event.ListEvent;  import org.jsampler.event.ListEvent;
51  import org.jsampler.event.ListListener;  import org.jsampler.event.ListListener;
52    
53  import org.linuxsampler.lscp.Effect;  import org.linuxsampler.lscp.Effect;
54  import org.linuxsampler.lscp.EffectParameter;  import org.linuxsampler.lscp.EffectParameter;
55    import org.linuxsampler.lscp.FxSend;
56    
57  import static org.jsampler.JSI18n.i18n;  import static org.jsampler.JSI18n.i18n;
58    
# Line 54  import static org.jsampler.JSI18n.i18n; Line 60  import static org.jsampler.JSI18n.i18n;
60   *   *
61   * @author Grigor Iliev   * @author Grigor Iliev
62   */   */
63  public class SamplerTreeModel implements TreeModel {  public class SamplerTreeModel extends AbstractTreeModel {
64          private final SamplerTreeNode root = new SamplerTreeNode(this);          private final SamplerTreeNode root = new SamplerTreeNode(this);
         private ArrayList<TreeModelListener> listeners = new ArrayList<TreeModelListener>();  
65                    
66            private final SamplerChannelDirTreeNode samplerChannels;
67          private final AudioDevicesTreeNode audioDevices;          private final AudioDevicesTreeNode audioDevices;
68          private final InternalEffectsTreeNode internalEffects;          private final InternalEffectsTreeNode internalEffects;
69                    
70          public          public
71          SamplerTreeModel() {          SamplerTreeModel() {
72                  audioDevices = new AudioDevicesTreeNode(this, root);                  audioDevices = new AudioDevicesTreeNode(this, root); // should be created before samplerChannels
                 root.addChild(audioDevices);  
73                                    
74                  for(AudioDeviceModel a : CC.getSamplerModel().getAudioDevices()) {                  for(AudioDeviceModel a : CC.getSamplerModel().getAudioDevices()) {
75                          audioDevices.addChild(new AudioDeviceTreeNode(this, audioDevices, a));                          audioDevices.addChild(new AudioDeviceTreeNode(this, audioDevices, a));
# Line 73  public class SamplerTreeModel implements Line 78  public class SamplerTreeModel implements
78                                    
79                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());                  CC.getSamplerModel().addAudioDeviceListListener(getHandler());
80                                    
81                    root.addChild(audioDevices);
82                    
83                    samplerChannels = new SamplerChannelDirTreeNode(this, root);
84                    root.insertChild(samplerChannels, root.getIndex(audioDevices));
85                    
86                  internalEffects = new InternalEffectsTreeNode(this, root);                  internalEffects = new InternalEffectsTreeNode(this, root);
87                  root.addChild(internalEffects);                  root.addChild(internalEffects);
88                  for(int i = 0; i < CC.getSamplerModel().getEffects().getEffectCount(); i++) {                  for(int i = 0; i < CC.getSamplerModel().getEffects().getEffectCount(); i++) {
# Line 81  public class SamplerTreeModel implements Line 91  public class SamplerTreeModel implements
91                  }                  }
92          }          }
93                    
         // Tree model methods  
         @Override  
         public void  
         addTreeModelListener(TreeModelListener l) {  
                 listeners.add(l);  
         }  
           
         @Override  
         public void  
         removeTreeModelListener(TreeModelListener l) {  
                 listeners.remove(l);  
         }  
           
         @Override  
         public Object  
         getChild(Object parent, int index) {  
                 return ((TreeNode)parent).getChildAt(index);  
         }  
           
         @Override  
         public int  
         getChildCount(Object parent) {  
                 return ((TreeNode)parent).getChildCount();  
         }  
           
94          @Override          @Override
95          public Object          public Object
96          getRoot() { return root; }          getRoot() { return root; }
97                    
98          @Override          @Override
         public int  
         getIndexOfChild(Object parent, Object child) {  
                 if(parent == null || child == null) return -1;  
                 return ((TreeNode)parent).getIndex((TreeNode)child);  
         }  
           
         @Override  
         public boolean  
         isLeaf(Object node) { return ((TreeNode)node).isLeaf(); }  
           
         @Override  
99          public void          public void
100          valueForPathChanged(TreePath path, Object newValue) {          valueForPathChanged(TreePath path, Object newValue) {
101                                    
102          }          }
103          ///////          ///////
104                    
         protected Object[]  
         getPathToRoot(TreeNode node) {  
                 Vector v = new Vector();  
                   
                 while(node != null) {  
                         v.insertElementAt(node, 0);  
                         if(node == getRoot()) break;  
                         node = node.getParent();  
                 }  
                   
                 return v.toArray(new Object[v.size()]);  
         }  
           
         private void  
         fireNodeInserted(TreeNode node, int index) {  
                 Object[] path = getPathToRoot(node.getParent());  
                   
                 int[] idxs = { index };  
                 Object[] objs = { node };  
                 TreeModelEvent e = new TreeModelEvent(this, path, idxs, objs);  
                 for(TreeModelListener l : listeners) {  
                         l.treeNodesInserted(e);  
                 }  
         }  
           
         private void  
         fireNodeChanged(TreeNode node, int index) {  
                 Object[] path = getPathToRoot(node.getParent());  
                 int[] idxs = { index };  
                 Object[] objs = { node };  
                 TreeModelEvent e = new TreeModelEvent(this, path, idxs, objs);  
                 for(TreeModelListener l : listeners) {  
                         l.treeNodesChanged(e);  
                 }  
         }  
           
         private void  
         fireNodeRemoved(TreeNode parent, TreeNode node, int index) {  
                 Object[] path = getPathToRoot(parent);  
                 int[] idxs = { index };  
                 Object[] objs = { node };  
                 TreeModelEvent e = new TreeModelEvent(this, path, idxs, objs);  
                 for(int i = listeners.size() - 1; i >=0; i--) {  
                         listeners.get(i).treeNodesRemoved(e);  
                 }  
         }  
           
         private void  
         fireNodeStructureChanged(TreeNode node) {  
                 Object[] path = getPathToRoot(node);  
                 Object[] objs = { node };  
                 TreeModelEvent e = new TreeModelEvent(this, path);  
                 for(TreeModelListener l : listeners) {  
                         l.treeStructureChanged(e);  
                 }  
         }  
           
105                    
106          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
107                    
# Line 250  public class SamplerTreeModel implements Line 167  public class SamplerTreeModel implements
167                                  return;                                  return;
168                          }                          }
169                                                    
170                          SendEffectChainsTreeNode chainsNode = node.getSendEffectChainsTreeNode();                          SendEffectChainsTreeNode chainsNode = node.getSendEffectChainsNode();
171                                                    
172                          SendEffectChainTreeNode child = new SendEffectChainTreeNode (                          SendEffectChainTreeNode child = new SendEffectChainTreeNode (
173                                  SamplerTreeModel.this, chainsNode, e.getEffectChain()                                  SamplerTreeModel.this, chainsNode, e.getEffectChain()
# Line 275  public class SamplerTreeModel implements Line 192  public class SamplerTreeModel implements
192                                  return;                                  return;
193                          }                          }
194                                                    
195                          SendEffectChainsTreeNode chainsNode = node.getSendEffectChainsTreeNode();                          SendEffectChainsTreeNode chainsNode = node.getSendEffectChainsNode();
196                                                    
197                          SendEffectChainTreeNode child = chainsNode.getChildById(e.getEffectChain().getChainId());                          SendEffectChainTreeNode child = chainsNode.getChildById(e.getEffectChain().getChainId());
198                          if(child == null)  {                          if(child == null)  {
# Line 283  public class SamplerTreeModel implements Line 200  public class SamplerTreeModel implements
200                                  return;                                  return;
201                          }                          }
202                                                    
203                          e.getEffectChain().removeEffectChainListener(child);                          child.uninstall();
                         child.uninstallListeners();  
204                                                    
205                          int idx = chainsNode.getIndex(child);                          int idx = chainsNode.getIndex(child);
206                          chainsNode.removeChildAt(idx);                          chainsNode.removeChildAt(idx);
# Line 302  public class SamplerTreeModel implements Line 218  public class SamplerTreeModel implements
218                                    
219                  public abstract T getChildAt(int index);                  public abstract T getChildAt(int index);
220                  public abstract boolean isLeaf();                  public abstract boolean isLeaf();
221                    public abstract void uninstall();
222                    
223                    public boolean
224                    isLink() { return false; }
225                    
226                    public TreeNodeBase
227                    getLink() { return null; }
228                    
229                    public void edit() { }
230                    
231                    public int
232                    getId() { return -1; }
233                                    
234                  /** Gets the number of columns for the corresponding table model. */                  /** Gets the number of columns for the corresponding table model. */
235                  public int                  public int
# Line 337  public class SamplerTreeModel implements Line 265  public class SamplerTreeModel implements
265          }          }
266    
267          public static class AbstractTreeNode<T extends TreeNodeBase> extends TreeNodeBase<T> {          public static class AbstractTreeNode<T extends TreeNodeBase> extends TreeNodeBase<T> {
268                  protected final SamplerTreeModel treeModel;                  protected  AbstractTreeModel treeModel;
269                  private final TreeNodeBase parent;                  private  TreeNodeBase parent;
270                  private final Vector<T> children = new Vector<T>();                  private Vector<T> children = new Vector<T>();
271                    
272                  public                  public
273                  AbstractTreeNode(SamplerTreeModel treeModel) { this(treeModel, null); }                  AbstractTreeNode(AbstractTreeModel treeModel) { this(treeModel, null); }
274                    
275                  public                  public
276                  AbstractTreeNode(SamplerTreeModel treeModel, TreeNodeBase parent) {                  AbstractTreeNode(AbstractTreeModel treeModel, TreeNodeBase parent) {
277                          this.parent = parent;                          this.parent = parent;
278                          this.treeModel = treeModel;                          this.treeModel = treeModel;
279                  }                  }
# Line 382  public class SamplerTreeModel implements Line 310  public class SamplerTreeModel implements
310                    
311                  public void                  public void
312                  addChild(T child) { children.add(child); }                  addChild(T child) { children.add(child); }
313                    ///////
314            
315                    public void
316                    insertChild(T child, int index) { children.insertElementAt(child, index); }
317                    
318                  public T                  public T
319                  removeChildAt(int index) { return children.remove(index); }                  removeChildAt(int index) { return children.remove(index); }
320                    
321                  public void                  public void
322                  removeAllChildren() { children.removeAllElements(); }                  removeAllChildren() {
323                            children.removeAllElements();
324                    }
325            
326                    public T
327                    getChildById(int id) {
328                            if(id == -1) return null;
329                            
330                            for(int i = 0; i < getChildCount(); i++) {
331                                    if(getChildAt(i).getId() == id) return getChildAt(i);
332                            }
333                    
334                            return null;
335                    }
336            
337                    public void
338                    removeAndUninstallAllChildren() {
339                            for(int i = getChildCount() - 1; i >= 0; i--) {
340                                    T child = getChildAt(i);
341                                    removeChildAt(i);
342                                    child.uninstall();
343                            }
344                    }
345                    
346                    public void
347                    uninstall() {
348                            removeAndUninstallAllChildren();
349                            treeModel = null;
350                            parent = null;
351                    }
352          }          }
353    
354          public static class AbstractTreeLeaf<T extends TreeNodeBase> extends TreeNodeBase<T> {          public static class AbstractTreeLeaf<T extends TreeNodeBase> extends TreeNodeBase<T> {
355                  private final T parent;                  private T parent;
356                    
357                  public                  public
358                  AbstractTreeLeaf() { this(null); }                  AbstractTreeLeaf() { this(null); }
# Line 428  public class SamplerTreeModel implements Line 389  public class SamplerTreeModel implements
389                  public Enumeration                  public Enumeration
390                  children() { return null; }                  children() { return null; }
391                  ///////                  ///////
392                    
393                    public void
394                    uninstall() { parent = null; }
395          }          }
396    
397          public static class StandardTreeNode<T extends TreeNodeBase> extends AbstractTreeNode<T> {          public static class StandardTreeNode<T extends TreeNodeBase> extends AbstractTreeNode<T> {
398                  public                  public
399                  StandardTreeNode(SamplerTreeModel treeModel) { this(treeModel, null); }                  StandardTreeNode(AbstractTreeModel treeModel) { this(treeModel, null); }
400                    
401                  public                  public
402                  StandardTreeNode(SamplerTreeModel treeModel, TreeNodeBase parent) {                  StandardTreeNode(AbstractTreeModel treeModel, TreeNodeBase parent) {
403                          super(treeModel, parent);                          super(treeModel, parent);
404                  }                  }
405                                    
# Line 482  public class SamplerTreeModel implements Line 446  public class SamplerTreeModel implements
446                  toString() { return i18n.getLabel("SamplerTreeNode.toString"); }                  toString() { return i18n.getLabel("SamplerTreeNode.toString"); }
447          }          }
448    
449          public static class AudioDevicesTreeNode extends AbstractTreeNode<AudioDeviceTreeNode> {          public static class SamplerChannelDirTreeNode
450                                    extends StandardTreeNode<ChannelLaneTreeNode>
451                                    implements PropertyChangeListener {
452                  public                  public
453                  AudioDevicesTreeNode(SamplerTreeModel treeModel, TreeNodeBase parent) {                  SamplerChannelDirTreeNode(SamplerTreeModel treeModel, TreeNodeBase parent) {
454                          super(treeModel, parent);                          super(treeModel, parent);
455                            
456                            updateChildren();
457                            
458                            CC.getMainFrame().addPropertyChangeListener(this);
459                    }
460                    
461                    @Override
462                    public void
463                    propertyChange(PropertyChangeEvent e) {
464                            if (
465                                    e.getPropertyName() == "channelLaneAdded" ||
466                                    e.getPropertyName() == "channelLaneInserted" ||
467                                    e.getPropertyName() == "channelLaneRemoved"
468                            ) {
469                                    updateChildren();
470                                    firePropertyChange("SamplerTreeModel.update", null, null);
471                                    getParent().firePropertyChange("SamplerTreeModel.update", null, null);
472                            }
473                    }
474                    
475                    private void
476                    updateChildren() {
477                            removeAndUninstallAllChildren();
478                            
479                            for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
480                                    JSChannelsPane lane = CC.getMainFrame().getChannelsPane(i);
481                                    addChild(new ChannelLaneTreeNode(treeModel, this, lane));
482                            }
483                    }
484                    
485                    @Override
486                    public void
487                    uninstall() {
488                            CC.getMainFrame().removePropertyChangeListener(this);
489                            
490                            super.uninstall();
491                  }                  }
492                    
493                  public AudioDeviceTreeNode                  @Override
494                  getChildById(int audioDeviceId) {                  public String
495                          for(int i = 0; i < getChildCount(); i++) {                  toString() { return i18n.getLabel("SamplerChannelDirTreeNode.toString"); }
496                                  if(getChildAt(i).getAudioDeviceId() == audioDeviceId) return getChildAt(i);          }
497    
498            public static class ChannelLaneTreeNode extends StandardTreeNode<SamplerChannelTreeNode>
499                                                    implements PropertyChangeListener {
500                    
501                    private JSChannelsPane lane;
502                    
503                    public
504                    ChannelLaneTreeNode (
505                            AbstractTreeModel treeModel, TreeNodeBase parent, JSChannelsPane lane
506                    ) {
507                            super(treeModel, parent);
508                            this.lane = lane;
509                            
510                            updateChildren();
511                            
512                            lane.addPropertyChangeListener(this);
513                    }
514                    
515                    public JSChannelsPane
516                    getLane() { return lane; }
517                    
518                    /** Gets the number of columns for the corresponding table model. */
519                    @Override
520                    public int
521                    getColumnCount() { return 3; }
522                    
523                    /** Gets the number of rows for the corresponding table model. */
524                    @Override
525                    public int
526                    getRowCount() { return getChildCount(); }
527                    
528                    /**
529                     * Gets the value for the cell at <code>row</code> and
530                     * <code>col</code> for the corresponding table model.
531                     */
532                    @Override
533                    public Object
534                    getValueAt(int row, int col) {
535                            if(col == 0) return getChildAt(row);
536                            if(col == 1) {
537                                    Object o = getChildAt(row).getChannel().getChannelInfo().getEngine();
538                                    if(o == null) o = i18n.getLabel("ChannelLaneTreeNode.noEngine");
539                                    return o;
540                          }                          }
541                            return "";
542                    }
543                                    
544                          return null;                  /** Gets the name of the column for the corresponding table model. */
545                    @Override
546                    public String
547                    getColumnName(int col) {
548                            if(col == 0) return i18n.getLabel("SamplerTreeModel.tableColumn.chn");
549                            if(col == 1) return i18n.getLabel("SamplerTreeModel.tableColumn.engine");
550                            return " ";
551                    }
552                    
553                    @Override
554                    public void
555                    propertyChange(PropertyChangeEvent e) {
556                            if (
557                                    e.getPropertyName() == "channelAdded" ||
558                                    e.getPropertyName() == "channelsAdded" ||
559                                    e.getPropertyName() == "channelRemoved" ||
560                                    e.getPropertyName() == "channelsRemoved"
561                            ) {
562                                    updateChildren();
563                                    firePropertyChange("SamplerTreeModel.update", null, null);
564                                    getParent().firePropertyChange("SamplerTreeModel.update", null, null);
565                            }
566                            
567                            if(e.getPropertyName() == "channelsPositionChanged") {
568                                    updateChildren();
569                                    firePropertyChange("SamplerTreeModel.update", null, null);
570                            }
571                    }
572                    
573                    private void
574                    updateChildren() {
575                            removeAndUninstallAllChildren();
576                            
577                            for(int i = 0; i < lane.getChannelCount(); i++) {
578                                    SamplerChannelModel chn = lane.getChannel(i).getModel();
579                                    addChild(new SamplerChannelTreeNode(treeModel, this, chn));
580                            }
581                            
582                            treeModel.fireNodeStructureChanged(this);
583                    }
584                    
585                    @Override
586                    public void
587                    uninstall() {
588                            lane.removePropertyChangeListener(this);
589                            lane = null;
590                            
591                            super.uninstall();
592                    }
593            
594                    @Override
595                    public String
596                    toString() { return lane.getTitle(); }
597            }
598    
599            public static class SamplerChannelTreeNode extends StandardTreeNode {
600                    private SamplerChannelModel channel;
601                    
602                    public
603                    SamplerChannelTreeNode (
604                            AbstractTreeModel treeModel, TreeNodeBase parent, SamplerChannelModel chn
605                    ) {
606                            super(treeModel, parent);
607                            channel = chn;
608                            addChild(new FxSendDirTreeNode(treeModel, this, chn));
609                    }
610                    
611                    public SamplerChannelModel
612                    getChannel() { return channel; }
613                    
614                    public int
615                    getId() { return getChannel().getChannelId(); }
616                    
617                    @Override
618                    public void
619                    uninstall() {
620                            super.uninstall();
621                            channel = null; // might be needed by the children to uninstall properly
622                    }
623            
624                    @Override
625                    public String
626                    toString() {
627                            String s = CC.getMainFrame().getChannelPath(channel);
628                            return i18n.getLabel("SamplerChannelTreeNode.toString", s);
629                    }
630            }
631    
632            public static class FxSendDirTreeNode
633                                    extends StandardTreeNode<FxSendTreeNode>
634                                    implements EffectSendsListener {
635                    
636                    private SamplerChannelModel channel;
637                    
638                    public
639                    FxSendDirTreeNode (
640                            AbstractTreeModel treeModel, TreeNodeBase parent, SamplerChannelModel chn
641                    ) {
642                            super(treeModel, parent);
643                            channel = chn;
644                            
645                            for(FxSend fx : chn.getFxSends()) {
646                                    addChild(new FxSendTreeNode(treeModel, this, fx));
647                            }
648                            
649                            chn.addEffectSendsListener(this);
650                    }
651                    
652                    public SamplerChannelModel
653                    getChannel() { return channel; }
654                    
655                    @Override
656                    public void
657                    effectSendAdded(EffectSendsEvent e) {
658                            FxSendTreeNode node = new FxSendTreeNode(treeModel, this, e.getFxSend());
659                            addChild(node);
660                            treeModel.fireNodeInserted(node, getIndex(node));
661                            firePropertyChange("SamplerTreeModel.update", null, null);
662                            getParent().firePropertyChange("SamplerTreeModel.update", null, null);
663                    }
664            
665                    @Override
666                    public void
667                    effectSendRemoved(EffectSendsEvent e) {
668                            final FxSendTreeNode child = getChildById(e.getFxSend().getFxSendId());
669                            int i = getIndex(child);
670                            if(i == -1) return;
671                            
672                            removeChildAt(i);
673                            treeModel.fireNodeRemoved(this, child, i);
674                            firePropertyChange("SamplerTreeModel.update", null, null);
675                            getParent().firePropertyChange("SamplerTreeModel.update", null, null);
676                            
677                            /* To avoid ConcurrentModificationException. */
678                            SwingUtilities.invokeLater(new Runnable() {
679                                    public void
680                                    run() { child.uninstall(); }
681                            });
682                            ///////
683                    }
684            
685                    @Override
686                    public void
687                    effectSendChanged(EffectSendsEvent e) {
688                            FxSendTreeNode node = getChildById(e.getFxSend().getFxSendId());
689                            node.setFxSend(e.getFxSend());
690                            
691                            treeModel.fireNodeChanged(node, getIndex(node));
692                            
693                            firePropertyChange("SamplerTreeModel.update", null, null);
694                    }
695                    
696                    @Override
697                    public void
698                    uninstall() {
699                            channel.removeEffectSendsListener(this);
700                            super.uninstall();
701                            channel = null; // might be needed by the children to uninstall properly
702                    }
703            
704                    @Override
705                    public String
706                    toString() { return i18n.getLabel("FxSendDirTreeNode.toString"); }
707            }
708    
709            public static class FxSendTreeNode extends StandardTreeNode<DestEffectDirTreeNode> {
710                    private FxSend fxSend;
711                    private DestEffectDirTreeNode destEffectDir;
712                    
713                    public
714                    FxSendTreeNode(AbstractTreeModel treeModel, TreeNodeBase parent, FxSend fxSend) {
715                            super(treeModel, parent);
716                            this.fxSend = fxSend;
717                            
718                            destEffectDir = new DestEffectDirTreeNode(treeModel, this, fxSend);
719                            addChild(destEffectDir);
720                    }
721                    
722                    public SamplerChannelModel
723                    getChannel() { return ((FxSendDirTreeNode)getParent()).getChannel(); }
724                    
725                    public FxSend
726                    getFxSend() { return fxSend; }
727                    
728                    public void
729                    setFxSend(FxSend fxSend) {
730                            this.fxSend = fxSend;
731                            destEffectDir.setFxSend(fxSend);
732                    }
733                    
734                    public int
735                    getId() { return fxSend.getFxSendId(); }
736                    
737                    @Override
738                    public void
739                    uninstall() {
740                            fxSend = null;
741                            super.uninstall();
742                    }
743            
744                    @Override
745                    public String
746                    toString() { return fxSend != null ? fxSend.getName(): super.toString(); }
747            }
748    
749            public static class DestEffectDirTreeNode extends AbstractTreeNode<DestEffectTreeNode> {
750                    public
751                    DestEffectDirTreeNode(AbstractTreeModel treeModel, TreeNodeBase parent, FxSend fxSend) {
752                            super(treeModel, parent);
753                            
754                            addChild(new DestEffectTreeNode(this, fxSend));
755                    }
756                    
757                    public void
758                    setFxSend(FxSend fxSend) { getChildAt(0).setFxSend(fxSend); }
759                    
760                    /** Gets the number of columns for the corresponding table model. */
761                    @Override
762                    public int
763                    getColumnCount() { return 3; }
764                    
765                    /** Gets the number of rows for the corresponding table model. */
766                    @Override
767                    public int
768                    getRowCount() { return getChildCount(); }
769                    
770                    /**
771                     * Gets the value for the cell at <code>row</code> and
772                     * <code>col</code> for the corresponding table model.
773                     */
774                    @Override
775                    public Object
776                    getValueAt(int row, int col) {
777                            if(col == 0) return getChildAt(row);
778                            if(col == 1) return getChildAt(row).getEffectInstanceString();
779                            return "";
780                    }
781                    
782                    /** Gets the name of the column for the corresponding table model. */
783                    @Override
784                    public String
785                    getColumnName(int col) {
786                            if(col == 0) return i18n.getLabel("SamplerTreeModel.tableColumn.destChain");
787                            if(col == 1) return i18n.getLabel("SamplerTreeModel.tableColumn.destFx");
788                            return " ";
789                    }
790            
791                    @Override
792                    public String
793                    toString() { return i18n.getLabel("DestEffectDirTreeNode.toString"); }
794            }
795    
796            public static class DestEffectTreeNode  extends AbstractTreeLeaf<DestEffectDirTreeNode>
797                                                    implements EffectSendsListener {
798                    
799                    private SendEffectChainTreeNode chain;
800                    private FxSend fxSend;
801                                    
802                    public
803                    DestEffectTreeNode(DestEffectDirTreeNode parent, FxSend fxSend) {
804                            super(parent);
805                            
806                            setFxSend(fxSend);
807                            
808                            /* To avoid ConcurrentModificationException because
809                             * this method is created due to effect sends event. */
810                            SwingUtilities.invokeLater(new Runnable() {
811                                    public void
812                                    run() { getChannel().addEffectSendsListener(DestEffectTreeNode.this); }
813                            });
814                            ///////
815                    }
816                    
817                    public SamplerChannelModel
818                    getChannel() { return ((FxSendTreeNode)getParent().getParent()).getChannel(); }
819                    
820                    public FxSend
821                    getFxSend() { return fxSend; }
822                    
823                    public void
824                    setFxSend(FxSend fxSend) {
825                            this.fxSend = fxSend;
826                            
827                            int d = getChannel().getChannelInfo().getAudioOutputDevice();
828                            int c = fxSend.getDestChainId();
829                            SamplerTreeModel m = (SamplerTreeModel)getParent().treeModel;
830                            chain = m.audioDevices.getSendEffectChainNodeById(d, c);
831                    }
832                    
833                    public SendEffectChainTreeNode
834                    getEffectChain() { return chain; }
835                    
836                    public EffectInstance
837                    getEffectInstance() {
838                            if(chain == null) return null;
839                            return chain.getEffectChain().getEffectInstance(fxSend.getDestChainPos());
840                    }
841                    
842                    public String
843                    getEffectInstanceString() {
844                            if(chain == null) return "";
845                            int i = fxSend.getDestChainPos();
846                            String s = chain.getEffectChain().getEffectInstance(i).getInfo().getDescription();
847                            return String.valueOf(i) + " (" + s + ")";
848                    }
849                    
850                    public AudioDeviceModel
851                    getAudioDevice() {
852                            int dev = getChannel().getChannelInfo().getAudioOutputDevice();
853                            if(dev == -1) return null;
854                            return CC.getSamplerModel().getAudioDeviceById(dev);
855                    }
856                    
857                    @Override
858                    public boolean
859                    isLink() { return true; }
860                    
861                    @Override
862                    public TreeNodeBase
863                    getLink() {
864                            if(chain == null) return null;
865                            return chain.getChildAt(fxSend.getDestChainPos());
866                    }
867                    
868                    @Override
869                    public void
870                    effectSendAdded(EffectSendsEvent e) { }
871            
872                    @Override
873                    public void
874                    effectSendRemoved(EffectSendsEvent e) { }
875            
876                    @Override
877                    public void
878                    effectSendChanged(EffectSendsEvent e) {
879                            if(e.getFxSend().getFxSendId() != getFxSend().getFxSendId()) return;
880                            firePropertyChange("SamplerTreeModel.update", null, null);
881                    }
882                    
883                    @Override
884                    public void
885                    uninstall() {
886                            getChannel().removeEffectSendsListener(this);
887                            fxSend = null;
888                            chain = null;
889                            
890                            super.uninstall();
891                    }
892            
893                    @Override
894                    public String
895                    toString() {
896                            Object o = getEffectChain();
897                            return o == null ? i18n.getLabel("DestEffectTreeNode.noFx") : o.toString();
898                    }
899            }
900    
901            public static class AudioDevicesTreeNode extends AbstractTreeNode<AudioDeviceTreeNode> {
902                    public
903                    AudioDevicesTreeNode(SamplerTreeModel treeModel, TreeNodeBase parent) {
904                            super(treeModel, parent);
905                    }
906                    
907                    public SendEffectChainTreeNode
908                    getSendEffectChainNodeById(int devId, int chainId) {
909                            AudioDeviceTreeNode node = getChildById(devId);
910                            if(node == null) return null;
911                            return node.getSendEffectChainNodeById(chainId);
912                  }                  }
913                                    
914                  /** Gets the number of columns for the corresponding table model. */                  /** Gets the number of columns for the corresponding table model. */
# Line 539  public class SamplerTreeModel implements Line 953  public class SamplerTreeModel implements
953          }          }
954    
955          public static class AudioDeviceTreeNode extends StandardTreeNode {          public static class AudioDeviceTreeNode extends StandardTreeNode {
956                  private final AudioDeviceModel audioDevice;                  private AudioDeviceModel audioDevice;
957                  private final SendEffectChainsTreeNode effectChains;                  private SendEffectChainsTreeNode effectChains;
958                    
959                  public                  public
960                  AudioDeviceTreeNode (                  AudioDeviceTreeNode (
961                          SamplerTreeModel treeModel, TreeNodeBase parent, AudioDeviceModel audioDevice                          AbstractTreeModel treeModel, TreeNodeBase parent, AudioDeviceModel audioDevice
962                  ) {                  ) {
963                          super(treeModel, parent);                          super(treeModel, parent);
964                          this.audioDevice = audioDevice;                          this.audioDevice = audioDevice;
# Line 556  public class SamplerTreeModel implements Line 970  public class SamplerTreeModel implements
970                  public AudioDeviceModel                  public AudioDeviceModel
971                  getAudioDevice() { return audioDevice; }                  getAudioDevice() { return audioDevice; }
972                    
973                    @Override
974                  public int                  public int
975                  getAudioDeviceId() { return audioDevice.getDeviceId(); }                  getId() { return audioDevice.getDeviceId(); }
976                                    
977                  public SendEffectChainsTreeNode                  public SendEffectChainsTreeNode
978                  getSendEffectChainsTreeNode() { return effectChains; }                  getSendEffectChainsNode() { return effectChains; }
979                    
980                    public SendEffectChainTreeNode
981                    getSendEffectChainNodeById(int id) {
982                            return getSendEffectChainsNode().getChildById(id);
983                    }
984                    
985                    @Override
986                    public void
987                    uninstall() {
988                            audioDevice = null;
989                            effectChains = null;
990                            super.uninstall();
991                    }
992                    
993                  @Override                  @Override
994                  public String                  public String
995                  toString() { return i18n.getLabel("AudioDeviceTreeNode.toString", getAudioDeviceId()); }                  toString() { return i18n.getLabel("AudioDeviceTreeNode.toString", getId()); }
996          }          }
997    
998          public static class SendEffectChainsTreeNode extends StandardTreeNode<SendEffectChainTreeNode> {          public static class SendEffectChainsTreeNode extends StandardTreeNode<SendEffectChainTreeNode> {
999                  private final AudioDeviceModel audioDevice;                  private AudioDeviceModel audioDevice;
1000                    
1001                  public                  public
1002                  SendEffectChainsTreeNode (                  SendEffectChainsTreeNode (
1003                          SamplerTreeModel treeModel, TreeNodeBase parent, AudioDeviceModel audioDevice                          AbstractTreeModel treeModel, TreeNodeBase parent, AudioDeviceModel audioDevice
1004                  ) {                  ) {
1005                          super(treeModel, parent);                          super(treeModel, parent);
1006                          this.audioDevice = audioDevice;                          this.audioDevice = audioDevice;
# Line 589  public class SamplerTreeModel implements Line 1017  public class SamplerTreeModel implements
1017                  public int                  public int
1018                  getAudioDeviceId() { return audioDevice.getDeviceId(); }                  getAudioDeviceId() { return audioDevice.getDeviceId(); }
1019                                    
1020                  public SendEffectChainTreeNode                  @Override
1021                  getChildById(int chainId) {                  public void
1022                          for(int i = 0; i < getChildCount(); i++) {                  uninstall() {
1023                                  if(getChildAt(i).getChainId() == chainId) return getChildAt(i);                          audioDevice = null;
1024                          }                          super.uninstall();
                           
                         return null;  
1025                  }                  }
1026                    
1027                  @Override                  @Override
# Line 605  public class SamplerTreeModel implements Line 1031  public class SamplerTreeModel implements
1031    
1032          public static class SendEffectChainTreeNode extends AbstractTreeNode<EffectInstanceTreeNode>          public static class SendEffectChainTreeNode extends AbstractTreeNode<EffectInstanceTreeNode>
1033                                                          implements EffectChainListener {                                                          implements EffectChainListener {
1034                  private final EffectChain chain;                  private EffectChain chain;
1035                    
1036                  public                  public
1037                  SendEffectChainTreeNode (                  SendEffectChainTreeNode (
1038                          SamplerTreeModel treeModel, SendEffectChainsTreeNode parent, EffectChain chain                          AbstractTreeModel treeModel, SendEffectChainsTreeNode parent, EffectChain chain
1039                  ) {                  ) {
1040                          super(treeModel, parent);                          super(treeModel, parent);
1041                          this.chain = chain;                          this.chain = chain;
# Line 621  public class SamplerTreeModel implements Line 1047  public class SamplerTreeModel implements
1047                  public EffectChain                  public EffectChain
1048                  getEffectChain() { return chain; }                  getEffectChain() { return chain; }
1049                                    
1050                    @Override
1051                  public int                  public int
1052                  getChainId() { return chain.getChainId(); }                  getId() { return chain.getChainId(); }
1053                    
1054                  /**                  /**
1055                   * Gets the audio device to which the                   * Gets the audio device to which the
# Line 672  public class SamplerTreeModel implements Line 1099  public class SamplerTreeModel implements
1099                  getHorizontalAlignment(int column) {                  getHorizontalAlignment(int column) {
1100                          return column == 1 ? SwingConstants.CENTER : SwingConstants.LEFT;                          return column == 1 ? SwingConstants.CENTER : SwingConstants.LEFT;
1101                  }                  }
1102                    
1103                    @Override
1104                    public void
1105                    uninstall() {
1106                            chain.removeEffectChainListener(this);
1107                            chain = null;
1108                            super.uninstall();
1109                    }
1110                    
1111                  @Override                  @Override
1112                  public String                  public String
# Line 689  public class SamplerTreeModel implements Line 1124  public class SamplerTreeModel implements
1124                                    
1125                  private void                  private void
1126                  updateEffectInstanceList() {                  updateEffectInstanceList() {
1127                          uninstallListeners();                          removeAndUninstallAllChildren();
1128                                                    
                         removeAllChildren();  
1129                          for(int i = 0; i < chain.getEffectInstanceCount(); i++) {                          for(int i = 0; i < chain.getEffectInstanceCount(); i++) {
1130                                  EffectInstance ei = chain.getEffectInstance(i);                                  EffectInstance ei = chain.getEffectInstance(i);
1131                                  addChild(new EffectInstanceTreeNode(treeModel, this, ei));                                  addChild(new EffectInstanceTreeNode(treeModel, this, ei));
1132                          }                          }
                           
                         installListeners();  
                 }  
                   
                 public void  
                 installListeners() {  
                         for(int i = 0; i < getChildCount(); i++) {  
                                 getChildAt(i).effectInstance.addEffectInstanceListener(getChildAt(i));  
                         }  
                 }  
                   
                 public void  
                 uninstallListeners() {  
                         for(int i = 0; i < getChildCount(); i++) {  
                                 getChildAt(i).effectInstance.removeEffectInstanceListener(getChildAt(i));  
                         }  
1133                  }                  }
1134          }          }
1135    
1136          public static class EffectInstanceTreeNode extends AbstractTreeNode implements EffectInstanceListener {          public static class EffectInstanceTreeNode extends AbstractTreeNode implements EffectInstanceListener {
1137                  private final EffectInstance effectInstance;                  private EffectInstance effectInstance;
1138                  private EffectParameter[] params;                  private EffectParameter[] params;
1139                                    
1140                  public                  public
1141                  EffectInstanceTreeNode (                  EffectInstanceTreeNode (
1142                          SamplerTreeModel treeModel, SendEffectChainTreeNode parent, EffectInstance ei                          AbstractTreeModel treeModel, SendEffectChainTreeNode parent, EffectInstance ei
1143                  ) {                  ) {
1144                          super(treeModel, parent);                          super(treeModel, parent);
1145                          effectInstance = ei;                          effectInstance = ei;
1146                          params = ei.getInfo().getParameters();                          params = ei.getInfo().getParameters();
1147                            
1148                            effectInstance.addEffectInstanceListener(this);
1149                    }
1150                    
1151                    @Override
1152                    public void
1153                    uninstall() {
1154                            effectInstance.removeEffectInstanceListener(this);
1155                            effectInstance = null;
1156                            params = null;
1157                            super.uninstall();
1158                  }                  }
1159                    
1160                  @Override                  @Override

Legend:
Removed from v.2199  
changed lines
  Added in v.2200

  ViewVC Help
Powered by ViewVC