SoundMonitor.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.*;
16: import java.awt.event.*;
17: import java.awt.image.*;
18: import java.lang.*;
19: import java.util.*;
20: import javax.swing.*;
21:
22: public class SoundMonitor {
23:
24:
25: public static final int SMN_WIDTH = 4 + 8 + 4 * (14 * 8 + 6) + 4;
26: public static final int SMN_OFFSET = SMN_WIDTH + 3 >> 2;
27:
28:
29: public static final byte SMN_BLACK = (byte) 0b00000000;
30: public static final byte SMN_BLUE = (byte) 0b01010101;
31: public static final byte SMN_ORANGE = (byte) 0b10101010;
32: public static final byte SMN_WHITE = (byte) 0b11111111;
33:
34:
35: public static final byte[] SMN_FONT_1 = new byte[5 * 127];
36: public static final byte[] SMN_FONT_2 = new byte[5 * 127];
37: public static final byte[] SMN_FONT_3 = new byte[5 * 127];
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144: public static final byte[] SMN_ICON_1 = "UT@\4A\4A\4A\4A\4A\4@\4UTUT@\4ED@DEDD\4ED@\4UTUT@\4ED@DED@DED@\4UTUT@\4DDDDED@D@D@\4UTUT@\4EDD\4ED@DED@\4UTUT@\4EDD\4EDDDED@\4UTUT@\4ED@D@D@D@D@\4UTUT@\4EDDDEDDDED@\4UTUT@\4DDDDEDEDDD@\4UTUT@\4ADD\4A\4@DE\4@\4UTUT@\4E\4DDE\4D\4D\4@\4UT".getBytes (XEiJ.ISO_8859_1);
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249: public static final byte[] SMN_ICON_3 = "\377\374\300\f\303\f\303\f\303\f\303\f\303\f\300\f\377\374\377\374\300\f\317\314\300\314\317\314\314\f\317\314\300\f\377\374\377\374\300\f\317\314\300\314\317\314\300\314\317\314\300\f\377\374\377\374\300\f\314\314\314\314\317\314\300\314\300\314\300\f\377\374\377\374\300\f\317\314\314\f\317\314\300\314\317\314\300\f\377\374\377\374\300\f\317\314\314\f\317\314\314\314\317\314\300\f\377\374\377\374\300\f\317\314\300\314\300\314\300\314\300\314\300\f\377\374\377\374\300\f\317\314\314\314\317\314\314\314\317\314\300\f\377\374\377\374\300\f\314\314\314\314\317\314\317\314\314\314\300\f\377\374\377\374\300\f\303\314\314\f\303\f\300\314\317\f\300\f\377\374\377\374\300\f\317\f\314\314\317\f\314\f\314\f\300\f\377\374".getBytes (XEiJ.ISO_8859_1);
250:
251:
252: public static final int SMN_WAVE_X = 12;
253: public static final int SMN_WAVE_Y = 4;
254: public static final int SMN_WAVE_WIDTH = SMN_WIDTH - 4 - SMN_WAVE_X;
255: public static final int SMN_WAVE_VALUE_SHIFT = 11;
256: public static final int SMN_WAVE_HEIGHT = (1 << 16 - SMN_WAVE_VALUE_SHIFT) + 1;
257: public static final int SMN_WAVE_SCALE_X_MAX = 5;
258: public static final int SMN_WAVE_SCALE_Y_MAX = 3;
259: public static final int[] smnOPMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
260: public static final int[] smnPCMBuffer = new int[SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES];
261: public static final int[][] smnWaveIndex0 = new int[SMN_WAVE_SCALE_X_MAX + 1][];
262: public static final int[][] smnWaveIndex1 = new int[SMN_WAVE_SCALE_X_MAX + 1][];
263: public static int smnWaveScaleX;
264: public static int smnWaveScaleY;
265: public static int smnWaveOffsetMax;
266: public static int smnWaveOffset;
267: public static int smnWaveElevation;
268: public static boolean smnWaveDragOn;
269: public static int smnWavePressedX;
270: public static int smnWavePressedY;
271: public static final int[] smnWaveLastYPCMLeft = new int[2];
272: public static final int[] smnWaveLastYPCMRight = new int[2];
273: public static final int[] smnWaveLastYOPMLeft = new int[2];
274: public static final int[] smnWaveLastYOPMRight = new int[2];
275:
276:
277:
278: public static final int SMN_SPECTRUM_X = 4;
279: public static final int SMN_SPECTRUM_Y = SMN_WAVE_Y + SMN_WAVE_HEIGHT + 4;
280: public static final int SMN_SPECTRUM_WIDTH = 480;
281: public static final int SMN_SPECTRUM_HEIGHT = 32;
282:
283:
284:
285:
286:
287:
288:
289:
290:
291: public static final byte[] SMN_SPECTRUM_MAP = "\0\1\2\3\5\7\t\13\r\17\21\23\25\27\31\33\35\37!#$%&\'()*+-/13579;=?ACEGIKMOQSUWY[\\]^_".getBytes (XEiJ.ISO_8859_1);
292: public static final int SMN_SPECTRUM_BIT = 10;
293: public static final int SMN_SPECTRUM_N = 1 << SMN_SPECTRUM_BIT;
294: public static final int SMN_SPECTRUM_PARTITIONS = 6;
295: public static final int SMN_SPECTRUM_RANGE = 480 / SMN_SPECTRUM_PARTITIONS;
296: public static final int[] SMN_SPECTRUM_INTERVAL = new int[] { 100, 100, 50, 25, 10, 5 };
297: public static final double[][] smnSpectrumBuffer = new double[SMN_SPECTRUM_PARTITIONS][];
298: public static final double[] smnSpectrumX = new double[SMN_SPECTRUM_N];
299: public static final double[] smnSpectrumY = new double[SMN_SPECTRUM_N];
300: public static final int[] smnSpectrumIndex = new int[480];
301: public static final int[] smnSpectrumValue = new int[480];
302: public static final double[] smnSpectrumWindow = new double[SMN_SPECTRUM_N];
303: public static final int SMN_SPECTRUM_TRAIL = 2;
304: public static final double SMN_SPECTRUM_SCALE = 64.0;
305: public static FFT smnFFT;
306:
307:
308: public static final int[] SMN_440HZ_PATTERN = { 18, SMN_BLUE, 0, 0, -1, 1, 1, 1, -2, 2, 2, 2, -1, 3, 1, 3, 0, 4 };
309:
310:
311: public static final int SMN_KEY_X = 12;
312: public static final int SMN_KEY_Y = SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT + 1;
313: public static final int SMN_KEY_HEIGHT = 6 + 12 * 8;
314: public static final byte[] SMN_KEY_COLOR = {
315: SMN_WHITE,
316: SMN_BLUE,
317: SMN_WHITE,
318: SMN_BLUE,
319: SMN_WHITE,
320: SMN_WHITE,
321: SMN_BLUE,
322: SMN_WHITE,
323: SMN_BLUE,
324: SMN_WHITE,
325: SMN_BLUE,
326: SMN_WHITE,
327: };
328: public static final int[] smnKey = new int[8];
329:
330:
331: public static final int SMN_TONE_X = 20;
332: public static final int SMN_TONE_Y = SMN_KEY_Y + SMN_KEY_HEIGHT + 4;
333: public static final int SMN_TONE_BOX_COLS = 3 * 12 + 2;
334: public static final int SMN_TONE_BOX_HEIGHT = 6 * 7 + 4;
335: public static final int SMN_TONE_HEIGHT = SMN_TONE_BOX_HEIGHT * 3 - 4;
336: public static final char[] SMN_TONE_H1 = "FC SL WA SY SP PD AD PS AS PN" .toCharArray ();
337: public static final char[] SMN_TONE_V0 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
338: public static final char[] SMN_TONE_H2 = "AR 1R 2R RR 1L TL KS ML T1 T2 AE".toCharArray ();
339: public static final char[] SMN_TONE_M1 = "M1".toCharArray ();
340: public static final char[] SMN_TONE_V1 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
341: public static final char[] SMN_TONE_C1 = "C1".toCharArray ();
342: public static final char[] SMN_TONE_V2 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
343: public static final char[] SMN_TONE_M2 = "M2".toCharArray ();
344: public static final char[] SMN_TONE_V3 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
345: public static final char[] SMN_TONE_C2 = "C2".toCharArray ();
346: public static final char[] SMN_TONE_V4 = "00 00 00 00 00 00 00 00 00 00 00".toCharArray ();
347:
348:
349: public static final int SMN_PCM_COL = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * 2 + 6;
350: public static final int SMN_PCM_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2;
351:
352:
353:
354:
355:
356:
357: public static final char[][] SMN_PCM_OSCILLATOR = {
358: " 8".toCharArray (),
359: " 4".toCharArray (),
360: " 8".toCharArray (),
361: "16".toCharArray (),
362: };
363: public static final char[][] SMN_PCM_DIVIDER = {
364: "1024".toCharArray (),
365: "768 ".toCharArray (),
366: "512 ".toCharArray (),
367: "768 ".toCharArray (),
368: };
369: public static final char[][] SMN_PCM_FREQ = {
370: " 7.8".toCharArray (),
371: "10.4".toCharArray (),
372: "15.6".toCharArray (),
373: "10.4".toCharArray (),
374: " 3.9".toCharArray (),
375: " 5.2".toCharArray (),
376: " 7.8".toCharArray (),
377: " 5.2".toCharArray (),
378: " 7.8".toCharArray (),
379: "10.4".toCharArray (),
380: "15.6".toCharArray (),
381: "10.4".toCharArray (),
382: "15.6".toCharArray (),
383: "20.8".toCharArray (),
384: "31.3".toCharArray (),
385: "20.8".toCharArray (),
386: };
387: public static final char[][] SMN_PCM_PLAY = {
388: " ".toCharArray (),
389: "PLAY".toCharArray (),
390: };
391: public static final char[][] SMN_PCM_DATA = {
392: " ".toCharArray (),
393: "DATA".toCharArray (),
394: };
395: public static final char[][] SMN_PCM_LEFT = {
396: " ".toCharArray (),
397: "LEFT".toCharArray (),
398: };
399: public static final char[][] SMN_PCM_RIGHT = {
400: " ".toCharArray (),
401: "RIGHT".toCharArray (),
402: };
403:
404:
405: public static final int SMN_PALET_X = SMN_TONE_X + 4 * SMN_TONE_BOX_COLS * 2;
406: public static final int SMN_PALET_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2 + 6 * 2;
407: public static final int SMN_PALET_WIDTH = 140;
408: public static final int SMN_PALET_HEIGHT = 6 * 5;
409: public static final int[][] SMN_SLIDER_ARRAY = {
410: { SMN_PALET_X + 4 * 2, SMN_PALET_Y + 6 * 1, 48, SMN_WHITE , 0 },
411: { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 1, 32, SMN_WHITE , 0 },
412: { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 1, 32, SMN_WHITE , 0 },
413: { SMN_PALET_X + 4 * 2, SMN_PALET_Y + 6 * 2, 48, SMN_BLUE , 30 },
414: { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 2, 32, SMN_BLUE , 30 },
415: { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 2, 32, SMN_BLUE , 32 },
416: { SMN_PALET_X + 4 * 2, SMN_PALET_Y + 6 * 3, 48, SMN_ORANGE, 3 },
417: { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 3, 32, SMN_ORANGE, 30 },
418: { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 3, 32, SMN_ORANGE, 32 },
419: { SMN_PALET_X + 4 * 2, SMN_PALET_Y + 6 * 4, 48, SMN_WHITE , 30 },
420: { SMN_PALET_X + 4 * 16, SMN_PALET_Y + 6 * 4, 32, SMN_WHITE , 3 },
421: { SMN_PALET_X + 4 * 26, SMN_PALET_Y + 6 * 4, 32, SMN_WHITE , 30 },
422: };
423: public static final int[][] SMN_SLIDER_PATTERN = {
424: { 18, SMN_WHITE , 1, -2, 2, -2, 0, -1, 3, -1, 0, 1, 3, 1, 1, 2, 2, 2,
425: 14, SMN_BLACK , 1, -1, 2, -1, 1, 0, 2, 0, 1, 1, 2, 1 },
426: { 26, SMN_BLUE , 1, -2, 2, -2, 0, -1, 1, -1, 2, -1, 3, -1, 0, 1, 1, 1, 2, 1, 3, 1, 1, 2, 2, 2 },
427: { 26, SMN_ORANGE, 1, -2, 2, -2, 0, -1, 1, -1, 2, -1, 3, -1, 0, 1, 1, 1, 2, 1, 3, 1, 1, 2, 2, 2 },
428: { 26, SMN_WHITE , 1, -2, 2, -2, 0, -1, 1, -1, 2, -1, 3, -1, 0, 1, 1, 1, 2, 1, 3, 1, 1, 2, 2, 2 },
429: };
430: public static int smnPaletDragSlider;
431: public static int smnPaletPressedX;
432: public static IndexColorModel smnColorModel;
433:
434:
435: public static final int SMN_PAUSE_WIDTH = 16;
436: public static final int SMN_PAUSE_HEIGHT = 16;
437: public static final int SMN_PAUSE_X = SMN_WIDTH - 4 - SMN_PAUSE_WIDTH;
438: public static final int SMN_PAUSE_Y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * 2 + 6 * 3 + (6 * 4 - SMN_PAUSE_HEIGHT >> 1);
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460: public static final byte[] SMN_PAUSE_ICON_3 = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\377\377\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482: public static final byte[] SMN_PLAY_ICON_3 = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\360\0\f0\377\0\f0\377\360\f0\377\377\f0\377\377\f0\377\360\f0\377\0\f0\360\0\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
483: public static boolean smnPauseRequest;
484: public static boolean smnPauseUpdate;
485:
486:
487: public static final int SMN_ZOOM_WIDTH = 16;
488: public static final int SMN_ZOOM_HEIGHT = 16;
489: public static final int SMN_ZOOM_X = SMN_PAUSE_X;
490: public static final int SMN_ZOOM_Y = SMN_PAUSE_Y - 24;
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512: public static final byte[] SMN_ZOOM_X1_ICON = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\0\17\f0\0\17\f0\0\17\f3\317\17\f3\317\17\f0\374\17\f3\317\17\f3\317\17\f0\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534: public static final byte[] SMN_ZOOM_X2_ICON = "\0\0\0\0?\377\377\3740\0\0\f0\0\0\f0\0?\f0\0\3\3140\0\3\3143\317\17\f3\317\17\f0\374<\f3\317<\f3\317?\3140\0\0\f0\0\0\f?\377\377\374\0\0\0\0".getBytes (XEiJ.ISO_8859_1);
535: public static int smnZoomRequest;
536: public static int smnZoomShift;
537:
538:
539: public static final int SMN_HEIGHT = SMN_TONE_Y + SMN_TONE_HEIGHT + 4;
540: public static boolean smnIsVisible;
541: public static BufferedImage smnImage;
542: public static byte[] smnBitmap;
543: public static JPanel smnPanel;
544: public static JFrame smnFrame;
545:
546:
547:
548: public static void smnInit () {
549:
550:
551: {
552: final long m = 0b01010100_01010000_01000100_01000000_00010100_00010000_00000100_00000000L;
553: int k = 0;
554: for (int i = 0; i < 127; i++) {
555: int t = Indicator.IND_ASCII_3X5[i];
556: int d;
557:
558: d = (int) (m >>> (t >>> 12 - 3 & 7 << 3)) & 255;
559: SMN_FONT_1[k] = (byte) d;
560: SMN_FONT_2[k] = (byte) (d * 2);
561: SMN_FONT_3[k] = (byte) (d * 3);
562: k++;
563:
564: d = (int) (m >>> (t >>> 9 - 3 & 7 << 3)) & 255;
565: SMN_FONT_1[k] = (byte) d;
566: SMN_FONT_2[k] = (byte) (d * 2);
567: SMN_FONT_3[k] = (byte) (d * 3);
568: k++;
569:
570: d = (int) (m >>> (t >>> 6 - 3 & 7 << 3)) & 255;
571: SMN_FONT_1[k] = (byte) d;
572: SMN_FONT_2[k] = (byte) (d * 2);
573: SMN_FONT_3[k] = (byte) (d * 3);
574: k++;
575:
576: d = (int) (m >>> (t & 7 << 3)) & 255;
577: SMN_FONT_1[k] = (byte) d;
578: SMN_FONT_2[k] = (byte) (d * 2);
579: SMN_FONT_3[k] = (byte) (d * 3);
580: k++;
581:
582: d = (int) (m >>> (t << 6 - 3 & 7 << 3)) & 255;
583: SMN_FONT_1[k] = (byte) d;
584: SMN_FONT_2[k] = (byte) (d * 2);
585: SMN_FONT_3[k] = (byte) (d * 3);
586: k++;
587: }
588: }
589:
590:
591:
592:
593: for (int scaleX = 0; scaleX <= SMN_WAVE_SCALE_X_MAX; scaleX++) {
594: int limit = SMN_WAVE_WIDTH << scaleX;
595: int[] index0 = smnWaveIndex0[scaleX] = new int[limit];
596: if (SoundSource.SND_CHANNELS == 1) {
597: for (int x = 0; x < limit; x++) {
598: index0[x] = x * OPM.OPM_BLOCK_SAMPLES / limit;
599: }
600: } else {
601: int[] index1 = smnWaveIndex1[scaleX] = new int[limit];
602: for (int x = 0; x < limit; x++) {
603: index1[x] = (index0[x] = x * OPM.OPM_BLOCK_SAMPLES / limit << 1) + 1;
604: }
605: }
606: }
607: smnWaveScaleX = 0;
608: smnWaveScaleY = 0;
609: smnWaveOffsetMax = (SMN_WAVE_WIDTH << smnWaveScaleX) - SMN_WAVE_WIDTH;
610: smnWaveOffset = 0;
611: smnWaveElevation = 0;
612: smnWaveDragOn = false;
613: smnWavePressedX = -1;
614: smnWavePressedY = -1;
615:
616:
617:
618:
619: smnWaveLastYPCMLeft[0] = 0;
620: smnWaveLastYPCMLeft[1] = 0;
621: smnWaveLastYPCMRight[0] = 0;
622: smnWaveLastYPCMRight[1] = 0;
623: smnWaveLastYOPMLeft[0] = 0;
624: smnWaveLastYOPMLeft[1] = 0;
625: smnWaveLastYOPMRight[0] = 0;
626: smnWaveLastYOPMRight[1] = 0;
627:
628:
629:
630:
631:
632:
633:
634: for (int partition = 0; partition < SMN_SPECTRUM_PARTITIONS; partition++) {
635: if (partition != 1) {
636: smnSpectrumBuffer[partition] = new double[SMN_SPECTRUM_N];
637: }
638: double coeff = (double) SMN_SPECTRUM_N * 440.0 / 62500.0 * (double) SMN_SPECTRUM_INTERVAL[partition];
639: for (int x = SMN_SPECTRUM_RANGE * partition, x1 = x + SMN_SPECTRUM_RANGE; x < x1; x++) {
640: int k = (int) Math.floor (coeff * Math.pow (
641: 2.0,
642: (double) (((56 - 8 + x) / 56 - 1) * 96 + SMN_SPECTRUM_MAP[(56 - 8 + x) % 56] - (96 * 4 + 75)) / 96.0));
643: int n = (int) Math.floor (coeff * Math.pow (
644: 2.0,
645: (double) (((56 - 8 + 1 + x) / 56 - 1) * 96 + SMN_SPECTRUM_MAP[(56 - 8 + 1 + x) % 56] - (96 * 4 + 75)) / 96.0)) - k;
646: smnSpectrumIndex[x] = n << 16 | k;
647:
648: }
649: }
650: Arrays.fill (smnSpectrumValue, -1);
651:
652: for (int i = 0; i < SMN_SPECTRUM_N; i++) {
653: smnSpectrumWindow[i] = 0.5 * (1.0 - Math.cos (2.0 * Math.PI / (double) SMN_SPECTRUM_N * (double) i));
654: }
655: smnFFT = new FFT (SMN_SPECTRUM_N);
656:
657:
658:
659: smnPauseRequest = false;
660: smnPauseUpdate = true;
661:
662:
663: smnZoomRequest = 0;
664: smnZoomShift = 1;
665:
666:
667: smnPaletDragSlider = -1;
668: smnPaletPressedX = 0;
669:
670: }
671:
672:
673: public static void smnStart () {
674: if (RestorableFrame.rfmGetOpened (Settings.SGS_SMN_FRAME_KEY)) {
675: smnOpen ();
676: }
677: }
678:
679:
680:
681: public static void smnOpen () {
682: if (smnFrame == null) {
683: smnMakeFrame ();
684: smnIsVisible = true;
685: smnUpdate ();
686: smnFrame.setVisible (true);
687: } else {
688: smnIsVisible = true;
689: smnUpdate ();
690: smnFrame.setVisible (true);
691: }
692: }
693:
694:
695:
696:
697: public static void smnMakeFrame () {
698:
699:
700: smnMakeImage ();
701:
702:
703: smnPanel = ComponentFactory.setFixedSize (new JPanel () {
704: @Override public void paint (Graphics g) {
705: if (smnZoomShift == 0) {
706: g.drawImage (smnImage, 0, 0, null);
707: } else {
708: g.drawImage (smnImage,
709: 0, 0, SMN_WIDTH << smnZoomShift, SMN_HEIGHT << smnZoomShift,
710: 0, 0, SMN_WIDTH, SMN_HEIGHT,
711: null);
712: }
713: }
714: @Override protected void paintComponent (Graphics g) {
715: }
716: @Override protected void paintBorder (Graphics g) {
717: }
718: @Override protected void paintChildren (Graphics g) {
719: }
720: @Override public void update (Graphics g) {
721: }
722: }, SMN_WIDTH, SMN_HEIGHT);
723: smnPanel.setOpaque (true);
724:
725:
726: ComponentFactory.addListener (
727: smnPanel,
728: new MouseAdapter () {
729: @Override public void mouseClicked (MouseEvent me) {
730: int x = me.getX () >> smnZoomShift;
731: int y = me.getY () >> smnZoomShift;
732: int button = me.getButton ();
733: int modifiersEx = me.getModifiersEx ();
734: if (SMN_WAVE_X <= x && x < SMN_WAVE_X + SMN_WAVE_WIDTH &&
735: SMN_WAVE_Y <= y && y < SMN_WAVE_Y + SMN_WAVE_HEIGHT) {
736: if ((modifiersEx & InputEvent.SHIFT_DOWN_MASK) == 0) {
737: int d = 0;
738: if (button == MouseEvent.BUTTON1) {
739: if (smnWaveScaleX < SMN_WAVE_SCALE_X_MAX) {
740: d = 1;
741: }
742: } else if (button == MouseEvent.BUTTON3) {
743: if (0 < smnWaveScaleX) {
744: d = -1;
745: }
746: }
747: if (d != 0) {
748: smnWaveScaleX += d;
749: smnWaveOffsetMax = (SMN_WAVE_WIDTH << smnWaveScaleX) - SMN_WAVE_WIDTH;
750: int o = x - SMN_WAVE_X;
751: smnWaveOffset = Math.max (0, Math.min (smnWaveOffsetMax, (d >= 0 ? smnWaveOffset + o << d : smnWaveOffset + o >> -d) - o));
752: if (smnPauseUpdate) {
753: smnWavePaint ();
754: smnPanel.repaint ();
755: }
756: }
757: } else {
758: int d = 0;
759: if (button == MouseEvent.BUTTON1) {
760: if (smnWaveScaleY < SMN_WAVE_SCALE_Y_MAX) {
761: d = 1;
762: }
763: } else if (button == MouseEvent.BUTTON3) {
764: if (0 < smnWaveScaleY) {
765: d = -1;
766: }
767: }
768: if (d != 0) {
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779: smnWaveScaleY += d;
780: int spaceY = (SMN_WAVE_HEIGHT >> 1 << smnWaveScaleY) - (SMN_WAVE_HEIGHT >> 1);
781: int o = y - (SMN_WAVE_Y + SMN_WAVE_HEIGHT / 2);
782: smnWaveElevation = Math.max (-spaceY, Math.min (spaceY, (d >= 0 ? smnWaveElevation + o << d : smnWaveElevation + o >> -d) - o));
783: if (smnPauseUpdate) {
784: smnWavePaint ();
785: smnPanel.repaint ();
786: }
787: }
788: }
789: } else if (SMN_PAUSE_X <= x && x < SMN_PAUSE_X + SMN_PAUSE_WIDTH &&
790: SMN_PAUSE_Y <= y && y < SMN_PAUSE_Y + SMN_PAUSE_HEIGHT) {
791: smnPauseRequest = !smnPauseRequest;
792: } else if (SMN_ZOOM_X <= x && x < SMN_ZOOM_X + SMN_ZOOM_WIDTH &&
793: SMN_ZOOM_Y <= y && y < SMN_ZOOM_Y + SMN_ZOOM_HEIGHT) {
794: smnZoomRequest = smnZoomShift ^ 1;
795: }
796: }
797: @Override public void mousePressed (MouseEvent me) {
798: int x = me.getX () >> smnZoomShift;
799: int y = me.getY () >> smnZoomShift;
800: smnWaveDragOn = false;
801: smnPaletDragSlider = -1;
802: if (SMN_WAVE_X <= x && x < SMN_WAVE_X + SMN_WAVE_WIDTH &&
803: SMN_WAVE_Y <= y && y < SMN_WAVE_Y + SMN_WAVE_HEIGHT) {
804: smnWaveDragOn = true;
805: smnWavePressedX = x;
806: smnWavePressedY = y;
807: } else if (SMN_PALET_X <= x && x < SMN_PALET_X + SMN_PALET_WIDTH &&
808: SMN_PALET_Y <= y && y < SMN_PALET_Y + SMN_PALET_HEIGHT) {
809: for (int n = 0; n < SMN_SLIDER_ARRAY.length; n++) {
810: int[] slider = SMN_SLIDER_ARRAY[n];
811: int x0 = slider[0];
812: int y0 = slider[1];
813: int max = slider[2];
814: int value = slider[4];
815: if (x0 <= x && x < x0 + max + 4 && y0 <= y && y < y0 + 5) {
816: smnPaletDragSlider = n;
817: smnPaletPressedX = x;
818: if (x < x0 + value || x0 + value + 4 <= x) {
819: slider[4] = Math.max (0, Math.min (max, x - x0));
820: smnDrawPaletSlider ();
821: smnUpdateColor ();
822: }
823: break;
824: }
825: }
826: }
827: }
828: @Override public void mouseReleased (MouseEvent me) {
829: smnWaveDragOn = false;
830: smnPaletDragSlider = -1;
831: }
832: });
833:
834:
835: ComponentFactory.addListener (
836: smnPanel,
837: new MouseMotionAdapter () {
838: @Override public void mouseDragged (MouseEvent me) {
839: int x = me.getX () >> smnZoomShift;
840: int y = me.getY () >> smnZoomShift;
841: if (smnWaveDragOn) {
842: int offset = Math.max (0, Math.min (smnWaveOffsetMax, smnWaveOffset - (x - smnWavePressedX)));
843: int spaceY = (SMN_WAVE_HEIGHT >> 1 << smnWaveScaleY) - (SMN_WAVE_HEIGHT >> 1);
844: int elevation = Math.max (-spaceY, Math.min (spaceY, smnWaveElevation - (y - smnWavePressedY)));
845: smnWavePressedX = x;
846: smnWavePressedY = y;
847: if (smnWaveOffset != offset || smnWaveElevation != elevation) {
848: smnWaveOffset = offset;
849: smnWaveElevation = elevation;
850: if (smnPauseUpdate) {
851: smnWavePaint ();
852: smnPanel.repaint ();
853: }
854: }
855: } else if (smnPaletDragSlider >= 0) {
856: int[] slider = SMN_SLIDER_ARRAY[smnPaletDragSlider];
857: int max = slider[2];
858: int value = slider[4];
859: slider[4] = Math.max (0, Math.min (max, value + x - smnPaletPressedX));
860: smnPaletPressedX = x;
861: smnDrawPaletSlider ();
862: smnUpdateColor ();
863: }
864: }
865: });
866:
867:
868: smnFrame = Multilingual.mlnTitle (
869: ComponentFactory.createRestorableSubFrame (
870: Settings.SGS_SMN_FRAME_KEY,
871: "Sound Monitor",
872: null,
873: smnPanel,
874: false
875: ),
876: "ja", "音声モニタ");
877: ComponentFactory.addListener (
878: smnFrame,
879: new WindowAdapter () {
880: @Override public void windowClosing (WindowEvent we) {
881: smnIsVisible = false;
882: }
883: });
884:
885: }
886:
887:
888:
889: public static void smnMakeImage () {
890:
891:
892: smnMakeColorModel ();
893: smnImage = new BufferedImage (SMN_WIDTH, SMN_HEIGHT, BufferedImage.TYPE_BYTE_BINARY, smnColorModel);
894: byte[] bb = smnBitmap = ((DataBufferByte) smnImage.getRaster ().getDataBuffer ()).getData ();
895:
896:
897:
898:
899:
900:
901:
902: smnDrawIcon3 (SMN_SPECTRUM_X / 4, SMN_SPECTRUM_Y, 9);
903:
904:
905: smnDrawPattern (SMN_KEY_X + 56 * 4 + 43, SMN_KEY_Y, SMN_440HZ_PATTERN);
906:
907:
908: for (int ch = 0; ch < 8; ch++) {
909:
910: smnDrawIcon3 (SMN_KEY_X / 4 - 2, SMN_KEY_Y + 6 + 12 * ch, ch);
911: smnKey[ch] = -1;
912: for (int o = 0, i = SMN_KEY_X / 4 + SMN_OFFSET * (SMN_KEY_Y + 6 + 12 * ch); ; o++, i += 14) {
913: smnDrawChar1 (SMN_KEY_X / 4 + 14 * o, SMN_KEY_Y, '0' + o);
914: smnPaintKey (i , 0, SMN_KEY_COLOR[ 0]);
915: smnPaintKey (i + 1, 1, SMN_KEY_COLOR[ 1]);
916: smnPaintKey (i + 2, 2, SMN_KEY_COLOR[ 2]);
917: smnPaintKey (i + 3, 3, SMN_KEY_COLOR[ 3]);
918: smnPaintKey (i + 4, 4, SMN_KEY_COLOR[ 4]);
919: if (o == 8) {
920: break;
921: }
922: smnPaintKey (i + 6, 5, SMN_KEY_COLOR[ 5]);
923: smnPaintKey (i + 7, 6, SMN_KEY_COLOR[ 6]);
924: smnPaintKey (i + 8, 7, SMN_KEY_COLOR[ 7]);
925: smnPaintKey (i + 9, 8, SMN_KEY_COLOR[ 8]);
926: smnPaintKey (i + 10, 9, SMN_KEY_COLOR[ 9]);
927: smnPaintKey (i + 11, 10, SMN_KEY_COLOR[10]);
928: smnPaintKey (i + 12, 11, SMN_KEY_COLOR[11]);
929: }
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940: {
941: int x = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * (0b01_00_10_01_00_10_01_00 >> (ch << 1) & 3);
942: int y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * (0b10_10_01_01_01_00_00_00 >> (ch << 1) & 3);
943: smnDrawIcon3 (x, y, ch);
944: smnDrawString1 (3 + x, y, SMN_TONE_H1);
945: smnDrawString1 (3 + x, 6 * 2 + y, SMN_TONE_H2);
946: smnDrawString1 ( x, 6 * 3 + y, SMN_TONE_M1);
947: smnDrawString1 ( x, 6 * 4 + y, SMN_TONE_C1);
948: smnDrawString1 ( x, 6 * 5 + y, SMN_TONE_M2);
949: smnDrawString1 ( x, 6 * 6 + y, SMN_TONE_C2);
950: }
951: }
952:
953:
954: smnDrawIcon3 (SMN_PCM_COL, SMN_PCM_Y, 10);
955: smnDrawString3 (SMN_PCM_COL + 5, SMN_PCM_Y , "MHz");
956: smnDrawString3 (SMN_PCM_COL + 9, SMN_PCM_Y , "1/");
957: smnDrawString3 (SMN_PCM_COL + 20, SMN_PCM_Y , "kHz");
958:
959:
960:
961:
962:
963:
964:
965:
966:
967: smnDrawChar1 (SMN_PALET_X / 4 + 8, SMN_PALET_Y, 'H');
968: smnDrawChar1 (SMN_PALET_X / 4 + 20, SMN_PALET_Y, 'S');
969: smnDrawChar1 (SMN_PALET_X / 4 + 30, SMN_PALET_Y, 'B');
970: for (int p = 0; p < 4; p++) {
971: smnDrawChar1 (SMN_PALET_X / 4, SMN_PALET_Y + 6 + 6 * p, '0' + p);
972: }
973: smnDrawPaletSlider ();
974:
975: }
976:
977:
978:
979: public static void smnDrawPaletSlider () {
980: for (int p = 0; p < 4; p++) {
981: int[] pattern = SMN_SLIDER_PATTERN[p];
982: smnDrawSlider (SMN_SLIDER_ARRAY[3 * p ], pattern);
983: smnDrawSlider (SMN_SLIDER_ARRAY[3 * p + 1], pattern);
984: smnDrawSlider (SMN_SLIDER_ARRAY[3 * p + 2], pattern);
985: }
986: }
987:
988:
989:
990: public static void smnMakeColorModel () {
991: byte[] r = new byte[4];
992: byte[] g = new byte[4];
993: byte[] b = new byte[4];
994: for (int p = 0; p < 4; p++) {
995: int rgb = Color.HSBtoRGB ((float) SMN_SLIDER_ARRAY[3 * p ][4] / 48F,
996: (float) SMN_SLIDER_ARRAY[3 * p + 1][4] / 32F,
997: (float) SMN_SLIDER_ARRAY[3 * p + 2][4] / 32F);
998: if (false) {
999: System.out.printf ("%d 0x%08x %2d %2d %2d\n", p, rgb,
1000: SMN_SLIDER_ARRAY[3 * p ][4],
1001: SMN_SLIDER_ARRAY[3 * p + 1][4],
1002: SMN_SLIDER_ARRAY[3 * p + 2][4]);
1003: }
1004: r[p] = (byte) (rgb >> 16);
1005: g[p] = (byte) (rgb >> 8);
1006: b[p] = (byte) rgb;
1007: }
1008: smnColorModel = new IndexColorModel (2, 4, r, g, b);
1009: }
1010:
1011:
1012: public static void smnUpdateColor () {
1013: smnMakeColorModel ();
1014: smnImage = new BufferedImage (smnColorModel, smnImage.getRaster(), false, null);
1015:
1016: smnPanel.repaint ();
1017: }
1018:
1019:
1020:
1021: public static void smnUpdate () {
1022: byte[] bb = smnBitmap;
1023:
1024:
1025: if (smnZoomShift != smnZoomRequest) {
1026: smnZoomShift = smnZoomRequest;
1027: byte[] icon = smnZoomShift == 0 ? SMN_ZOOM_X2_ICON : SMN_ZOOM_X1_ICON;
1028: int i = SMN_ZOOM_X / 4 + SMN_OFFSET * SMN_ZOOM_Y;
1029: int j = 0;
1030: for (int v = 0; v < SMN_ZOOM_HEIGHT; v++) {
1031: for (int u = 0; u < SMN_ZOOM_WIDTH; u += 4) {
1032: bb[i++] = icon[j++];
1033: }
1034: i += SMN_OFFSET - SMN_ZOOM_WIDTH / 4;
1035: }
1036: int panelWidth = SMN_WIDTH << smnZoomShift;
1037: int panelHeight = SMN_HEIGHT << smnZoomShift;
1038: int marginWidth = smnFrame.getWidth () - smnPanel.getWidth ();
1039: int marginHeight = smnFrame.getHeight () - smnPanel.getHeight ();
1040: ComponentFactory.setFixedSize (smnFrame, panelWidth + marginWidth, panelHeight + marginHeight);
1041: smnFrame.setResizable (false);
1042: ComponentFactory.setFixedSize (smnPanel, panelWidth, panelHeight);
1043: smnFrame.pack ();
1044: }
1045:
1046:
1047: if (smnPauseUpdate) {
1048: if (smnPauseRequest) {
1049: return;
1050: }
1051: smnPauseUpdate = false;
1052: int i = SMN_PAUSE_X / 4 + SMN_OFFSET * SMN_PAUSE_Y;
1053: int j = 0;
1054: for (int v = 0; v < SMN_PAUSE_HEIGHT; v++) {
1055: for (int u = 0; u < SMN_PAUSE_WIDTH; u += 4) {
1056: bb[i++] = SMN_PAUSE_ICON_3[j++];
1057: }
1058: i += SMN_OFFSET - SMN_PAUSE_WIDTH / 4;
1059: }
1060: } else if (smnPauseRequest) {
1061: smnPauseUpdate = true;
1062: int i = SMN_PAUSE_X / 4 + SMN_OFFSET * SMN_PAUSE_Y;
1063: int j = 0;
1064: for (int v = 0; v < SMN_PAUSE_HEIGHT; v++) {
1065: for (int u = 0; u < SMN_PAUSE_WIDTH; u += 4) {
1066: bb[i++] = SMN_PLAY_ICON_3[j++];
1067: }
1068: i += SMN_OFFSET - SMN_PAUSE_WIDTH / 4;
1069: }
1070: smnPanel.repaint ();
1071: return;
1072: }
1073:
1074:
1075: System.arraycopy (OPM.opmBuffer, 0, smnOPMBuffer, 0, SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES);
1076: System.arraycopy (ADPCM.pcmBuffer, 0, smnPCMBuffer, 0, SoundSource.SND_CHANNELS * OPM.OPM_BLOCK_SAMPLES);
1077: smnWavePaint ();
1078:
1079:
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087:
1088:
1089:
1090:
1091:
1092:
1093:
1094:
1095:
1096:
1097:
1098:
1099:
1100:
1101:
1102:
1103:
1104:
1105:
1106:
1107:
1108:
1109:
1110:
1111:
1112:
1113:
1114:
1115:
1116:
1117:
1118:
1119:
1120:
1121:
1122:
1123:
1124:
1125:
1126:
1127:
1128:
1129:
1130:
1131:
1132:
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151:
1152:
1153:
1154:
1155:
1156:
1157:
1158:
1159:
1160:
1161:
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:
1183:
1184:
1185:
1186:
1187:
1188:
1189:
1190:
1191:
1192:
1193:
1194:
1195:
1196:
1197:
1198:
1199:
1200:
1201:
1202:
1203:
1204:
1205:
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213:
1214:
1215:
1216:
1217:
1218:
1219:
1220:
1221:
1222:
1223:
1224:
1225:
1226:
1227: double[] buffer0 = smnSpectrumBuffer[0];
1228: double[] buffer2 = smnSpectrumBuffer[2];
1229: double[] buffer3 = smnSpectrumBuffer[3];
1230: double[] buffer4 = smnSpectrumBuffer[4];
1231: double[] buffer5 = smnSpectrumBuffer[5];
1232:
1233: System.arraycopy (buffer5, 500, buffer5, 0, SMN_SPECTRUM_N - 500);
1234: if (SoundSource.SND_CHANNELS == 1) {
1235: for (int i = SMN_SPECTRUM_N - 500, k = 0; i < SMN_SPECTRUM_N; i++, k += 5) {
1236: buffer5[i] = (double) (OPM.opmBuffer[k ] + ADPCM.pcmBuffer[k ] +
1237: OPM.opmBuffer[k + 1] + ADPCM.pcmBuffer[k + 1] +
1238: OPM.opmBuffer[k + 2] + ADPCM.pcmBuffer[k + 2] +
1239: OPM.opmBuffer[k + 3] + ADPCM.pcmBuffer[k + 3] +
1240: OPM.opmBuffer[k + 4] + ADPCM.pcmBuffer[k + 4]) * (0.2 / 32768.0);
1241: }
1242: } else {
1243: for (int i = SMN_SPECTRUM_N - 500, k = 0; i < SMN_SPECTRUM_N; i++, k += 10) {
1244: buffer5[i] = (double) (OPM.opmBuffer[k ] + OPM.opmBuffer[k + 1] + ADPCM.pcmBuffer[k ] + ADPCM.pcmBuffer[k + 1] +
1245: OPM.opmBuffer[k + 2] + OPM.opmBuffer[k + 3] + ADPCM.pcmBuffer[k + 2] + ADPCM.pcmBuffer[k + 3] +
1246: OPM.opmBuffer[k + 4] + OPM.opmBuffer[k + 5] + ADPCM.pcmBuffer[k + 4] + ADPCM.pcmBuffer[k + 5] +
1247: OPM.opmBuffer[k + 6] + OPM.opmBuffer[k + 7] + ADPCM.pcmBuffer[k + 6] + ADPCM.pcmBuffer[k + 7] +
1248: OPM.opmBuffer[k + 8] + OPM.opmBuffer[k + 9] + ADPCM.pcmBuffer[k + 8] + ADPCM.pcmBuffer[k + 9]) * (0.1 / 32768.0);
1249: }
1250: }
1251:
1252: System.arraycopy (buffer4, 250, buffer4, 0, SMN_SPECTRUM_N - 250);
1253: for (int i = SMN_SPECTRUM_N - 250, k = SMN_SPECTRUM_N - 500; i < SMN_SPECTRUM_N; i++, k += 2) {
1254: buffer4[i] = (buffer5[k] + buffer5[k + 1]) * 0.5;
1255: }
1256:
1257: System.arraycopy (buffer3, 100, buffer3, 0, SMN_SPECTRUM_N - 100);
1258: for (int i = SMN_SPECTRUM_N - 100, k = SMN_SPECTRUM_N - 500; i < SMN_SPECTRUM_N; i++, k += 5) {
1259: buffer3[i] = (buffer5[k] + buffer5[k + 1] + buffer5[k + 2] + buffer5[k + 3] + buffer5[k + 4]) * 0.2;
1260: }
1261:
1262: System.arraycopy (buffer2, 50, buffer2, 0, SMN_SPECTRUM_N - 50);
1263: for (int i = SMN_SPECTRUM_N - 50, k = SMN_SPECTRUM_N - 100; i < SMN_SPECTRUM_N; i++, k += 2) {
1264: buffer2[i] = (buffer3[k] + buffer3[k + 1]) * 0.5;
1265: }
1266:
1267: System.arraycopy (buffer0, 25, buffer0, 0, SMN_SPECTRUM_N - 25);
1268: for (int i = SMN_SPECTRUM_N - 25, k = SMN_SPECTRUM_N - 50; i < SMN_SPECTRUM_N; i++, k += 2) {
1269: buffer0[i] = (buffer2[k] + buffer2[k + 1]) * 0.5;
1270: }
1271: for (int partition = 0; partition < SMN_SPECTRUM_PARTITIONS; partition++) {
1272: if (partition != 1) {
1273:
1274: double[] buffer = smnSpectrumBuffer[partition];
1275: for (int i = 0; i < SMN_SPECTRUM_N; i++) {
1276: smnSpectrumX[i] = smnSpectrumWindow[i] * buffer[i];
1277: }
1278:
1279: Arrays.fill (smnSpectrumY, 0, SMN_SPECTRUM_N, 0.0);
1280:
1281:
1282: smnFFT.fftSandeTukey4 (smnSpectrumX, smnSpectrumY);
1283: }
1284:
1285:
1286: for (int x = partition == 0 ? 8 : SMN_SPECTRUM_RANGE * partition, x1 = x + SMN_SPECTRUM_RANGE, b = 6; x < x1; x++, b = b - 2 & 6) {
1287: int k = smnSpectrumIndex[x];
1288: int n = k >> 16;
1289: k = (char) k;
1290: double level = smnSpectrumX[k];
1291: while (--n > 0) {
1292: level = Math.max (level, smnSpectrumX[++k]);
1293: }
1294: int value = Math.max (0, Math.min (SMN_SPECTRUM_HEIGHT - 1, (int) ((double) SMN_SPECTRUM_HEIGHT / (double) SMN_SPECTRUM_N * SMN_SPECTRUM_SCALE * level)));
1295: int value0 = smnSpectrumValue[x];
1296: if (value > value0) {
1297: smnSpectrumValue[x] = value;
1298: int i = SMN_OFFSET * (SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT - 1 - value) + SMN_SPECTRUM_X / 4 + (x >> 2);
1299: while (value > value0) {
1300: bb[i] = (byte) (bb[i] & ~(3 << b) | (SMN_WHITE & 3) << b);
1301: i += SMN_OFFSET;
1302: value--;
1303: }
1304: } else if (value < value0) {
1305: if (value < value0 - SMN_SPECTRUM_TRAIL) {
1306: value = value0 - SMN_SPECTRUM_TRAIL;
1307: }
1308: smnSpectrumValue[x] = value;
1309: int i = SMN_OFFSET * (SMN_SPECTRUM_Y + SMN_SPECTRUM_HEIGHT - 1 - value0) + SMN_SPECTRUM_X / 4 + (x >> 2);
1310: while (value < value0) {
1311: bb[i] = (byte) (bb[i] & ~(3 << b));
1312: i += SMN_OFFSET;
1313: value++;
1314: }
1315: }
1316: }
1317: }
1318:
1319:
1320: for (int ch = 0; ch < 8; ch++) {
1321: YM2151.fm_channel channel = OPM.opmYM2151.m_channel[ch];
1322: YM2151.fm_operator opM1 = channel.m_op[0];
1323: YM2151.fm_operator opM2 = channel.m_op[1];
1324: YM2151.fm_operator opC1 = channel.m_op[2];
1325: YM2151.fm_operator opC2 = channel.m_op[3];
1326:
1327: int k0 = smnKey[ch];
1328:
1329: int m1 = opM1.m_env_state < YM2151.EG_RELEASE ? -1 : opM1.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
1330: int m2 = opM2.m_env_state < YM2151.EG_RELEASE ? -1 : opM2.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
1331: int c1 = opC1.m_env_state < YM2151.EG_RELEASE ? -1 : opC1.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
1332: int c2 = opC2.m_env_state < YM2151.EG_RELEASE ? -1 : opC2.m_env_attenuation < YM2151.EG_QUIET ? 0 : 1;
1333: int k1;
1334: if (m1 > 0 && m2 > 0 && c1 > 0 && c2 > 0) {
1335: k1 = -1;
1336: } else {
1337:
1338: int kc = OPM.opmRegister[0x28 + ch] & 127;
1339: int kf = (OPM.opmRegister[0x30 + ch] >> 2) & 63;
1340: k1 = (((kc - (kc >> 2)) << 6 | kf) + (3 << 6) + (64 - 38)) >> 6;
1341: if (m1 >= 0 && m2 >= 0 && c1 >= 0 && c2 >= 0) {
1342: k1 |= 0x10000;
1343: }
1344: }
1345: if (k0 != k1) {
1346: int i = SMN_KEY_X / 4 + SMN_OFFSET * (SMN_KEY_Y + 6 + 12 * ch);
1347: if (k0 >= 0 && (short) k0 != (short) k1) {
1348:
1349:
1350: int kk = (short) k0;
1351: int o = kk * 43 >>> 9;
1352: kk -= 12 * o;
1353: smnPaintKey (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_KEY_COLOR[kk]);
1354: }
1355: if (k1 >= 0 && k0 != k1) {
1356:
1357:
1358: int kk = (short) k1;
1359: int o = kk * 43 >>> 9;
1360: kk -= 12 * o;
1361: if (k1 >> 16 == 0) {
1362: smnPaintKey (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_ORANGE);
1363: } else {
1364: smnPaintKey2 (i + 14 * o + (kk < 5 ? kk : kk + 1), kk, SMN_KEY_COLOR[kk], SMN_ORANGE);
1365: }
1366: }
1367: smnKey[ch] = k1;
1368: }
1369:
1370: {
1371: XEiJ.fmtHex2 (SMN_TONE_V0, 0, OPM.opmRegister[0x20 + ch] & 63);
1372: XEiJ.fmtHex2 (SMN_TONE_V0, 3, OPM.opmRegister[256 + ch]);
1373: XEiJ.fmtHex2 (SMN_TONE_V0, 6, OPM.opmRegister[0x1b] & 3);
1374: XEiJ.fmtHex2 (SMN_TONE_V0, 9, 0);
1375: XEiJ.fmtHex2 (SMN_TONE_V0, 12, OPM.opmRegister[0x18] & 255);
1376: XEiJ.fmtHex2 (SMN_TONE_V0, 15, OPM.opmRegister[265]);
1377: XEiJ.fmtHex2 (SMN_TONE_V0, 18, OPM.opmRegister[264]);
1378: XEiJ.fmtHex2 (SMN_TONE_V0, 21, (OPM.opmRegister[0x38 + ch] >> 4) & 7);
1379: XEiJ.fmtHex2 (SMN_TONE_V0, 24, OPM.opmRegister[0x38 + ch] & 3);
1380: XEiJ.fmtHex2 (SMN_TONE_V0, 27, (OPM.opmRegister[0x20 + ch] >> 6) & 3);
1381: XEiJ.fmtHex2 (SMN_TONE_V1, 0, OPM.opmRegister[0x80 + ch] & 31);
1382: XEiJ.fmtHex2 (SMN_TONE_V2, 0, OPM.opmRegister[0x90 + ch] & 31);
1383: XEiJ.fmtHex2 (SMN_TONE_V3, 0, OPM.opmRegister[0x88 + ch] & 31);
1384: XEiJ.fmtHex2 (SMN_TONE_V4, 0, OPM.opmRegister[0x98 + ch] & 31);
1385: XEiJ.fmtHex2 (SMN_TONE_V1, 3, OPM.opmRegister[0xa0 + ch] & 31);
1386: XEiJ.fmtHex2 (SMN_TONE_V2, 3, OPM.opmRegister[0xb0 + ch] & 31);
1387: XEiJ.fmtHex2 (SMN_TONE_V3, 3, OPM.opmRegister[0xa8 + ch] & 31);
1388: XEiJ.fmtHex2 (SMN_TONE_V4, 3, OPM.opmRegister[0xb8 + ch] & 31);
1389: XEiJ.fmtHex2 (SMN_TONE_V1, 6, OPM.opmRegister[0xc0 + ch] & 31);
1390: XEiJ.fmtHex2 (SMN_TONE_V2, 6, OPM.opmRegister[0xd0 + ch] & 31);
1391: XEiJ.fmtHex2 (SMN_TONE_V3, 6, OPM.opmRegister[0xc8 + ch] & 31);
1392: XEiJ.fmtHex2 (SMN_TONE_V4, 6, OPM.opmRegister[0xd8 + ch] & 31);
1393: XEiJ.fmtHex2 (SMN_TONE_V1, 9, OPM.opmRegister[0xe0 + ch] & 15);
1394: XEiJ.fmtHex2 (SMN_TONE_V2, 9, OPM.opmRegister[0xf0 + ch] & 15);
1395: XEiJ.fmtHex2 (SMN_TONE_V3, 9, OPM.opmRegister[0xe8 + ch] & 15);
1396: XEiJ.fmtHex2 (SMN_TONE_V4, 9, OPM.opmRegister[0xf8 + ch] & 15);
1397: XEiJ.fmtHex2 (SMN_TONE_V1, 12, (OPM.opmRegister[0xe0 + ch] >> 4) & 15);
1398: XEiJ.fmtHex2 (SMN_TONE_V2, 12, (OPM.opmRegister[0xf0 + ch] >> 4) & 15);
1399: XEiJ.fmtHex2 (SMN_TONE_V3, 12, (OPM.opmRegister[0xe8 + ch] >> 4) & 15);
1400: XEiJ.fmtHex2 (SMN_TONE_V4, 12, (OPM.opmRegister[0xf8 + ch] >> 4) & 15);
1401: XEiJ.fmtHex2 (SMN_TONE_V1, 15, OPM.opmRegister[0x60 + ch] & 127);
1402: XEiJ.fmtHex2 (SMN_TONE_V2, 15, OPM.opmRegister[0x70 + ch] & 127);
1403: XEiJ.fmtHex2 (SMN_TONE_V3, 15, OPM.opmRegister[0x68 + ch] & 127);
1404: XEiJ.fmtHex2 (SMN_TONE_V4, 15, OPM.opmRegister[0x78 + ch] & 127);
1405: XEiJ.fmtHex2 (SMN_TONE_V1, 18, (OPM.opmRegister[0x80 + ch] >> 6) & 3);
1406: XEiJ.fmtHex2 (SMN_TONE_V2, 18, (OPM.opmRegister[0x90 + ch] >> 6) & 3);
1407: XEiJ.fmtHex2 (SMN_TONE_V3, 18, (OPM.opmRegister[0x88 + ch] >> 6) & 3);
1408: XEiJ.fmtHex2 (SMN_TONE_V4, 18, (OPM.opmRegister[0x98 + ch] >> 6) & 3);
1409: XEiJ.fmtHex2 (SMN_TONE_V1, 21, OPM.opmRegister[0x40 + ch] & 15);
1410: XEiJ.fmtHex2 (SMN_TONE_V2, 21, OPM.opmRegister[0x50 + ch] & 15);
1411: XEiJ.fmtHex2 (SMN_TONE_V3, 21, OPM.opmRegister[0x48 + ch] & 15);
1412: XEiJ.fmtHex2 (SMN_TONE_V4, 21, OPM.opmRegister[0x58 + ch] & 15);
1413: XEiJ.fmtHex2 (SMN_TONE_V1, 24, (OPM.opmRegister[0x40 + ch] >> 4) & 7);
1414: XEiJ.fmtHex2 (SMN_TONE_V2, 24, (OPM.opmRegister[0x50 + ch] >> 4) & 7);
1415: XEiJ.fmtHex2 (SMN_TONE_V3, 24, (OPM.opmRegister[0x48 + ch] >> 4) & 7);
1416: XEiJ.fmtHex2 (SMN_TONE_V4, 24, (OPM.opmRegister[0x58 + ch] >> 4) & 7);
1417: XEiJ.fmtHex2 (SMN_TONE_V1, 27, (OPM.opmRegister[0xc0 + ch] >> 6) & 3);
1418: XEiJ.fmtHex2 (SMN_TONE_V2, 27, (OPM.opmRegister[0xd0 + ch] >> 6) & 3);
1419: XEiJ.fmtHex2 (SMN_TONE_V3, 27, (OPM.opmRegister[0xc8 + ch] >> 6) & 3);
1420: XEiJ.fmtHex2 (SMN_TONE_V4, 27, (OPM.opmRegister[0xd8 + ch] >> 6) & 3);
1421: XEiJ.fmtHex2 (SMN_TONE_V1, 30, (OPM.opmRegister[0xa0 + ch] >> 7) & 1);
1422: XEiJ.fmtHex2 (SMN_TONE_V2, 30, (OPM.opmRegister[0xb0 + ch] >> 7) & 1);
1423: XEiJ.fmtHex2 (SMN_TONE_V3, 30, (OPM.opmRegister[0xa8 + ch] >> 7) & 1);
1424: XEiJ.fmtHex2 (SMN_TONE_V4, 30, (OPM.opmRegister[0xb8 + ch] >> 7) & 1);
1425: int x = SMN_TONE_X / 4 + SMN_TONE_BOX_COLS * (0b01_00_10_01_00_10_01_00 >> (ch << 1) & 3);
1426: int y = SMN_TONE_Y + SMN_TONE_BOX_HEIGHT * (0b10_10_01_01_01_00_00_00 >> (ch << 1) & 3);
1427: smnDrawString3 (3 + x, 6 + y, SMN_TONE_V0);
1428: smnDrawString3 (3 + x, 6 * 3 + y, SMN_TONE_V1);
1429: smnDrawString3 (3 + x, 6 * 4 + y, SMN_TONE_V2);
1430: smnDrawString3 (3 + x, 6 * 5 + y, SMN_TONE_V3);
1431: smnDrawString3 (3 + x, 6 * 6 + y, SMN_TONE_V4);
1432: }
1433: }
1434:
1435:
1436: smnDrawString3 (SMN_PCM_COL + 3, SMN_PCM_Y , SMN_PCM_OSCILLATOR[ADPCM.pcmOSCFreqMode << 1 | ADPCM.pcmOscillator]);
1437: smnDrawString3 (SMN_PCM_COL + 11, SMN_PCM_Y , SMN_PCM_DIVIDER[ADPCM.pcmDivider]);
1438: smnDrawString3 (SMN_PCM_COL + 16, SMN_PCM_Y , SMN_PCM_FREQ[ADPCM.pcmOSCFreqMode << 3 | ADPCM.pcmOscillator << 2 | ADPCM.pcmDivider]);
1439: smnDrawString2 (SMN_PCM_COL + 3, SMN_PCM_Y + 6, SMN_PCM_PLAY[ADPCM.pcmActive ? 1 : 0]);
1440: smnDrawString2 (SMN_PCM_COL + 8, SMN_PCM_Y + 6, SMN_PCM_DATA[ADPCM.pcmEncodedData >= 0 ? 1 : 0]);
1441: smnDrawString2 (SMN_PCM_COL + 13, SMN_PCM_Y + 6, SMN_PCM_LEFT[ADPCM.pcmPanLeft == 0 || ADPCM.pcmPanLeft < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1]);
1442: smnDrawString2 (SMN_PCM_COL + 18, SMN_PCM_Y + 6, SMN_PCM_RIGHT[SoundSource.SND_CHANNELS == 1 ?
1443: ADPCM.pcmPanLeft == 0 || ADPCM.pcmPanLeft < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1 :
1444: ADPCM.pcmPanRight == 0 || ADPCM.pcmPanRight < 0x80000000 + ADPCM.PCM_ATTACK_SPAN * 2 ? 0 : 1]);
1445:
1446: smnPanel.repaint ();
1447:
1448: }
1449:
1450:
1451:
1452: public static void smnWavePaint () {
1453: byte[] bb = smnBitmap;
1454:
1455: Arrays.fill (bb, SMN_OFFSET * SMN_WAVE_Y, SMN_OFFSET * (SMN_WAVE_Y + SMN_WAVE_HEIGHT), SMN_BLACK);
1456:
1457: smnDrawIcon3 (SMN_WAVE_X / 4 - 2, SMN_WAVE_Y, 8);
1458:
1459: if (-SMN_WAVE_HEIGHT / 2 <= smnWaveElevation && smnWaveElevation <= SMN_WAVE_HEIGHT / 2) {
1460: int i = SMN_OFFSET * (SMN_WAVE_Y + SMN_WAVE_HEIGHT / 2 - smnWaveElevation) + SMN_WAVE_X / 4;
1461: Arrays.fill (bb, i, i + SMN_WAVE_WIDTH / 4, SMN_BLUE);
1462: }
1463:
1464: int ms0 = (1000 / SoundSource.SND_BLOCK_FREQ * smnWaveOffset + (SMN_WAVE_WIDTH << smnWaveScaleX) - 1) / (SMN_WAVE_WIDTH << smnWaveScaleX);
1465: int ms1 = 1000 / SoundSource.SND_BLOCK_FREQ * (smnWaveOffset + SMN_WAVE_WIDTH) / (SMN_WAVE_WIDTH << smnWaveScaleX);
1466: for (int ms = ms0; ms <= ms1; ms++) {
1467:
1468:
1469:
1470: int x = Math.max (0, Math.min (SMN_WAVE_WIDTH - 1, (SoundSource.SND_BLOCK_FREQ * SMN_WAVE_WIDTH * ms * 8389 >>> 23 << smnWaveScaleX) - smnWaveOffset));
1471: int b = (~x & 3) << 1;
1472: if (ms1 - ms0 <= 10 ||
1473: ms1 - ms0 <= 20 && (1L << 63 - 0 |
1474: 1L << 63 - 5 |
1475: 1L << 63 - 10 |
1476: 1L << 63 - 15 |
1477: 1L << 63 - 20 |
1478: 1L << 63 - 25 |
1479: 1L << 63 - 30 |
1480: 1L << 63 - 35 |
1481: 1L << 63 - 40 |
1482: 1L << 63 - 45 |
1483: 1L << 63 - 50 |
1484: 1L << 63 - 55 |
1485: 1L << 63 - 60) << ms < 0 ||
1486: (1L << 63 - 0 |
1487: 1L << 63 - 10 |
1488: 1L << 63 - 20 |
1489: 1L << 63 - 30 |
1490: 1L << 63 - 40 |
1491: 1L << 63 - 50 |
1492: 1L << 63 - 60) << ms < 0) {
1493: int t = XEiJ.FMT_BCD4[ms];
1494: int col = SMN_WAVE_X / 4 + Math.max (0, Math.min (SMN_WAVE_WIDTH / 4 - (t >= 0x10 ? 4 : 3), (x + 3 >> 2) - (t >= 0x10 ? 2 : 1)));
1495: if (t >= 0x10) {
1496: smnDrawChar1 (col++, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, '0' | t >> 4);
1497: }
1498: smnDrawChar1 (col , SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, '0' | t & 15);
1499: smnDrawChar1 (col + 1, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, 'm');
1500: smnDrawChar1 (col + 2, SMN_WAVE_Y + SMN_WAVE_HEIGHT - 6, 's');
1501: }
1502: int v0, v1;
1503: if ((1L << 63 - 0 |
1504: 1L << 63 - 10 |
1505: 1L << 63 - 20 |
1506: 1L << 63 - 30 |
1507: 1L << 63 - 40 |
1508: 1L << 63 - 50 |
1509: 1L << 63 - 60) << ms < 0) {
1510: v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 4 / 16;
1511: v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 4 / 16;
1512: } else if ((1L << 63 - 0 |
1513: 1L << 63 - 5 |
1514: 1L << 63 - 10 |
1515: 1L << 63 - 15 |
1516: 1L << 63 - 20 |
1517: 1L << 63 - 25 |
1518: 1L << 63 - 30 |
1519: 1L << 63 - 35 |
1520: 1L << 63 - 40 |
1521: 1L << 63 - 45 |
1522: 1L << 63 - 50 |
1523: 1L << 63 - 55 |
1524: 1L << 63 - 60) << ms < 0) {
1525: v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 3 / 16;
1526: v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 3 / 16;
1527: } else {
1528: v0 = SMN_WAVE_HEIGHT / 2 - SMN_WAVE_HEIGHT * 2 / 16;
1529: v1 = SMN_WAVE_HEIGHT / 2 + SMN_WAVE_HEIGHT * 2 / 16;
1530: }
1531: v0 -= smnWaveElevation;
1532: v1 -= smnWaveElevation;
1533: if (v0 < 0) {
1534: v0 = 0;
1535: }
1536: if (v1 > SMN_WAVE_HEIGHT - 1) {
1537: v1 = SMN_WAVE_HEIGHT - 1;
1538: }
1539: int i = SMN_OFFSET * (SMN_WAVE_Y + v0) + SMN_WAVE_X / 4 + (x >> 2);
1540: for (int v = v0; v <= v1; v++) {
1541: bb[i] = (byte) (bb[i] & ~(3 << b) | (SMN_BLUE & 3) << b);
1542: i += SMN_OFFSET;
1543: }
1544: }
1545: if (SoundSource.SND_CHANNELS == 1) {
1546: smnWavePaint1 (smnPCMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMLeft);
1547: smnWavePaint1 (smnOPMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMLeft);
1548: } else {
1549: smnWavePaint1 (smnPCMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMLeft);
1550: smnWavePaint1 (smnPCMBuffer, smnWaveIndex1[smnWaveScaleX], SMN_ORANGE & 3, smnWaveLastYPCMRight);
1551: smnWavePaint1 (smnOPMBuffer, smnWaveIndex0[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMLeft);
1552: smnWavePaint1 (smnOPMBuffer, smnWaveIndex1[smnWaveScaleX], SMN_WHITE & 3, smnWaveLastYOPMRight);
1553: }
1554: }
1555:
1556:
1557: public static void smnWavePaint1 (int[] buffer, int[] index, int palet, int[] lastY) {
1558: byte[] bb = smnBitmap;
1559: int o = smnWaveOffset;
1560: int t;
1561: int y0 = lastY[0];
1562: int y1 = lastY[1];
1563: int scaleY = SMN_WAVE_VALUE_SHIFT - smnWaveScaleY;
1564: for (int x = 0, b = 6; x < SMN_WAVE_WIDTH; x++, b = b - 2 & 6) {
1565: int y2 = SMN_WAVE_HEIGHT / 2 - ((t = buffer[index[o + x]]) + (t >>> -scaleY) >> scaleY);
1566: int min, max;
1567: if (y0 < y1) {
1568: if (y1 < y2) {
1569: min = y0 + y1 >> 1;
1570: max = y1 + y2 >> 1;
1571: } else if (y0 < y2) {
1572: min = y0 + y1 >> 1;
1573: max = y1;
1574: } else {
1575: min = y1 + y2 >> 1;
1576: max = y1;
1577: }
1578: } else {
1579: if (y0 < y2) {
1580: min = y1;
1581: max = y1 + y2 >> 1;
1582: } else if (y1 < y2) {
1583: min = y1;
1584: max = y0 + y1 >> 1;
1585: } else {
1586: min = y1 + y2 >> 1;
1587: max = y0 + y1 >> 1;
1588: }
1589: }
1590: min -= smnWaveElevation;
1591: max -= smnWaveElevation;
1592:
1593: if (min < 0) {
1594: min = 0;
1595: }
1596: if (max > SMN_WAVE_HEIGHT - 1) {
1597: max = SMN_WAVE_HEIGHT - 1;
1598: }
1599: for (int y = min; y <= max; y++) {
1600: int i = SMN_OFFSET * (SMN_WAVE_Y + y) + SMN_WAVE_X / 4 + (x >> 2);
1601: bb[i] = (byte) (bb[i] & ~(3 << b) | palet << b);
1602: }
1603: y0 = y1;
1604: y1 = y2;
1605: }
1606: lastY[0] = y0;
1607: lastY[1] = y1;
1608: }
1609:
1610:
1611:
1612:
1613:
1614:
1615:
1616:
1617:
1618:
1619:
1620:
1621:
1622:
1623:
1624:
1625:
1626:
1627:
1628:
1629:
1630:
1631:
1632: public static void smnPaintKey (int i, int k, int c1111) {
1633: int c1110 = c1111 & 0b11111100;
1634: byte[] bb = smnBitmap;
1635: switch (k) {
1636: case 0:
1637: case 5:
1638: bb[ SMN_OFFSET * 6 + i] = (
1639: bb[ SMN_OFFSET * 7 + i] =
1640: bb[ SMN_OFFSET * 8 + i] =
1641: bb[ SMN_OFFSET * 9 + i] =
1642: bb[ SMN_OFFSET * 10 + i] = (byte) c1111);
1643: bb[ + i] = (
1644: bb[ SMN_OFFSET + i] =
1645: bb[ SMN_OFFSET * 2 + i] =
1646: bb[ SMN_OFFSET * 3 + i] =
1647: bb[ SMN_OFFSET * 4 + i] =
1648: bb[ SMN_OFFSET * 5 + i] =
1649: bb[ 1 + SMN_OFFSET * 6 + i] =
1650: bb[ 1 + SMN_OFFSET * 7 + i] =
1651: bb[ 1 + SMN_OFFSET * 8 + i] =
1652: bb[ 1 + SMN_OFFSET * 9 + i] =
1653: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
1654: break;
1655: case 1:
1656: case 3:
1657: case 6:
1658: case 8:
1659: case 10:
1660: bb[ i] = (
1661: bb[ SMN_OFFSET + i] =
1662: bb[ SMN_OFFSET * 2 + i] =
1663: bb[ SMN_OFFSET * 3 + i] =
1664: bb[ SMN_OFFSET * 4 + i] = (byte) c1111);
1665: bb[ 1 + + i] = (
1666: bb[ 1 + SMN_OFFSET + i] =
1667: bb[ 1 + SMN_OFFSET * 2 + i] =
1668: bb[ 1 + SMN_OFFSET * 3 + i] =
1669: bb[ 1 + SMN_OFFSET * 4 + i] = (byte) c1110);
1670: break;
1671: case 2:
1672: case 7:
1673: case 9:
1674: bb[ SMN_OFFSET * 6 + i] = (
1675: bb[ SMN_OFFSET * 7 + i] =
1676: bb[ SMN_OFFSET * 8 + i] =
1677: bb[ SMN_OFFSET * 9 + i] =
1678: bb[ SMN_OFFSET * 10 + i] = (byte) c1111);
1679: bb[ 1 + SMN_OFFSET * 6 + i] = (
1680: bb[ 1 + SMN_OFFSET * 7 + i] =
1681: bb[ 1 + SMN_OFFSET * 8 + i] =
1682: bb[ 1 + SMN_OFFSET * 9 + i] =
1683: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
1684: break;
1685: case 4:
1686: case 11:
1687: bb[ SMN_OFFSET * 6 + i] = (
1688: bb[ SMN_OFFSET * 7 + i] =
1689: bb[ SMN_OFFSET * 8 + i] =
1690: bb[ SMN_OFFSET * 9 + i] =
1691: bb[ SMN_OFFSET * 10 + i] = (byte) c1111);
1692: bb[ 1 + + i] = (
1693: bb[ 1 + SMN_OFFSET + i] =
1694: bb[ 1 + SMN_OFFSET * 2 + i] =
1695: bb[ 1 + SMN_OFFSET * 3 + i] =
1696: bb[ 1 + SMN_OFFSET * 4 + i] =
1697: bb[ 1 + SMN_OFFSET * 5 + i] =
1698: bb[ 1 + SMN_OFFSET * 6 + i] =
1699: bb[ 1 + SMN_OFFSET * 7 + i] =
1700: bb[ 1 + SMN_OFFSET * 8 + i] =
1701: bb[ 1 + SMN_OFFSET * 9 + i] =
1702: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110);
1703: break;
1704: }
1705: }
1706:
1707:
1708:
1709:
1710:
1711:
1712:
1713:
1714:
1715:
1716:
1717:
1718:
1719:
1720:
1721:
1722:
1723:
1724:
1725:
1726:
1727:
1728:
1729:
1730: public static void smnPaintKey2 (int i, int k, int c1111a, int c1111b) {
1731: int c1111ab = c1111a & 0b11001100 | c1111b & 0b00110011;
1732: int c1111ba = c1111b & 0b11001100 | c1111a & 0b00110011;
1733: int c1110ab = c1111ab & 0b11111100;
1734: int c1110ba = c1111ba & 0b11111100;
1735: byte[] bb = smnBitmap;
1736: switch (k) {
1737: case 0:
1738: case 5:
1739: bb[ SMN_OFFSET * 6 + i] = (
1740: bb[ SMN_OFFSET * 8 + i] =
1741: bb[ SMN_OFFSET * 10 + i] = (byte) c1111ab);
1742: bb[ SMN_OFFSET * 7 + i] = (
1743: bb[ SMN_OFFSET * 9 + i] = (byte) c1111ba);
1744: bb[ + i] = (
1745: bb[ SMN_OFFSET * 2 + i] =
1746: bb[ SMN_OFFSET * 4 + i] =
1747: bb[ 1 + SMN_OFFSET * 6 + i] =
1748: bb[ 1 + SMN_OFFSET * 8 + i] =
1749: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
1750: bb[ SMN_OFFSET + i] = (
1751: bb[ SMN_OFFSET * 3 + i] =
1752: bb[ SMN_OFFSET * 5 + i] =
1753: bb[ 1 + SMN_OFFSET * 7 + i] =
1754: bb[ 1 + SMN_OFFSET * 9 + i] = (byte) c1110ba);
1755: break;
1756: case 1:
1757: case 3:
1758: case 6:
1759: case 8:
1760: case 10:
1761: bb[ i] = (
1762: bb[ SMN_OFFSET * 2 + i] =
1763: bb[ SMN_OFFSET * 4 + i] = (byte) c1111ab);
1764: bb[ SMN_OFFSET + i] = (
1765: bb[ SMN_OFFSET * 3 + i] = (byte) c1111ba);
1766: bb[ 1 + + i] = (
1767: bb[ 1 + SMN_OFFSET * 2 + i] =
1768: bb[ 1 + SMN_OFFSET * 4 + i] = (byte) c1110ab);
1769: bb[ 1 + SMN_OFFSET + i] = (
1770: bb[ 1 + SMN_OFFSET * 3 + i] = (byte) c1110ba);
1771: break;
1772: case 2:
1773: case 7:
1774: case 9:
1775: bb[ SMN_OFFSET * 6 + i] = (
1776: bb[ SMN_OFFSET * 8 + i] =
1777: bb[ SMN_OFFSET * 10 + i] = (byte) c1111ab);
1778: bb[ SMN_OFFSET * 7 + i] = (
1779: bb[ SMN_OFFSET * 9 + i] = (byte) c1111ba);
1780: bb[ 1 + SMN_OFFSET * 6 + i] = (
1781: bb[ 1 + SMN_OFFSET * 8 + i] =
1782: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
1783: bb[ 1 + SMN_OFFSET * 7 + i] = (
1784: bb[ 1 + SMN_OFFSET * 9 + i] = (byte) c1110ba);
1785: break;
1786: case 4:
1787: case 11:
1788: bb[ SMN_OFFSET * 6 + i] = (
1789: bb[ SMN_OFFSET * 8 + i] =
1790: bb[ SMN_OFFSET * 10 + i] = (byte) c1111ab);
1791: bb[ SMN_OFFSET * 7 + i] = (
1792: bb[ SMN_OFFSET * 9 + i] = (byte) c1111ba);
1793: bb[ 1 + + i] = (
1794: bb[ 1 + SMN_OFFSET * 2 + i] =
1795: bb[ 1 + SMN_OFFSET * 4 + i] =
1796: bb[ 1 + SMN_OFFSET * 6 + i] =
1797: bb[ 1 + SMN_OFFSET * 8 + i] =
1798: bb[ 1 + SMN_OFFSET * 10 + i] = (byte) c1110ab);
1799: bb[ 1 + SMN_OFFSET + i] = (
1800: bb[ 1 + SMN_OFFSET * 3 + i] =
1801: bb[ 1 + SMN_OFFSET * 5 + i] =
1802: bb[ 1 + SMN_OFFSET * 7 + i] =
1803: bb[ 1 + SMN_OFFSET * 9 + i] = (byte) c1110ba);
1804: break;
1805: }
1806: }
1807:
1808:
1809:
1810: public static void smnDrawIcon1 (int x, int y, int c) {
1811: byte[] bb = smnBitmap;
1812: x += SMN_OFFSET * y;
1813: c *= 18;
1814: bb[ + x] = SMN_ICON_1[c ];
1815: bb[1 + x] = SMN_ICON_1[c + 1];
1816: bb[ SMN_OFFSET + x] = SMN_ICON_1[c + 2];
1817: bb[1 + SMN_OFFSET + x] = SMN_ICON_1[c + 3];
1818: bb[ SMN_OFFSET * 2 + x] = SMN_ICON_1[c + 4];
1819: bb[1 + SMN_OFFSET * 2 + x] = SMN_ICON_1[c + 5];
1820: bb[ SMN_OFFSET * 3 + x] = SMN_ICON_1[c + 6];
1821: bb[1 + SMN_OFFSET * 3 + x] = SMN_ICON_1[c + 7];
1822: bb[ SMN_OFFSET * 4 + x] = SMN_ICON_1[c + 8];
1823: bb[1 + SMN_OFFSET * 4 + x] = SMN_ICON_1[c + 9];
1824: bb[ SMN_OFFSET * 5 + x] = SMN_ICON_1[c + 10];
1825: bb[1 + SMN_OFFSET * 5 + x] = SMN_ICON_1[c + 11];
1826: bb[ SMN_OFFSET * 6 + x] = SMN_ICON_1[c + 12];
1827: bb[1 + SMN_OFFSET * 6 + x] = SMN_ICON_1[c + 13];
1828: bb[ SMN_OFFSET * 7 + x] = SMN_ICON_1[c + 14];
1829: bb[1 + SMN_OFFSET * 7 + x] = SMN_ICON_1[c + 15];
1830: bb[ SMN_OFFSET * 8 + x] = SMN_ICON_1[c + 16];
1831: bb[1 + SMN_OFFSET * 8 + x] = SMN_ICON_1[c + 17];
1832: }
1833:
1834:
1835:
1836: public static void smnDrawIcon3 (int x, int y, int c) {
1837: byte[] bb = smnBitmap;
1838: x += SMN_OFFSET * y;
1839: c *= 18;
1840: bb[ + x] = SMN_ICON_3[c ];
1841: bb[1 + x] = SMN_ICON_3[c + 1];
1842: bb[ SMN_OFFSET + x] = SMN_ICON_3[c + 2];
1843: bb[1 + SMN_OFFSET + x] = SMN_ICON_3[c + 3];
1844: bb[ SMN_OFFSET * 2 + x] = SMN_ICON_3[c + 4];
1845: bb[1 + SMN_OFFSET * 2 + x] = SMN_ICON_3[c + 5];
1846: bb[ SMN_OFFSET * 3 + x] = SMN_ICON_3[c + 6];
1847: bb[1 + SMN_OFFSET * 3 + x] = SMN_ICON_3[c + 7];
1848: bb[ SMN_OFFSET * 4 + x] = SMN_ICON_3[c + 8];
1849: bb[1 + SMN_OFFSET * 4 + x] = SMN_ICON_3[c + 9];
1850: bb[ SMN_OFFSET * 5 + x] = SMN_ICON_3[c + 10];
1851: bb[1 + SMN_OFFSET * 5 + x] = SMN_ICON_3[c + 11];
1852: bb[ SMN_OFFSET * 6 + x] = SMN_ICON_3[c + 12];
1853: bb[1 + SMN_OFFSET * 6 + x] = SMN_ICON_3[c + 13];
1854: bb[ SMN_OFFSET * 7 + x] = SMN_ICON_3[c + 14];
1855: bb[1 + SMN_OFFSET * 7 + x] = SMN_ICON_3[c + 15];
1856: bb[ SMN_OFFSET * 8 + x] = SMN_ICON_3[c + 16];
1857: bb[1 + SMN_OFFSET * 8 + x] = SMN_ICON_3[c + 17];
1858: }
1859:
1860:
1861:
1862: public static void smnDrawChar1 (int x, int y, int c) {
1863: byte[] bb = smnBitmap;
1864: x += SMN_OFFSET * y;
1865: c *= 5;
1866: bb[x ] = SMN_FONT_1[c ];
1867: bb[x + SMN_OFFSET ] = SMN_FONT_1[c + 1];
1868: bb[x + SMN_OFFSET * 2] = SMN_FONT_1[c + 2];
1869: bb[x + SMN_OFFSET * 3] = SMN_FONT_1[c + 3];
1870: bb[x + SMN_OFFSET * 4] = SMN_FONT_1[c + 4];
1871: }
1872:
1873:
1874:
1875: public static void smnDrawChar2 (int x, int y, int c) {
1876: byte[] bb = smnBitmap;
1877: x += SMN_OFFSET * y;
1878: c *= 5;
1879: bb[x ] = SMN_FONT_2[c ];
1880: bb[x + SMN_OFFSET ] = SMN_FONT_2[c + 1];
1881: bb[x + SMN_OFFSET * 2] = SMN_FONT_2[c + 2];
1882: bb[x + SMN_OFFSET * 3] = SMN_FONT_2[c + 3];
1883: bb[x + SMN_OFFSET * 4] = SMN_FONT_2[c + 4];
1884: }
1885:
1886:
1887:
1888: public static void smnDrawChar3 (int x, int y, int c) {
1889: byte[] bb = smnBitmap;
1890: x += SMN_OFFSET * y;
1891: c *= 5;
1892: bb[x ] = SMN_FONT_3[c ];
1893: bb[x + SMN_OFFSET ] = SMN_FONT_3[c + 1];
1894: bb[x + SMN_OFFSET * 2] = SMN_FONT_3[c + 2];
1895: bb[x + SMN_OFFSET * 3] = SMN_FONT_3[c + 3];
1896: bb[x + SMN_OFFSET * 4] = SMN_FONT_3[c + 4];
1897: }
1898:
1899:
1900:
1901: public static void smnDrawString1 (int x, int y, String s) {
1902: smnDrawString1 (x, y, s.toCharArray ());
1903: }
1904: public static void smnDrawString1 (int x, int y, char[] s) {
1905: byte[] bb = smnBitmap;
1906: x += SMN_OFFSET * y;
1907: for (char c : s) {
1908: c *= 5;
1909: bb[x ] = SMN_FONT_1[c ];
1910: bb[x + SMN_OFFSET ] = SMN_FONT_1[c + 1];
1911: bb[x + SMN_OFFSET * 2] = SMN_FONT_1[c + 2];
1912: bb[x + SMN_OFFSET * 3] = SMN_FONT_1[c + 3];
1913: bb[x + SMN_OFFSET * 4] = SMN_FONT_1[c + 4];
1914: x++;
1915: }
1916: }
1917:
1918:
1919:
1920: public static void smnDrawString2 (int x, int y, String s) {
1921: smnDrawString2 (x, y, s.toCharArray ());
1922: }
1923: public static void smnDrawString2 (int x, int y, char[] s) {
1924: byte[] bb = smnBitmap;
1925: x += SMN_OFFSET * y;
1926: for (char c : s) {
1927: c *= 5;
1928: bb[x ] = SMN_FONT_2[c ];
1929: bb[x + SMN_OFFSET ] = SMN_FONT_2[c + 1];
1930: bb[x + SMN_OFFSET * 2] = SMN_FONT_2[c + 2];
1931: bb[x + SMN_OFFSET * 3] = SMN_FONT_2[c + 3];
1932: bb[x + SMN_OFFSET * 4] = SMN_FONT_2[c + 4];
1933: x++;
1934: }
1935: }
1936:
1937:
1938:
1939: public static void smnDrawString3 (int x, int y, String s) {
1940: smnDrawString3 (x, y, s.toCharArray ());
1941: }
1942: public static void smnDrawString3 (int x, int y, char[] s) {
1943: byte[] bb = smnBitmap;
1944: x += SMN_OFFSET * y;
1945: for (char c : s) {
1946: c *= 5;
1947: bb[x ] = SMN_FONT_3[c ];
1948: bb[x + SMN_OFFSET ] = SMN_FONT_3[c + 1];
1949: bb[x + SMN_OFFSET * 2] = SMN_FONT_3[c + 2];
1950: bb[x + SMN_OFFSET * 3] = SMN_FONT_3[c + 3];
1951: bb[x + SMN_OFFSET * 4] = SMN_FONT_3[c + 4];
1952: x++;
1953: }
1954: }
1955:
1956:
1957:
1958:
1959:
1960:
1961:
1962:
1963:
1964:
1965: public static void smnDrawSlider (int[] slider, int[] pattern) {
1966: byte[] bb = smnBitmap;
1967: int x0 = slider[0];
1968: int y0 = slider[1];
1969: int max = slider[2];
1970: int palet = slider[3];
1971: int value = slider[4];
1972: int width = max + 4;
1973: for (int i = (x0 >> 2) + SMN_OFFSET * y0, l = i + (width >> 2); i < l; i++) {
1974: bb[ i ] = (
1975: bb[i + SMN_OFFSET * 1] =
1976: bb[i + SMN_OFFSET * 3] =
1977: bb[i + SMN_OFFSET * 4] = SMN_BLACK);
1978: bb[ i + SMN_OFFSET * 2] = (byte) palet;
1979: }
1980: smnDrawPattern (x0 + value, y0 + 2, pattern);
1981: }
1982:
1983:
1984:
1985:
1986:
1987: public static void smnDrawPattern (int x0, int y0, int[] pattern) {
1988: byte[] bb = smnBitmap;
1989: for (int k = 0; k < pattern.length; ) {
1990: int limit = k + pattern[k];
1991: int palet = pattern[k + 1] & 3;
1992: for (k += 2; k < limit; k += 2) {
1993: int x = x0 + pattern[k];
1994: int y = y0 + pattern[k + 1];
1995: int b = (~x & 3) << 1;
1996: int i = SMN_OFFSET * y + (x >> 2);
1997: bb[i] = (byte) (bb[i] & ~(3 << b) | palet << b);
1998: }
1999: }
2000: }
2001:
2002: }
2003:
2004:
2005: