5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.media.sound;
26
27 import java.util.Arrays;
28
29 /**
30 * A standard indexed director who chooses performers
31 * by there keyfrom,keyto,velfrom,velto properties.
32 *
33 * @author Karl Helgason
34 */
35 public final class ModelStandardIndexedDirector implements ModelDirector {
36
37 private final ModelPerformer[] performers;
38 private final ModelDirectedPlayer player;
39 private boolean noteOnUsed = false;
40 private boolean noteOffUsed = false;
41
42 // Variables needed for index
43 private byte[][] trantables;
44 private int[] counters;
139 for (int y = y_from; y < y_to; y++) {
140 int i = x_from + y * counters[0];
141 for (int x = x_from; x < x_to; x++) {
142 int[] mprev = mat[i];
143 if (mprev == null) {
144 mat[i] = new int[] { ix };
145 } else {
146 int[] mnew = new int[mprev.length + 1];
147 mnew[mnew.length - 1] = ix;
148 for (int k = 0; k < mprev.length; k++)
149 mnew[k] = mprev[k];
150 mat[i] = mnew;
151 }
152 i++;
153 }
154 }
155 ix++;
156 }
157 }
158
159 public void close() {
160 }
161
162 public void noteOff(int noteNumber, int velocity) {
163 if (!noteOffUsed)
164 return;
165 int[] plist = lookupIndex(noteNumber, velocity);
166 if(plist == null) return;
167 for (int i : plist) {
168 ModelPerformer p = performers[i];
169 if (p.isReleaseTriggered()) {
170 player.play(i, null);
171 }
172 }
173 }
174
175 public void noteOn(int noteNumber, int velocity) {
176 if (!noteOnUsed)
177 return;
178 int[] plist = lookupIndex(noteNumber, velocity);
179 if(plist == null) return;
180 for (int i : plist) {
181 ModelPerformer p = performers[i];
182 if (!p.isReleaseTriggered()) {
183 player.play(i, null);
184 }
185 }
186 }
187 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.media.sound;
27
28 import java.util.Arrays;
29
30 /**
31 * A standard indexed director who chooses performers
32 * by there keyfrom,keyto,velfrom,velto properties.
33 *
34 * @author Karl Helgason
35 */
36 public final class ModelStandardIndexedDirector implements ModelDirector {
37
38 private final ModelPerformer[] performers;
39 private final ModelDirectedPlayer player;
40 private boolean noteOnUsed = false;
41 private boolean noteOffUsed = false;
42
43 // Variables needed for index
44 private byte[][] trantables;
45 private int[] counters;
140 for (int y = y_from; y < y_to; y++) {
141 int i = x_from + y * counters[0];
142 for (int x = x_from; x < x_to; x++) {
143 int[] mprev = mat[i];
144 if (mprev == null) {
145 mat[i] = new int[] { ix };
146 } else {
147 int[] mnew = new int[mprev.length + 1];
148 mnew[mnew.length - 1] = ix;
149 for (int k = 0; k < mprev.length; k++)
150 mnew[k] = mprev[k];
151 mat[i] = mnew;
152 }
153 i++;
154 }
155 }
156 ix++;
157 }
158 }
159
160 @Override
161 public void close() {
162 }
163
164 @Override
165 public void noteOff(int noteNumber, int velocity) {
166 if (!noteOffUsed)
167 return;
168 int[] plist = lookupIndex(noteNumber, velocity);
169 if(plist == null) return;
170 for (int i : plist) {
171 ModelPerformer p = performers[i];
172 if (p.isReleaseTriggered()) {
173 player.play(i, null);
174 }
175 }
176 }
177
178 @Override
179 public void noteOn(int noteNumber, int velocity) {
180 if (!noteOnUsed)
181 return;
182 int[] plist = lookupIndex(noteNumber, velocity);
183 if(plist == null) return;
184 for (int i : plist) {
185 ModelPerformer p = performers[i];
186 if (!p.isReleaseTriggered()) {
187 player.play(i, null);
188 }
189 }
190 }
191 }
|