aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/jsyn
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/jsyn')
-rw-r--r--src/com/jsyn/devices/AudioDeviceFactory.java1
-rw-r--r--src/com/jsyn/scope/TriggerModel.java1
-rw-r--r--src/com/jsyn/scope/swing/ScopeTriggerPanel.java5
-rw-r--r--src/com/jsyn/swing/DoubleBoundedRangeSlider.java2
-rw-r--r--src/com/jsyn/swing/DoubleBoundedTextField.java4
-rw-r--r--src/com/jsyn/swing/EnvelopeEditorBox.java10
-rw-r--r--src/com/jsyn/swing/XYController.java8
-rw-r--r--src/com/jsyn/util/NumericOutput.java187
-rw-r--r--src/com/jsyn/util/soundfile/AIFFFileParser.java1
9 files changed, 204 insertions, 15 deletions
diff --git a/src/com/jsyn/devices/AudioDeviceFactory.java b/src/com/jsyn/devices/AudioDeviceFactory.java
index 58b9772..612c81d 100644
--- a/src/com/jsyn/devices/AudioDeviceFactory.java
+++ b/src/com/jsyn/devices/AudioDeviceFactory.java
@@ -64,6 +64,7 @@ public class AudioDeviceFactory {
private static void tryJavaSound() {
if (instance == null) {
try {
+ @SuppressWarnings("unchecked")
Class<AudioDeviceManager> clazz = JavaTools.loadClass(
"com.jsyn.devices.javasound.JavaSoundAudioDevice", false);
if (clazz != null) {
diff --git a/src/com/jsyn/scope/TriggerModel.java b/src/com/jsyn/scope/TriggerModel.java
index 0ded1fa..7081b2c 100644
--- a/src/com/jsyn/scope/TriggerModel.java
+++ b/src/com/jsyn/scope/TriggerModel.java
@@ -16,6 +16,7 @@
package com.jsyn.scope;
+import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import com.jsyn.scope.AudioScope.TriggerMode;
diff --git a/src/com/jsyn/scope/swing/ScopeTriggerPanel.java b/src/com/jsyn/scope/swing/ScopeTriggerPanel.java
index e466c05..a5f1541 100644
--- a/src/com/jsyn/scope/swing/ScopeTriggerPanel.java
+++ b/src/com/jsyn/scope/swing/ScopeTriggerPanel.java
@@ -18,16 +18,19 @@ package com.jsyn.scope.swing;
import java.awt.BorderLayout;
+import javax.swing.ComboBoxModel;
+import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import com.jsyn.scope.AudioScopeModel;
import com.jsyn.scope.TriggerModel;
+import com.jsyn.scope.AudioScope.TriggerMode;
import com.jsyn.swing.RotaryTextController;
public class ScopeTriggerPanel extends JPanel {
private static final long serialVersionUID = 4511589171299298548L;
- private JComboBox triggerModeComboBox;
+ private JComboBox<DefaultComboBoxModel<TriggerMode>> triggerModeComboBox;
private RotaryTextController triggerLevelKnob;
public ScopeTriggerPanel(AudioScopeModel audioScopeModel) {
diff --git a/src/com/jsyn/swing/DoubleBoundedRangeSlider.java b/src/com/jsyn/swing/DoubleBoundedRangeSlider.java
index c67a4cf..3642221 100644
--- a/src/com/jsyn/swing/DoubleBoundedRangeSlider.java
+++ b/src/com/jsyn/swing/DoubleBoundedRangeSlider.java
@@ -25,7 +25,7 @@ import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-import com.softsynth.util.NumericOutput;
+import com.jsyn.util.NumericOutput;
/**
* Slider that takes a DoubleBoundedRangeModel. It displays the current value in a titled border.
diff --git a/src/com/jsyn/swing/DoubleBoundedTextField.java b/src/com/jsyn/swing/DoubleBoundedTextField.java
index 9605ae1..3301bb1 100644
--- a/src/com/jsyn/swing/DoubleBoundedTextField.java
+++ b/src/com/jsyn/swing/DoubleBoundedTextField.java
@@ -25,8 +25,6 @@ import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-import com.softsynth.util.NumericOutput;
-
/**
* TextField that turns pink when modified, and white when the value is entered.
*
@@ -90,7 +88,7 @@ public class DoubleBoundedTextField extends JTextField {
}
private void setValue(double value) {
- super.setText(NumericOutput.doubleToString(value, 1, 4));
+ super.setText(String.format("%6.4f", value));
markClean();
}
}
diff --git a/src/com/jsyn/swing/EnvelopeEditorBox.java b/src/com/jsyn/swing/EnvelopeEditorBox.java
index 6394fce..b7b224a 100644
--- a/src/com/jsyn/swing/EnvelopeEditorBox.java
+++ b/src/com/jsyn/swing/EnvelopeEditorBox.java
@@ -23,8 +23,6 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
-import com.softsynth.util.NumericOutput;
-
/**
* Edit a list of ordered duration,value pairs suitable for use with a SegmentedEnvelope.
*
@@ -381,7 +379,7 @@ public class EnvelopeEditorBox extends XYController implements MouseListener, Mo
*/
private void drawRange(Graphics g) {
if (rangeStart >= 0) {
- int height = bounds().height;
+ int height = getHeight();
int gx0 = 0, gx1 = 0;
if (rangeEnd < rangeStart) {
@@ -559,11 +557,11 @@ public class EnvelopeEditorBox extends XYController implements MouseListener, Mo
drawAllPoints(g);
/* Show X,Y,TotalX as text. */
- g.drawString(points.getName() + ", len=" + NumericOutput.doubleToString(wx, 7, 3), 5, 15);
+ g.drawString(points.getName() + ", len=" + String.format("%7.3f", wx), 5, 15);
if ((draggedPoint != null) && (dragIndex >= 0)) {
String s = "i=" + dragIndex + ", dur="
- + NumericOutput.doubleToString(draggedPoint[0], 7, 3) + ", y = "
- + NumericOutput.doubleToString(draggedPoint[1], 8, 4);
+ + String.format("%7.3f", draggedPoint[0]) + ", y = "
+ + String.format("%8.4f", draggedPoint[1]);
g.drawString(s, 5, 30);
}
}
diff --git a/src/com/jsyn/swing/XYController.java b/src/com/jsyn/swing/XYController.java
index 49cb9fd..b9cf90a 100644
--- a/src/com/jsyn/swing/XYController.java
+++ b/src/com/jsyn/swing/XYController.java
@@ -91,23 +91,23 @@ public class XYController extends JPanel {
/** Convert from graphics coordinates (pixels) to world coordinates. */
public double convertGXtoWX(int gx) {
- int width = bounds().width;
+ int width = getWidth();
return minWorldX + ((maxWorldX - minWorldX) * gx) / width;
}
public double convertGYtoWY(int gy) {
- int height = bounds().height;
+ int height = getHeight();
return minWorldY + ((maxWorldY - minWorldY) * (height - gy)) / height;
}
/** Convert from world coordinates to graphics coordinates (pixels). */
public int convertWXtoGX(double wx) {
- int width = bounds().width;
+ int width = getWidth();
return (int) (((wx - minWorldX) * width) / (maxWorldX - minWorldX));
}
public int convertWYtoGY(double wy) {
- int height = bounds().height;
+ int height = getHeight();
return height - (int) (((wy - minWorldY) * height) / (maxWorldY - minWorldY));
}
diff --git a/src/com/jsyn/util/NumericOutput.java b/src/com/jsyn/util/NumericOutput.java
new file mode 100644
index 0000000..79afaf1
--- /dev/null
+++ b/src/com/jsyn/util/NumericOutput.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 1999 Phil Burk, Mobileer Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.jsyn.util;
+
+/**
+ * Formatted numeric output. Convert integers and floats to strings based on field widths and
+ * desired decimal places.
+ *
+ * @author Phil Burk (C) 1999 SoftSynth.com
+ */
+
+public class NumericOutput {
+ static char digitToChar(int digit) {
+ if (digit > 9) {
+ return (char) ('A' + digit - 10);
+ } else {
+ return (char) ('0' + digit);
+ }
+ }
+
+ public static String integerToString(int n, int width, boolean leadingZeros) {
+ return integerToString(n, width, leadingZeros, 10);
+ }
+
+ public static String integerToString(int n, int width) {
+ return integerToString(n, width, false, 10);
+ }
+
+ public static String integerToString(int n, int width, boolean leadingZeros, int radix) {
+ if (width > 32)
+ width = 32;
+ StringBuffer buf = new StringBuffer();
+ long ln = n;
+ boolean ifNeg = false;
+ // only do sign if decimal
+ if (radix != 10) {
+ // System.out.println("MASK before : ln = " + ln );
+ ln = ln & 0x00000000FFFFFFFFL;
+ // System.out.println("MASK after : ln = " + ln );
+ } else if (ln < 0) {
+ ifNeg = true;
+ ln = -ln;
+ }
+ if (ln == 0) {
+ buf.append('0');
+ } else {
+ // System.out.println(" ln = " + ln );
+ while (ln > 0) {
+ int rem = (int) (ln % radix);
+ buf.append(digitToChar(rem));
+ ln = ln / radix;
+ }
+ }
+ if (leadingZeros) {
+ int pl = width;
+ if (ifNeg)
+ pl -= 1;
+ for (int i = buf.length(); i < pl; i++)
+ buf.append('0');
+ }
+ if (ifNeg)
+ buf.append('-');
+ // leading spaces
+ for (int i = buf.length(); i < width; i++)
+ buf.append(' ');
+ // reverse buffer to put characters in correct order
+ buf.reverse();
+
+ return buf.toString();
+ }
+
+ /**
+ * Convert double to string.
+ *
+ * @param width = minimum width of formatted string
+ * @param places = number of digits displayed after decimal point
+ */
+ public static String doubleToString(double value, int width, int places) {
+ return doubleToString(value, width, places, false);
+ }
+
+ /**
+ * Convert double to string.
+ *
+ * @param width = minimum width of formatted string
+ * @param places = number of digits displayed after decimal point
+ */
+ public static String doubleToString(double value, int width, int places, boolean leadingZeros) {
+ if (width > 32)
+ width = 32;
+ if (places > 16)
+ places = 16;
+
+ boolean ifNeg = false;
+ if (value < 0.0) {
+ ifNeg = true;
+ value = -value;
+ }
+ // round at relevant decimal place
+ value += 0.5 * Math.pow(10.0, 0 - places);
+ int ival = (int) Math.floor(value);
+ // get portion after decimal point as an integer
+ int fval = (int) ((value - Math.floor(value)) * Math.pow(10.0, places));
+ String result = "";
+
+ result += integerToString(ival, 0, false, 10);
+ result += ".";
+ result += integerToString(fval, places, true, 10);
+
+ if (leadingZeros) {
+ // prepend leading zeros and {-}
+ int zw = width;
+ if (ifNeg)
+ zw -= 1;
+ while (result.length() < zw)
+ result = "0" + result;
+ if (ifNeg)
+ result = "-" + result;
+ } else {
+ // prepend {-} and leading spaces
+ if (ifNeg)
+ result = "-" + result;
+ while (result.length() < width)
+ result = " " + result;
+ }
+ return result;
+ }
+
+ static void testInteger(int n) {
+ System.out.println("Test " + n + ", 0x" + Integer.toHexString(n) + ", %"
+ + Integer.toBinaryString(n));
+ System.out.println(" +,8,t,10 = " + integerToString(n, 8, true, 10));
+ System.out.println(" +,8,f,10 = " + integerToString(n, 8, false, 10));
+ System.out.println(" -,8,t,10 = " + integerToString(-n, 8, true, 10));
+ System.out.println(" -,8,f,10 = " + integerToString(-n, 8, false, 10));
+ System.out.println(" +,8,t,16 = " + integerToString(n, 8, true, 16));
+ System.out.println(" +,8,f,16 = " + integerToString(n, 8, false, 16));
+ System.out.println(" -,8,t,16 = " + integerToString(-n, 8, true, 16));
+ System.out.println(" -,8,f,16 = " + integerToString(-n, 8, false, 16));
+ System.out.println(" +,8,t, 2 = " + integerToString(n, 8, true, 2));
+ System.out.println(" +,8,f, 2 = " + integerToString(n, 8, false, 2));
+ }
+
+ static void testDouble(double value) {
+ System.out.println("Test " + value);
+ System.out.println(" +,5,1 = " + doubleToString(value, 5, 1));
+ System.out.println(" -,5,1 = " + doubleToString(-value, 5, 1));
+
+ System.out.println(" +,14,3 = " + doubleToString(value, 14, 3));
+ System.out.println(" -,14,3 = " + doubleToString(-value, 14, 3));
+
+ System.out.println(" +,6,2,true = " + doubleToString(value, 6, 2, true));
+ System.out.println(" -,6,2,true = " + doubleToString(-value, 6, 2, true));
+ }
+
+ public static void main(String argv[]) {
+ System.out.println("Test NumericOutput");
+ testInteger(0);
+ testInteger(1);
+ testInteger(16);
+ testInteger(23456);
+ testInteger(0x23456);
+ testInteger(0x89ABC);
+ testDouble(0.0);
+ testDouble(0.0678);
+ testDouble(0.1234567);
+ testDouble(1.234567);
+ testDouble(12.34567);
+ testDouble(123.4567);
+ testDouble(1234.5678);
+
+ }
+}
diff --git a/src/com/jsyn/util/soundfile/AIFFFileParser.java b/src/com/jsyn/util/soundfile/AIFFFileParser.java
index d2df08f..2b09d78 100644
--- a/src/com/jsyn/util/soundfile/AIFFFileParser.java
+++ b/src/com/jsyn/util/soundfile/AIFFFileParser.java
@@ -101,6 +101,7 @@ public class AIFFFileParser extends AudioFileParser {
}
/* parse tuning and multi-sample info */
+ @SuppressWarnings("unused")
void parseINSTChunk(IFFParser parser, int ckSize) throws IOException {
int baseNote = parser.readByte();
int detune = parser.readByte();