1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
23 |
package org.jsampler.task; |
package org.jsampler.task; |
24 |
|
|
25 |
import java.util.Vector; |
import java.util.Vector; |
|
import java.util.logging.Level; |
|
26 |
|
|
27 |
import org.jsampler.CC; |
import org.jsampler.CC; |
|
import org.jsampler.HF; |
|
28 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
29 |
import org.jsampler.SamplerModel; |
import org.jsampler.SamplerModel; |
30 |
|
|
48 |
} |
} |
49 |
|
|
50 |
/** The entry point of the task. */ |
/** The entry point of the task. */ |
51 |
|
@Override |
52 |
public void |
public void |
53 |
run() { |
exec() throws Exception { |
54 |
try { |
SamplerModel sm = CC.getSamplerModel(); |
55 |
SamplerModel sm = CC.getSamplerModel(); |
Integer[] chnIDs = CC.getClient().getSamplerChannelIDs(); |
56 |
Integer[] chnIDs = CC.getClient().getSamplerChannelIDs(); |
|
57 |
|
boolean found = false; |
58 |
boolean found = false; |
|
59 |
|
boolean oldValue = CC.getSamplerModel().getChannelListIsAdjusting(); |
60 |
boolean oldValue = CC.getSamplerModel().getChannelListIsAdjusting(); |
|
61 |
|
javax.swing.SwingUtilities.invokeAndWait(new Runnable() { |
62 |
javax.swing.SwingUtilities.invokeAndWait(new Runnable() { |
public void |
63 |
public void |
run() { |
64 |
run() { |
CC.getSamplerModel().setChannelListIsAdjusting(true); |
65 |
CC.getSamplerModel().setChannelListIsAdjusting(true); |
CC.getMainFrame().setAutoUpdateChannelListUI(false); |
|
CC.getMainFrame().setAutoUpdateChannelListUI(false); |
|
|
} |
|
|
}); |
|
|
|
|
|
for(SamplerChannelModel m : sm.getChannels()) { |
|
|
for(int i = 0; i < chnIDs.length; i++) { |
|
|
if(m.getChannelId() == chnIDs[i]) { |
|
|
chnIDs[i] = -1; |
|
|
found = true; |
|
|
} |
|
|
} |
|
|
|
|
|
if(!found) sm.removeChannelById(m.getChannelId()); |
|
|
found = false; |
|
66 |
} |
} |
67 |
|
}); |
68 |
Vector<SamplerChannel> v = new Vector<SamplerChannel>(); |
|
69 |
for(int id : chnIDs) { |
for(SamplerChannelModel m : sm.getChannels()) { |
70 |
if(id >= 0) v.add(CC.getClient().getSamplerChannelInfo(id)); |
for(int i = 0; i < chnIDs.length; i++) { |
71 |
|
if(m.getChannelId() == chnIDs[i]) { |
72 |
|
chnIDs[i] = -1; |
73 |
|
found = true; |
74 |
|
} |
75 |
} |
} |
76 |
|
|
77 |
for(int i = 0; i < v.size() - 1; i++) sm.addChannel(v.elementAt(i)); |
if(!found) sm.removeChannelById(m.getChannelId()); |
78 |
|
found = false; |
79 |
manageAutoUpdate(false); |
} |
80 |
|
|
81 |
if(v.size() > 0) sm.addChannel(v.elementAt(v.size() - 1)); |
Vector<SamplerChannel> v = new Vector<SamplerChannel>(); |
82 |
else if(!CC.getSamplerModel().getChannelListIsAdjusting()) { |
for(int id : chnIDs) { |
83 |
// FIXME: no change after |
if(id >= 0) v.add(CC.getClient().getSamplerChannelInfo(id)); |
|
// CC.getSamplerModel().setChannelListIsAdjusting(false); |
|
|
} |
|
|
} catch(Exception x) { |
|
|
setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x)); |
|
|
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
|
|
manageAutoUpdate(true); |
|
84 |
} |
} |
85 |
|
|
86 |
|
for(int i = 0; i < v.size() - 1; i++) sm.addChannel(v.elementAt(i)); |
87 |
|
|
88 |
|
manageAutoUpdate(false); |
89 |
|
|
90 |
|
if(v.size() > 0) sm.addChannel(v.elementAt(v.size() - 1)); |
91 |
|
else if(!CC.getSamplerModel().getChannelListIsAdjusting()) { |
92 |
|
// FIXME: no change after |
93 |
|
// CC.getSamplerModel().setChannelListIsAdjusting(false); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
@Override |
98 |
|
public void |
99 |
|
onError(Exception e) { |
100 |
|
manageAutoUpdate(true); |
101 |
} |
} |
102 |
|
|
103 |
private void |
private void |