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

Annotation of /jsampler/trunk/src/org/jsampler/task/UpdateChannels.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2192 - (hide annotations) (download)
Fri Jun 24 21:34:51 2011 UTC (12 years, 10 months ago) by iliev
File size: 3643 byte(s)
* Initial implementation of Sampler Browser
  (choose Window/Sampler Browser) - another way to view/edit
  the sampler configuration (work in progress - for now only
  support for viewing/editing send effects)

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2192 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 787 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.task;
24    
25     import org.jsampler.CC;
26 iliev 1143 import org.jsampler.SamplerChannelModel;
27 iliev 787 import org.jsampler.SamplerModel;
28    
29 iliev 1737 import org.linuxsampler.lscp.SamplerChannel;
30    
31 iliev 1734 import net.sf.juife.Task;
32    
33 iliev 787 import static org.jsampler.JSI18n.i18n;
34    
35    
36     /**
37 iliev 1143 * This task updates the sampler channel list.
38 iliev 787 * @author Grigor Iliev
39     */
40 iliev 842 public class UpdateChannels extends EnhancedTask {
41 iliev 911 /** Creates a new instance of <code>UpdateChannels</code>. */
42 iliev 787 public
43     UpdateChannels() {
44     setTitle("UpdateChannels_task");
45     setDescription(i18n.getMessage("UpdateChannels.description"));
46 iliev 2192 //setCalculateElapsedTime(true);
47 iliev 787 }
48    
49 iliev 911 /** The entry point of the task. */
50 iliev 1867 @Override
51 iliev 787 public void
52 iliev 1867 exec() throws Exception {
53     SamplerModel sm = CC.getSamplerModel();
54     Integer[] chnIDs = CC.getClient().getSamplerChannelIDs();
55    
56 iliev 1880 boolean found = false, changed = false;
57 iliev 1867
58 iliev 1880 boolean isAdjustingOld = CC.getSamplerModel().getChannelListIsAdjusting();
59 iliev 1867
60     javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
61     public void
62     run() {
63     CC.getSamplerModel().setChannelListIsAdjusting(true);
64     CC.getMainFrame().setAutoUpdateChannelListUI(false);
65     }
66     });
67    
68     for(SamplerChannelModel m : sm.getChannels()) {
69     for(int i = 0; i < chnIDs.length; i++) {
70     if(m.getChannelId() == chnIDs[i]) {
71     chnIDs[i] = -1;
72     found = true;
73 iliev 1737 }
74 iliev 787 }
75    
76 iliev 1880 if(!found) {
77     sm.removeChannelById(m.getChannelId());
78     changed = true;
79     }
80 iliev 1867 found = false;
81 iliev 787 }
82 iliev 2192
83     SamplerChannel[] chns = CC.getClient().getSamplerChannels(chnIDs);
84 iliev 1867
85 iliev 2192 for(int i = 0; i < chns.length - 1; i++) sm.addChannel(chns[i]);
86 iliev 1867
87     manageAutoUpdate(false);
88    
89 iliev 2192 if(chns.length > 0) sm.addChannel(chns[chns.length - 1]);
90 iliev 1867 else if(!CC.getSamplerModel().getChannelListIsAdjusting()) {
91 iliev 1880 if(!isAdjustingOld && !changed); // do nothing if nothing is changed
92     else sm.addChannel(null); // fire dummy event to end an adjusting sequence
93 iliev 1867 }
94 iliev 787 }
95 iliev 1867
96     @Override
97     public void
98     onError(Exception e) {
99     manageAutoUpdate(true);
100     }
101 iliev 1734
102     private void
103     manageAutoUpdate(boolean force) {
104     if(!force) {
105     Task[] tasks = CC.getTaskQueue().getPendingTasks();
106     for(Task t : tasks) if(t.equals(this)) return;
107     }
108    
109 iliev 1818 try {
110     javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
111     public void
112     run() {
113     CC.getSamplerModel().setChannelListIsAdjusting(false);
114     CC.getMainFrame().setAutoUpdateChannelListUI(true);
115     CC.getMainFrame().updateChannelListUI();
116     }
117     });
118     } catch(Exception x) {
119     x.printStackTrace();
120     }
121 iliev 1734 }
122    
123     /**
124     * Used to decrease the traffic. All task in the queue
125     * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
126     * @see org.jsampler.CC#addTask
127     */
128 iliev 1818 @Override
129 iliev 1734 public boolean
130     equals(Object obj) {
131     if(obj == null) return false;
132     if(!(obj instanceof UpdateChannels)) return false;
133    
134     return true;
135     }
136 iliev 787 }

  ViewVC Help
Powered by ViewVC