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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1734 - (show annotations) (download)
Sun May 4 18:40:13 2008 UTC (15 years, 11 months ago) by iliev
File size: 3080 byte(s)
* bugfix: JSampler took forever to load a configuration with
  too many sampler channels
* Implemented option to show different channel view when
  the mouse pointer is over sampler channel
  (choose Edit/Preferences, then click the `Defaults' tab)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 *
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 java.util.logging.Level;
26
27 import org.jsampler.CC;
28 import org.jsampler.HF;
29 import org.jsampler.SamplerChannelModel;
30 import org.jsampler.SamplerModel;
31
32 import net.sf.juife.Task;
33
34 import static org.jsampler.JSI18n.i18n;
35
36
37 /**
38 * This task updates the sampler channel list.
39 * @author Grigor Iliev
40 */
41 public class UpdateChannels extends EnhancedTask {
42 /** Creates a new instance of <code>UpdateChannels</code>. */
43 public
44 UpdateChannels() {
45 setTitle("UpdateChannels_task");
46 setDescription(i18n.getMessage("UpdateChannels.description"));
47 }
48
49 /** The entry point of the task. */
50 public void
51 run() {
52 try {
53 SamplerModel sm = CC.getSamplerModel();
54 Integer[] chnIDs = CC.getClient().getSamplerChannelIDs();
55
56 boolean found = false;
57
58 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
59 public void
60 run() { CC.getMainFrame().setAutoUpdateChannelListUI(false); }
61 });
62
63 for(SamplerChannelModel m : sm.getChannels()) {
64 for(int i = 0; i < chnIDs.length; i++) {
65 if(m.getChannelId() == chnIDs[i]) {
66 chnIDs[i] = -1;
67 found = true;
68 }
69 }
70
71 if(!found) sm.removeChannelById(m.getChannelId());
72 found = false;
73 }
74
75 for(int id : chnIDs) {
76 if(id >= 0) sm.addChannel(CC.getClient().getSamplerChannelInfo(id));
77 }
78
79 manageAutoUpdate(false);
80 } catch(Exception x) {
81 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
82 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
83 manageAutoUpdate(true);
84 }
85 }
86
87 private void
88 manageAutoUpdate(boolean force) {
89 if(!force) {
90 Task[] tasks = CC.getTaskQueue().getPendingTasks();
91 for(Task t : tasks) if(t.equals(this)) return;
92 }
93
94 javax.swing.SwingUtilities.invokeLater(new Runnable() {
95 public void
96 run() {
97 CC.getMainFrame().setAutoUpdateChannelListUI(true);
98 CC.getMainFrame().updateChannelListUI();
99 }
100 });
101 }
102
103 /**
104 * Used to decrease the traffic. All task in the queue
105 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
106 * @see org.jsampler.CC#addTask
107 */
108 public boolean
109 equals(Object obj) {
110 if(obj == null) return false;
111 if(!(obj instanceof UpdateChannels)) return false;
112
113 return true;
114 }
115 }

  ViewVC Help
Powered by ViewVC