Subversion Repositories svn.mios

Compare Revisions

Ignore whitespace Rev 627 → Rev 628

/trunk/java/META-INF/MANIFEST.MF
File deleted
/trunk/java/MIOSStudio.java
New file
0,0 → 1,321
/*
* @(#)MIOSStudioDriver.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.prefs.Preferences;
 
import javax.swing.JApplet;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
 
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI;
import org.midibox.apps.miosstudio.gui.MIOSStudioGUI.ExternalCommandButton;
import org.midibox.midi.gui.SysexSendReceiveGUI;
import org.midibox.mios.gui.HexFileUploadGUI;
import org.midibox.utils.gui.DialogOwner;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.SplashScreen;
 
public class MIOSStudio extends JApplet {
 
protected static String frameTitle = "MIOS Studio";
 
protected static String splashTitle = "MIOS Studio beta8.2";
 
protected static String splashImage = "splash.jpg";
 
protected static String frameComment = "MIOS Studio beta8.2";
 
protected org.midibox.apps.miosstudio.MIOSStudio miosStudio;
 
protected MIOSStudioGUI miosStudioGUI;
 
protected Hashtable windows;
 
public MIOSStudio() {
 
this.miosStudio = new org.midibox.apps.miosstudio.MIOSStudio();
 
Preferences preferences = getPreferences();
 
try {
UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
.getCrossPlatformLookAndFeelClassName()));
} catch (Exception e) {
System.out.println(e.toString());
}
 
JDialog.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
 
this.miosStudioGUI = new MIOSStudioGUI(miosStudio);
miosStudioGUI.setCommentLabel(frameComment);
 
this.windows = new Hashtable();
setContentPane(miosStudioGUI);
setJMenuBar(miosStudioGUI.createMenuBar());
}
 
public void init() {
 
Preferences preferences = getPreferences();
 
SysexSendReceiveGUI.currentDirectory = preferences.get(
"sysexCurrentDirectory", SysexSendReceiveGUI.currentDirectory);
 
HexFileUploadGUI.setCurrentDirectory(preferences.get(
"uploadCurrentDirectory", HexFileUploadGUI
.getCurrentDirectory()));
 
miosStudio.getHexFileUploadDeviceManager().setMIOS32_Mode(
preferences.getBoolean("uploadMIOS32_Mode", false));
 
String[] frames = preferences.get("visibleFrames", "").split(",");
String[] ec = preferences.get("externalCommands", "").split("\n");
 
createWindowsHashtable();
 
Enumeration keys = windows.keys();
 
int windowNo = 0;
 
while (keys.hasMoreElements()) {
String keyName = (String) keys.nextElement();
 
JInternalFrame window = (JInternalFrame) windows.get(keyName);
 
int x = preferences.getInt(keyName + "X", 20 * windowNo);
int y = preferences.getInt(keyName + "Y", 20 * windowNo);
int width = preferences.getInt(keyName + "Width", window
.getPreferredSize().width);
int height = preferences.getInt(keyName + "Height", window
.getPreferredSize().height);
 
Dimension d = window.getPreferredSize();
 
if (window.isResizable()) {
window.setBounds(x, y, Math.max(width, d.width), Math.max(
height, d.height));
} else {
window.setBounds(x, y, d.width, d.height);
}
 
if (preferences.getBoolean(keyName + "Visible", false)) {
miosStudioGUI.showFrame(window);
try {
window.setMaximum(preferences.getBoolean(keyName
+ "Maximized", false));
window.setIcon(preferences.getBoolean(
keyName + "Iconified", false));
} catch (Exception e) {
System.out.println(e.toString());
}
}
 
windowNo++;
}
 
for (int i = frames.length - 1; i >= 0; i--) {
if (windows.containsKey(frames[i])) {
((JInternalFrame) windows.get(frames[i])).toFront();
}
}
 
for (int i = 0; i < ec.length; i++) {
String[] temp = ec[i].split("\t");
if (temp.length == 2) {
miosStudioGUI.addExternalCommandButton(temp[0], temp[1]);
}
}
}
 
public void destroy() {
 
Preferences preferences = getPreferences();
 
preferences.put("lookAndFeel", miosStudioGUI.getLookAndFeel());
preferences.putBoolean("defaultDecoratedFrames", miosStudioGUI
.isDefaultDecoratedFrames());
 
preferences.put("sysexCurrentDirectory",
SysexSendReceiveGUI.currentDirectory);
 
preferences.put("uploadCurrentDirectory", HexFileUploadGUI
.getCurrentDirectory());
 
preferences.putBoolean("uploadMIOS32_Mode", miosStudio
.getHexFileUploadDeviceManager().isMIOS32_Mode());
 
JInternalFrame[] frames = miosStudioGUI.getDesktop().getAllFrames();
String visibleFrames = "";
 
for (int i = 0; i < frames.length; i++) {
Enumeration keys = windows.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (windows.get(key) == frames[i]) {
visibleFrames += (key + ",");
}
}
}
 
preferences.put("visibleFrames", visibleFrames);
 
Enumeration keys = windows.keys();
while (keys.hasMoreElements()) {
String keyName = (String) keys.nextElement();
JInternalFrame window = (JInternalFrame) windows.get(keyName);
 
boolean visible = window.isVisible();
try {
preferences.putBoolean(keyName + "Iconified", window.isIcon());
preferences.putBoolean(keyName + "Maximized", window
.isMaximum());
window.setIcon(false);
window.setMaximum(false);
} catch (Exception e) {
System.out.println(e);
}
preferences.putInt(keyName + "X", window.getX());
preferences.putInt(keyName + "Y", window.getY());
preferences.putInt(keyName + "Width", window.getWidth());
preferences.putInt(keyName + "Height", window.getHeight());
preferences.putBoolean(keyName + "Visible", visible);
}
 
String externalCommandsString = "";
 
for (int i = 0; i < miosStudioGUI.getExternalCommands().size(); i++) {
ExternalCommandButton ecb = (ExternalCommandButton) miosStudioGUI
.getExternalCommands().elementAt(i);
externalCommandsString += ecb.commandName + "\t"
+ ecb.externalCommand + "\n";
}
preferences.put("externalCommands", externalCommandsString);
}
 
public void exit(JFrame frame) {
 
Preferences preferences = getPreferences();
 
preferences.putInt("mainWindowX", frame.getX());
preferences.putInt("mainWindowY", frame.getY());
preferences.putInt("mainWindowWidth", frame.getWidth());
preferences.putInt("mainWindowHeight", frame.getHeight());
System.exit(0);
}
 
protected Preferences getPreferences() {
return Preferences.userRoot().node("org/midibox/miostudio/gui");
}
 
protected void createWindowsHashtable() {
 
windows.put("midiDevicesWindow", miosStudioGUI
.getMidiDeviceRoutingWindow());
windows.put("midiOutPortMonitorWindow", miosStudioGUI
.getMidiOutPortMonitorWindow());
windows.put("midiInPortMonitorWindow", miosStudioGUI
.getMidiInPortMonitorWindow());
windows.put("virtualKeyboardWindow", miosStudioGUI
.getMidiKeyboardControllerWindow());
/*
* windows.put("sysexWindow", miosStudioGUI
* .getSysexSendReceiveDeviceManagerWindow());
*/
 
windows.put("uploadWindow", miosStudioGUI
.getHexFileUploadDeviceManagerWindow());
windows.put("lcdWindow", miosStudioGUI.getLcdMessageWindow());
windows.put("debugWindow", miosStudioGUI.getDebugFunctionWindow());
windows
.put("miosTerminalWindow", miosStudioGUI
.getMIOSTerminalWindow());
windows.put("helpWindow", miosStudioGUI.getHelpWindow());
 
}
 
public static void main(String[] args) {
SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle);
 
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 
splashScreen.setLocation(
(screenSize.width - splashScreen.getWidth()) / 2,
(screenSize.height - splashScreen.getHeight()) / 2);
 
splashScreen.setVisible(true);
 
Preferences preferences = Preferences.userRoot().node(
"org/midibox/miostudio/gui");
 
JFrame.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
 
final JFrame frame = new JFrame(frameTitle);
 
DialogOwner.setFrame(frame);
 
final MIOSStudio miosStudio = new MIOSStudio();
miosStudio.init();
 
frame.setContentPane(miosStudio);
frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
 
frame.setBounds(preferences.getInt("mainWindowX", 50), preferences
.getInt("mainWindowY", 50), preferences.getInt(
"mainWindowWidth", (screenSize.width - 100)), preferences
.getInt("mainWindowHeight", (screenSize.height - 100)));
 
JMenuItem exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setMnemonic(KeyEvent.VK_X);
exitMenuItem.setActionCommand("exit");
 
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
miosStudio.destroy();
miosStudio.exit(frame);
}
});
 
miosStudio.miosStudioGUI.getFileMenu().add(exitMenuItem);
 
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
miosStudio.destroy();
miosStudio.exit(frame);
}
});
 
frame.setVisible(true);
splashScreen.setVisible(false);
}
}
/trunk/java/MIOSStudioSID.java
New file
0,0 → 1,123
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;
import java.util.prefs.Preferences;
 
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
 
import org.midibox.apps.miosstudiosid.gui.MIOSStudioSIDGUI;
import org.midibox.utils.gui.DialogOwner;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.SplashScreen;
 
public class MIOSStudioSID extends MIOSStudio {
 
protected static String frameTitle = "MIOS Studio +SID";
 
protected static String splashTitle = "MIOS Studio beta8.2 + SIDV2 Librarian";
 
protected static String splashImage = "splash.jpg";
 
protected static String frameComment = "MIOS Studio +SID beta8.2";
 
public MIOSStudioSID() {
 
this.miosStudio = new org.midibox.apps.miosstudiosid.MIOSStudioSID();
 
Preferences preferences = getPreferences();
 
try {
UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
.getCrossPlatformLookAndFeelClassName()));
} catch (Exception e) {
System.out.println(e.toString());
}
 
JDialog.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
 
this.miosStudioGUI = new MIOSStudioSIDGUI(
(org.midibox.apps.miosstudiosid.MIOSStudioSID) miosStudio);
miosStudioGUI.setCommentLabel(frameComment);
 
this.windows = new Hashtable();
setContentPane(miosStudioGUI);
setJMenuBar(miosStudioGUI.createMenuBar());
}
 
protected Preferences getPreferences() {
 
return Preferences.userRoot().node("org/midibox/miostudiosid/gui");
}
 
protected void createWindowsHashtable() {
super.createWindowsHashtable();
 
windows.put("sidv2librarianWindow", ((MIOSStudioSIDGUI) miosStudioGUI)
.getSidv2librarianWindow());
}
 
public static void main(String[] args) {
SplashScreen splashScreen = new SplashScreen(splashImage, splashTitle);
 
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 
splashScreen.setLocation(
(screenSize.width - splashScreen.getWidth()) / 2,
(screenSize.height - splashScreen.getHeight()) / 2);
 
splashScreen.setVisible(true);
 
Preferences preferences = Preferences.userRoot().node(
"org/midibox/miostudiosid/gui");
 
JFrame.setDefaultLookAndFeelDecorated(preferences.getBoolean(
"defaultDecoratedFrames", false));
 
final JFrame frame = new JFrame(frameTitle);
 
DialogOwner.setFrame(frame);
 
final MIOSStudioSID miosStudioSID = new MIOSStudioSID();
miosStudioSID.init();
 
frame.setContentPane(miosStudioSID);
frame.setIconImage(ImageLoader.getImageIcon("ucIcon.png").getImage());
 
frame.setBounds(preferences.getInt("mainWindowX", 50), preferences
.getInt("mainWindowY", 50), preferences.getInt(
"mainWindowWidth", (screenSize.width - 100)), preferences
.getInt("mainWindowHeight", (screenSize.height - 100)));
 
JMenuItem exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setMnemonic(KeyEvent.VK_X);
exitMenuItem.setActionCommand("exit");
 
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
miosStudioSID.destroy();
miosStudioSID.exit(frame);
}
});
 
miosStudioSID.miosStudioGUI.getFileMenu().add(exitMenuItem);
 
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
miosStudioSID.destroy();
miosStudioSID.exit(frame);
}
});
 
frame.setVisible(true);
splashScreen.setVisible(false);
}
}
/trunk/java/images/transmit.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/java/images/transmit.png
New file
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/wheelbuilder.pl
===================================================================
--- trunk/java/images/wheelbuilder.pl (revision 0)
+++ trunk/java/images/wheelbuilder.pl (revision 628)
@@ -0,0 +1,85 @@
+#!/usr/bin/perl
+
+use Gimp;
+use Cwd 'abs_path';
+Gimp::init;
+
+# args below
+
+$baseImage = $ARGV[0];
+$noOfImages = 51;
+$degreesOfRotation = 90;
+$height = 71;
+$axis = 'x';
+
+# calculated variables below
+
+@fn = split(/\./,$baseImage);
+$original_image = abs_path($fn[0]);
+$width = int $height*1.3333;
+$crop = ($width - $height)/2;
+$incrementAngle = $degreesOfRotation/($noOfImages-1);
+$startingAngle = 0-$degreesOfRotation/2;
+
+# begin below
+
+open(POV, $baseImage);
+@pov = <POV>;
+close POV;
+
+$image_strip = Gimp->gimp_image_new($noOfImages*$height,$height,0);
+
+$back = $image_strip->gimp_layer_new($noOfImages*$height, $height, RGB, "Back", 100, NORMAL_MODE);
+
+$image_strip->gimp_image_add_layer($back,0);
+
+for ($imageNo = 0; $imageNo < $noOfImages; $imageNo++)
+{
+ $angle = $startingAngle + ($incrementAngle*$imageNo);
+
+ for($i = 0; $i < scalar(@pov); $i++)
+ {
+ if ($pov[$i] =~ /Rotation/)
+ {
+ $pov[$i+1] = "rotate $axis*$angle\n";
+ }
+ }
+
+ $newImage = "$original_image$imageNo";
+
+ open(OUTF, ">$newImage.pov");
+ print OUTF @pov;
+ close OUTF;
+ system("povray $newImage.pov -H$height -W$width +A -D -V && rm -f $newImage.pov");
+
+ $image = Gimp->file_png_load("$newImage.png", "$newImage.png");
+ $image->gimp_crop($height,$height,$crop,0);
+
+ $layer = $image->gimp_image_get_active_layer();
+ $layer->gimp_edit_copy();
+
+ $float = $image_strip->gimp_image_get_active_layer()->gimp_edit_paste(1);
+ $float->gimp_layer_set_offsets($imageNo*$height,0);
+
+ $image_strip->gimp_image_merge_visible_layers(2);
+
+ system("rm -f $newImage.png");
+}
+
+$layer = $image_strip->gimp_image_get_active_layer();
+$layer->gimp_layer_add_alpha();
+
+$layer->gimp_fuzzy_select(1,1,30,0,1,0,0,0);
+
+$mask = $layer->gimp_layer_create_mask(0);
+
+$layer->gimp_layer_add_mask($mask);
+
+$mask->gimp_bucket_fill(0,0,100,0,0,1,1);
+
+$layer->gimp_layer_remove_mask(0);
+
+$final_image = $original_image."_strip.png";
+
+Gimp->file_png_save($image_strip, $image_strip->gimp_image_active_drawable, $final_image, $final_image, 125, 0, 0, 0, 0, 0, 0);
+
Index: trunk/java/images/expressionwheel_vertical_strip.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/expressionwheel_vertical_strip.png
===================================================================
--- trunk/java/images/expressionwheel_vertical_strip.png (revision 0)
+++ trunk/java/images/expressionwheel_vertical_strip.png (revision 628)
/trunk/java/images/expressionwheel_vertical_strip.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/expressionwheel_horizontal_strip.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/expressionwheel_horizontal_strip.png
===================================================================
--- trunk/java/images/expressionwheel_horizontal_strip.png (revision 0)
+++ trunk/java/images/expressionwheel_horizontal_strip.png (revision 628)
/trunk/java/images/expressionwheel_horizontal_strip.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/splash.jpg
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/splash.jpg
===================================================================
--- trunk/java/images/splash.jpg (revision 0)
+++ trunk/java/images/splash.jpg (revision 628)
/trunk/java/images/splash.jpg
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/expressionwheel_vertical.pov
===================================================================
--- trunk/java/images/expressionwheel_vertical.pov (revision 0)
+++ trunk/java/images/expressionwheel_vertical.pov (revision 628)
@@ -0,0 +1,160 @@
+#include "colors.inc"
+
+camera
+{
+ angle 10
+ location <0, 0, -50>
+ look_at <0,0,0>
+}
+
+background
+{
+ colour Clear
+}
+
+light_source
+{
+ <-20,20,-20> colour White
+}
+
+#declare reverse_switch =
+
+ difference
+ {
+difference{
+ union{
+ difference
+ {
+ difference
+ {
+ box
+ {
+ <-2,0,-1.1><2,3.8,1.1>
+ }
+ box {
+ <-2,0,-1.1><-3,4,1.1>
+ rotate z*-15
+ translate x*-.35
+ }
+ box {
+ <2,0,-1.1><3,4,1.1>
+ rotate z*15
+ translate x*.35
+ }
+ box
+ {
+ <-2.1,-1,-1.6><2.1,3.9,-.7>
+ rotate x*5
+ translate z*-.2
+ }
+ box
+ {
+ <-2.1,-1,1.6><2.1,3.9,.7>
+ rotate x*-5
+ translate z*.2
+ }
+
+ pigment { Gray95}
+
+ }
+
+ translate y*2
+ scale y*.5
+ scale z*.7
+ }
+cylinder
+{
+ <-2,0,0><2,0,0>,2
+}
+ }
+
+/* text {
+ ttf "cyrvetic.ttf" "FWD".15, .1*x
+ pigment { Black }
+ scale 1.6
+ rotate z*180
+ rotate x*25
+ translate x*1.75
+ translate y*1.6
+ translate z*-1.5
+
+
+ }
+
+ text {
+ ttf "cyrvetic.ttf" "REV" .15, .1*x
+ pigment { Black }
+ scale 1.6
+ rotate z*-180
+ rotate y*180
+ rotate x*-25
+ translate x*-1.65
+ translate y*1.6
+ translate z*1.5
+
+
+ }
+
+ */
+
+ //rotate x*-30
+ scale x*.26
+}
+
+
+
+
+
+
+/*box {
+ <-2.1,.8,-2><2.1,-2,2>
+ pigment { Black }
+
+
+
+} */
+
+}
+
+
+object
+{
+ reverse_switch
+ pigment { LightGray }
+ finish
+ {
+ ambient .6
+ phong .7
+ brilliance 5
+ reflection .2
+ }
+
+ scale 1.3
+ rotate x*-90
+ //Rotation
+ //rotate x*45
+
+
+ //rotate y*-5
+ //rotate x*-45
+ //rotate z*90
+ //scale 1.5
+ //scale x*.3
+ //rotate y*90
+ // Top View
+ // rotate -x*90 // scale 1.4 //translate y*2.36
+
+ // Bottom View
+ // rotate x*90 scale .72 translate y*2.36
+
+ // Side View
+ // scale .68 translate y*-.8
+
+ // Angle View
+ // rotate -x*45 scale .58 translate y*.63
+}
+
+box {
+<.8,2.55,1><-.8,-2.55,-1.3>
+pigment {Black}
+}
Index: trunk/java/images/down.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/expressionwheel_horizontal.pov
===================================================================
--- trunk/java/images/expressionwheel_horizontal.pov (revision 0)
+++ trunk/java/images/expressionwheel_horizontal.pov (revision 628)
@@ -0,0 +1,162 @@
+#include "colors.inc"
+
+camera
+{
+ angle 10
+ location <0, 0, -50>
+ look_at <0,0,0>
+}
+
+background
+{
+ colour Clear
+}
+
+light_source
+{
+ <-20,20,-20> colour White
+}
+
+#declare reverse_switch =
+
+ difference
+ {
+difference{
+ union{
+ difference
+ {
+ difference
+ {
+ box
+ {
+ <-2,0,-1.1><2,3.8,1.1>
+ }
+ box {
+ <-2,0,-1.1><-3,4,1.1>
+ rotate z*-15
+ translate x*-.35
+ }
+ box {
+ <2,0,-1.1><3,4,1.1>
+ rotate z*15
+ translate x*.35
+ }
+ box
+ {
+ <-2.1,-1,-1.6><2.1,3.9,-.7>
+ rotate x*5
+ translate z*-.2
+ }
+ box
+ {
+ <-2.1,-1,1.6><2.1,3.9,.7>
+ rotate x*-5
+ translate z*.2
+ }
+
+ pigment { Gray95}
+
+ }
+
+ translate y*2
+ scale y*.5
+ scale z*.7
+ }
+cylinder
+{
+ <-2,0,0><2,0,0>,2
+}
+ }
+
+/* text {
+ ttf "cyrvetic.ttf" "FWD".15, .1*x
+ pigment { Black }
+ scale 1.6
+ rotate z*180
+ rotate x*25
+ translate x*1.75
+ translate y*1.6
+ translate z*-1.5
+
+
+ }
+
+ text {
+ ttf "cyrvetic.ttf" "REV" .15, .1*x
+ pigment { Black }
+ scale 1.6
+ rotate z*-180
+ rotate y*180
+ rotate x*-25
+ translate x*-1.65
+ translate y*1.6
+ translate z*1.5
+
+
+ }
+
+ */
+
+ //rotate x*-30
+ scale x*.26
+}
+
+
+
+
+
+
+/*box {
+ <-2.1,.8,-2><2.1,-2,2>
+ pigment { Black }
+
+
+
+} */
+
+}
+
+
+object
+{
+ reverse_switch
+ pigment { LightGray }
+ finish
+ {
+ ambient .6
+ phong .7
+ brilliance 5
+ reflection .2
+ }
+
+ scale 1.3
+rotate x*-90
+ //Rotation
+ //rotate x*45
+
+
+ rotate z*-90
+ //rotate y*-5
+ //rotate x*-45
+ //rotate z*90
+ //scale 1.5
+ //scale x*.3
+ //rotate y*90
+ // Top View
+ // rotate -x*90 // scale 1.4 //translate y*2.36
+
+ // Bottom View
+ // rotate x*90 scale .72 translate y*2.36
+
+ // Side View
+ // scale .68 translate y*-.8
+
+ // Angle View
+ // rotate -x*45 scale .58 translate y*.63
+}
+
+box {
+<.8,2.55,1><-.8,-2.55,-1.3>
+pigment {Black}
+rotate z*90
+}
Index: trunk/java/images/receive.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/receive.png
===================================================================
--- trunk/java/images/receive.png (revision 0)
+++ trunk/java/images/receive.png (revision 628)
/trunk/java/images/receive.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/wKeyD.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/wKeyD.png
===================================================================
--- trunk/java/images/wKeyD.png (revision 0)
+++ trunk/java/images/wKeyD.png (revision 628)
/trunk/java/images/wKeyD.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/miosTerminal.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/miosTerminal.png
===================================================================
--- trunk/java/images/miosTerminal.png (revision 0)
+++ trunk/java/images/miosTerminal.png (revision 628)
/trunk/java/images/miosTerminal.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/wKeyU.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/images/wKeyU.png
===================================================================
--- trunk/java/images/wKeyU.png (revision 0)
+++ trunk/java/images/wKeyU.png (revision 628)
/trunk/java/images/wKeyU.png
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/java/images/up.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/java/COPYRIGHT.txt
===================================================================
--- trunk/java/COPYRIGHT.txt (revision 0)
+++ trunk/java/COPYRIGHT.txt (revision 628)
@@ -0,0 +1,345 @@
+******************************************************************************
+
+This file contains the text of the GNU General Public License under which
+the application is released.
+
+------------
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Index: trunk/java/VirtualKeyboard.java
===================================================================
--- trunk/java/VirtualKeyboard.java (revision 0)
+++ trunk/java/VirtualKeyboard.java (revision 628)
@@ -0,0 +1,149 @@
+/*
+ * @(#)VirtualKeyboardDriver.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.prefs.Preferences;
+
+import javax.swing.JApplet;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JMenuItem;
+import javax.swing.UIManager;
+
+import org.midibox.apps.virtualkeyboard.gui.VirtualKeyboardGUI;
+import org.midibox.utils.gui.ImageLoader;
+
+public class VirtualKeyboard extends JApplet {
+
+ final static Preferences preferences = Preferences.userRoot().node(
+ "org/midibox/virtualkeyboard/gui");
+
+ private org.midibox.apps.virtualkeyboard.VirtualKeyboard virtualKeyboard;
+
+ private VirtualKeyboardGUI virtualKeyboardGUI;
+
+ public VirtualKeyboard() {
+ virtualKeyboard = new org.midibox.apps.virtualkeyboard.VirtualKeyboard();
+
+ try {
+ UIManager.setLookAndFeel(preferences.get("lookAndFeel", UIManager
+ .getCrossPlatformLookAndFeelClassName()));
+ } catch (Exception e) {
+ System.out.println(e.toString());
+ }
+
+ JDialog.setDefaultLookAndFeelDecorated(preferences.getBoolean(
+ "defaultDecoratedFrames", false));
+
+ JFrame.setDefaultLookAndFeelDecorated(preferences.getBoolean(
+ "defaultDecoratedFrames", false));
+
+ virtualKeyboardGUI = new VirtualKeyboardGUI(virtualKeyboard);
+
+ getContentPane().add(virtualKeyboardGUI);
+
+ setJMenuBar(virtualKeyboardGUI.createMenuBar());
+ }
+
+ public void init() {
+ virtualKeyboardGUI.setShowConnections(preferences.getBoolean(
+ "showConnections", true));
+ }
+
+ public void destroy() {
+ preferences.put("lookAndFeel", virtualKeyboardGUI.getLookAndFeel());
+
+ preferences.putBoolean("defaultDecoratedFrames", virtualKeyboardGUI
+ .isDefaultDecoratedFrames());
+
+ preferences.putBoolean("showConnections", virtualKeyboardGUI
+ .isShowConnections());
+ }
+
+ public static void exit(JFrame frame) {
+ preferences.putInt("mainWindowX", frame.getX());
+ preferences.putInt("mainWindowY", frame.getY());
+ System.exit(0);
+ }
+
+ public static void main(String[] args) {
+
+ final VirtualKeyboard virtualKeyboardGUIDriver = new VirtualKeyboard();
+ virtualKeyboardGUIDriver.init();
+
+ final JFrame frame = new JFrame("Virtual Keyboard");
+ frame.setContentPane(virtualKeyboardGUIDriver);
+
+ frame.setIconImage(ImageLoader.getImageIcon("piano.png").getImage());
+ frame.pack();
+ frame.setResizable(false);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+ frame.setLocation(preferences.getInt("mainWindowX", 50), preferences
+ .getInt("mainWindowY", 50));
+
+ frame.setLocation(preferences.getInt("windowX", 50), preferences
+ .getInt("windowY", 50));
+
+ JMenuItem exitMenuItem = new JMenuItem("Exit");
+ exitMenuItem.setMnemonic(KeyEvent.VK_X);
+ exitMenuItem.setActionCommand("exit");
+
+ exitMenuItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ virtualKeyboardGUIDriver.destroy();
+ exit(frame);
+ }
+ });
+
+ virtualKeyboardGUIDriver.virtualKeyboardGUI.getFileMenu().add(
+ exitMenuItem);
+
+ virtualKeyboardGUIDriver.virtualKeyboardGUI.getMidiDeviceRoutingGUI()
+ .addComponentListener(new ComponentAdapter() {
+ public void componentShown(ComponentEvent arg0) {
+ frame.pack();
+ }
+
+ public void componentHidden(ComponentEvent arg0) {
+ frame.pack();
+ }
+ });
+
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent we) {
+ virtualKeyboardGUIDriver.destroy();
+ exit(frame);
+ }
+ });
+
+ frame.setVisible(true);
+ }
+}
Index: trunk/java/mios/mios_vectors.inc
===================================================================
--- trunk/java/mios/mios_vectors.inc (revision 0)
+++ trunk/java/mios/mios_vectors.inc (revision 628)
@@ -0,0 +1,256 @@
+MIOS_MIDI_BeginStream EQU 0x2c00
+MIOS_MIDI_DeviceIDAutoSet EQU 0x2c04
+MIOS_MIDI_DeviceIDGet EQU 0x2c08
+MIOS_MIDI_DeviceIDSet EQU 0x2c0c
+MIOS_MIDI_EndStream EQU 0x2c10
+MIOS_MIDI_Init EQU 0x2c14
+MIOS_MIDI_InterfaceAutoSet EQU 0x2c18
+MIOS_MIDI_InterfaceGet EQU 0x2c1c
+MIOS_MIDI_InterfaceSet EQU 0x2c20
+MIOS_MIDI_MergerGet EQU 0x2c24
+MIOS_MIDI_MergerSet EQU 0x2c28
+MIOS_MIDI_RxBufferFree EQU 0x2c2c
+MIOS_MIDI_RxBufferGet EQU 0x2c30
+MIOS_MIDI_RxBufferPut EQU 0x2c34
+MIOS_MIDI_RxBufferUsed EQU 0x2c38
+MIOS_MIDI_TxBufferFlush EQU 0x2c3c
+MIOS_MIDI_TxBufferFree EQU 0x2c40
+MIOS_MIDI_TxBufferGet EQU 0x2c44
+MIOS_MIDI_TxBufferPut EQU 0x2c48
+MIOS_MIDI_TxBufferUsed EQU 0x2c4c
+MIOS_MPROC_MergerDisable EQU 0x2c50
+MIOS_MPROC_MergerEnable EQU 0x2c54
+MIOS_MPROC_MergerGet EQU 0x2c58
+MIOS_AIN_DeadbandGet EQU 0x2c5c
+MIOS_AIN_DeadbandSet EQU 0x2c60
+MIOS_AIN_Muxed EQU 0x2c64
+MIOS_AIN_NumberGet EQU 0x2c68
+MIOS_AIN_NumberSet EQU 0x2c6c
+MIOS_AIN_Pin7bitGet EQU 0x2c70
+MIOS_AIN_PinGet EQU 0x2c74
+MIOS_AIN_PinLSBGet EQU 0x2c78
+MIOS_AIN_PinMSBGet EQU 0x2c7c
+MIOS_AIN_UnMuxed EQU 0x2c80
+MIOS_MF_PWM_DutyCycleDownGet EQU 0x2c84
+MIOS_MF_PWM_DutyCycleDownSet EQU 0x2c88
+MIOS_MF_PWM_DutyCycleUpGet EQU 0x2c8c
+MIOS_MF_PWM_DutyCycleUpSet EQU 0x2c90
+MIOS_MF_DeadbandGet EQU 0x2c94
+MIOS_MF_DeadbandSet EQU 0x2c98
+MIOS_MF_Disable EQU 0x2c9c
+MIOS_MF_Enable EQU 0x2ca0
+MIOS_MF_FaderMove EQU 0x2ca4
+MIOS_MF_SuspendDisable EQU 0x2ca8
+MIOS_MF_SuspendEnable EQU 0x2cac
+MIOS_MF_SuspendGet EQU 0x2cb0
+MIOS_DIN_PinGet EQU 0x2cb4
+MIOS_DIN_SRGet EQU 0x2cb8
+MIOS_DOUT_PinGet EQU 0x2cbc
+MIOS_DOUT_PinSet EQU 0x2cc0
+MIOS_DOUT_PinSet0 EQU 0x2cc4
+MIOS_DOUT_PinSet1 EQU 0x2cc8
+MIOS_DOUT_SRGet EQU 0x2ccc
+MIOS_DOUT_SRSet EQU 0x2cd0
+MIOS_ENC_Abs7bitAdd EQU 0x2cd4
+MIOS_ENC_Abs7bitGet EQU 0x2cd8
+MIOS_ENC_Abs7bitSet EQU 0x2cdc
+MIOS_ENC_NumberGet EQU 0x2ce0
+MIOS_ENC_SpeedGet EQU 0x2ce4
+MIOS_ENC_SpeedSet EQU 0x2ce8
+MIOS_SRIO_NumberGet EQU 0x2cec
+MIOS_SRIO_NumberSet EQU 0x2cf0
+MIOS_SRIO_TS_SensitivityGet EQU 0x2cf4
+MIOS_SRIO_TS_SensitivitySet EQU 0x2cf8
+MIOS_SRIO_UpdateFrqGet EQU 0x2cfc
+MIOS_SRIO_UpdateFrqSet EQU 0x2d00
+MIOS_LCD_Clear EQU 0x2d04
+MIOS_LCD_Cmd EQU 0x2d08
+MIOS_LCD_CursorGet EQU 0x2d0c
+MIOS_LCD_CursorSet EQU 0x2d10
+MIOS_LCD_Data EQU 0x2d14
+MIOS_LCD_Init EQU 0x2d18
+MIOS_LCD_PrintBCD1 EQU 0x2d1c
+MIOS_LCD_PrintBCD2 EQU 0x2d20
+MIOS_LCD_PrintBCD3 EQU 0x2d24
+MIOS_LCD_PrintChar EQU 0x2d28
+MIOS_LCD_PrintHex1 EQU 0x2d2c
+MIOS_LCD_PrintHex2 EQU 0x2d30
+MIOS_LCD_PrintMessage EQU 0x2d34
+MIOS_LCD_PrintPreconfString EQU 0x2d38
+MIOS_LCD_PrintString EQU 0x2d3c
+MIOS_LCD_TypeAutoSet EQU 0x2d40
+MIOS_LCD_TypeGet EQU 0x2d44
+MIOS_LCD_TypeSet EQU 0x2d48
+MIOS_LCD_YAddressGet EQU 0x2d4c
+MIOS_LCD_YAddressSet EQU 0x2d50
+MIOS_GLCD_FontInit EQU 0x2d54
+MIOS_GLCD_GCursorGet EQU 0x2d58
+MIOS_GLCD_GCursorSet EQU 0x2d5c
+MIOS_EEPROM_Read EQU 0x2d60
+MIOS_EEPROM_Write EQU 0x2d64
+MIOS_FLASH_Read EQU 0x2d68
+MIOS_FLASH_Write EQU 0x2d6c
+MIOS_BANKSTICK_Read EQU 0x2d70
+MIOS_BANKSTICK_Write EQU 0x2d74
+MIOS_TIMER_Init EQU 0x2d78
+MIOS_TIMER_Start EQU 0x2d7c
+MIOS_TIMER_Stop EQU 0x2d80
+MIOS_HLP_AddressFromTable EQU 0x2d84
+MIOS_HLP_GetBitANDMask EQU 0x2d88
+MIOS_HLP_GetBitORMask EQU 0x2d8c
+MIOS_HLP_GetIndex_2bytes EQU 0x2d90
+MIOS_HLP_GetIndex_4bytes EQU 0x2d94
+MIOS_HLP_IndirectJump EQU 0x2d98
+MIOS_Delay EQU 0x2d9c
+MIOS_GPCounterGet EQU 0x2da0
+MIOS_Reset EQU 0x2da4
+MIOS_SystemResume EQU 0x2da8
+MIOS_SystemSuspend EQU 0x2dac
+MIOS_UserResume EQU 0x2db0
+MIOS_UserSuspend EQU 0x2db4
+MIOS_HLP_16bitAddSaturate EQU 0x2db8
+MIOS_DIN_PinAutoRepeatEnable EQU 0x2dbc
+MIOS_DIN_PinAutoRepeatDisable EQU 0x2dc0
+MIOS_DIN_PinAutoRepeatGet EQU 0x2dc4
+MIOS_CLCD_SpecialCharInit EQU 0x2dc8
+MIOS_CLCD_SpecialCharsInit EQU 0x2dcc
+MIOS_AIN_DynamicPrioSet EQU 0x2dd0
+MIOS_AIN_DynamicPrioGet EQU 0x2dd4
+MIOS_AIN_LastPinsGet EQU 0x2dd8
+MIOS_BANKSTICK_CtrlSet EQU 0x2ddc
+MIOS_BANKSTICK_CtrlGet EQU 0x2de0
+MIOS_BANKSTICK_WritePage EQU 0x2de4
+MIOS_HLP_Dec2BCD EQU 0x2de8
+MIOS_LCD_PrintBCD4 EQU 0x2dec
+MIOS_LCD_PrintBCD5 EQU 0x2df0
+MIOS_LCD_MessageStart EQU 0x2df4
+MIOS_LCD_MessageStop EQU 0x2df8
+MIOS_MF_PWM_PeriodGet EQU 0x2dfc
+MIOS_MF_PWM_PeriodSet EQU 0x2e00
+MIOS_IIC_Start EQU 0x2e04
+MIOS_IIC_Stop EQU 0x2e08
+MIOS_IIC_ByteSend EQU 0x2e0c
+MIOS_IIC_ByteReceive EQU 0x2e10
+MIOS_IIC_AckSend EQU 0x2e14
+MIOS_IIC_NakSend EQU 0x2e18
+MIOS_IIC_CtrlSet EQU 0x2e1c
+MIOS_IIC_CtrlGet EQU 0x2e20
+MIOS_SRIO_DebounceSet EQU 0x2e24
+MIOS_SRIO_DebounceGet EQU 0x2e28
+MIOS_MF_TouchDetectionReset EQU 0x2e2c
+MIOS_BANKSTICK_ReadPage EQU 0x2e30
+MIOS_EEPROM_ReadPage EQU 0x2e34
+MIOS_EEPROM_WritePage EQU 0x2e38
+MIOS_TIMER_ReInit EQU 0x2e3c
+MIOS_RESERVED_144 EQU 0x2e40
+MIOS_RESERVED_145 EQU 0x2e44
+MIOS_RESERVED_146 EQU 0x2e48
+MIOS_RESERVED_147 EQU 0x2e4c
+MIOS_RESERVED_148 EQU 0x2e50
+MIOS_RESERVED_149 EQU 0x2e54
+MIOS_RESERVED_150 EQU 0x2e58
+MIOS_RESERVED_151 EQU 0x2e5c
+MIOS_RESERVED_152 EQU 0x2e60
+MIOS_RESERVED_153 EQU 0x2e64
+MIOS_RESERVED_154 EQU 0x2e68
+MIOS_RESERVED_155 EQU 0x2e6c
+MIOS_RESERVED_156 EQU 0x2e70
+MIOS_RESERVED_157 EQU 0x2e74
+MIOS_RESERVED_158 EQU 0x2e78
+MIOS_RESERVED_159 EQU 0x2e7c
+MIOS_RESERVED_160 EQU 0x2e80
+MIOS_RESERVED_161 EQU 0x2e84
+MIOS_RESERVED_162 EQU 0x2e88
+MIOS_RESERVED_163 EQU 0x2e8c
+MIOS_RESERVED_164 EQU 0x2e90
+MIOS_RESERVED_165 EQU 0x2e94
+MIOS_RESERVED_166 EQU 0x2e98
+MIOS_RESERVED_167 EQU 0x2e9c
+MIOS_RESERVED_168 EQU 0x2ea0
+MIOS_RESERVED_169 EQU 0x2ea4
+MIOS_RESERVED_170 EQU 0x2ea8
+MIOS_RESERVED_171 EQU 0x2eac
+MIOS_RESERVED_172 EQU 0x2eb0
+MIOS_RESERVED_173 EQU 0x2eb4
+MIOS_RESERVED_174 EQU 0x2eb8
+MIOS_RESERVED_175 EQU 0x2ebc
+MIOS_RESERVED_176 EQU 0x2ec0
+MIOS_RESERVED_177 EQU 0x2ec4
+MIOS_RESERVED_178 EQU 0x2ec8
+MIOS_RESERVED_179 EQU 0x2ecc
+MIOS_RESERVED_180 EQU 0x2ed0
+MIOS_RESERVED_181 EQU 0x2ed4
+MIOS_RESERVED_182 EQU 0x2ed8
+MIOS_RESERVED_183 EQU 0x2edc
+MIOS_RESERVED_184 EQU 0x2ee0
+MIOS_RESERVED_185 EQU 0x2ee4
+MIOS_RESERVED_186 EQU 0x2ee8
+MIOS_RESERVED_187 EQU 0x2eec
+MIOS_RESERVED_188 EQU 0x2ef0
+MIOS_RESERVED_189 EQU 0x2ef4
+MIOS_RESERVED_190 EQU 0x2ef8
+MIOS_RESERVED_191 EQU 0x2efc
+MIOS_RESERVED_192 EQU 0x2f00
+MIOS_RESERVED_193 EQU 0x2f04
+MIOS_RESERVED_194 EQU 0x2f08
+MIOS_RESERVED_195 EQU 0x2f0c
+MIOS_RESERVED_196 EQU 0x2f10
+MIOS_RESERVED_197 EQU 0x2f14
+MIOS_RESERVED_198 EQU 0x2f18
+MIOS_RESERVED_199 EQU 0x2f1c
+MIOS_RESERVED_200 EQU 0x2f20
+MIOS_RESERVED_201 EQU 0x2f24
+MIOS_RESERVED_202 EQU 0x2f28
+MIOS_RESERVED_203 EQU 0x2f2c
+MIOS_RESERVED_204 EQU 0x2f30
+MIOS_RESERVED_205 EQU 0x2f34
+MIOS_RESERVED_206 EQU 0x2f38
+MIOS_RESERVED_207 EQU 0x2f3c
+MIOS_RESERVED_208 EQU 0x2f40
+MIOS_RESERVED_209 EQU 0x2f44
+MIOS_RESERVED_210 EQU 0x2f48
+MIOS_RESERVED_211 EQU 0x2f4c
+MIOS_RESERVED_212 EQU 0x2f50
+MIOS_RESERVED_213 EQU 0x2f54
+MIOS_RESERVED_214 EQU 0x2f58
+MIOS_RESERVED_215 EQU 0x2f5c
+MIOS_RESERVED_216 EQU 0x2f60
+MIOS_RESERVED_217 EQU 0x2f64
+MIOS_RESERVED_218 EQU 0x2f68
+MIOS_RESERVED_219 EQU 0x2f6c
+MIOS_RESERVED_220 EQU 0x2f70
+MIOS_RESERVED_221 EQU 0x2f74
+MIOS_RESERVED_222 EQU 0x2f78
+MIOS_RESERVED_223 EQU 0x2f7c
+MIOS_RESERVED_224 EQU 0x2f80
+MIOS_RESERVED_225 EQU 0x2f84
+MIOS_RESERVED_226 EQU 0x2f88
+MIOS_RESERVED_227 EQU 0x2f8c
+MIOS_RESERVED_228 EQU 0x2f90
+MIOS_RESERVED_229 EQU 0x2f94
+MIOS_RESERVED_230 EQU 0x2f98
+MIOS_RESERVED_231 EQU 0x2f9c
+MIOS_RESERVED_232 EQU 0x2fa0
+MIOS_RESERVED_233 EQU 0x2fa4
+MIOS_RESERVED_234 EQU 0x2fa8
+MIOS_RESERVED_235 EQU 0x2fac
+MIOS_RESERVED_236 EQU 0x2fb0
+MIOS_RESERVED_237 EQU 0x2fb4
+MIOS_RESERVED_238 EQU 0x2fb8
+MIOS_RESERVED_239 EQU 0x2fbc
+MIOS_RESERVED_240 EQU 0x2fc0
+MIOS_RESERVED_241 EQU 0x2fc4
+MIOS_RESERVED_242 EQU 0x2fc8
+MIOS_RESERVED_243 EQU 0x2fcc
+MIOS_RESERVED_244 EQU 0x2fd0
+MIOS_RESERVED_245 EQU 0x2fd4
+MIOS_RESERVED_246 EQU 0x2fd8
+MIOS_RESERVED_247 EQU 0x2fdc
+MIOS_RESERVED_248 EQU 0x2fe0
+MIOS_RESERVED_249 EQU 0x2fe4
+MIOS_RESERVED_250 EQU 0x2fe8
+MIOS_RESERVED_251 EQU 0x2fec
+MIOS_RESERVED_252 EQU 0x2ff0
+MIOS_RESERVED_253 EQU 0x2ff4
+MIOS_RESERVED_254 EQU 0x2ff8
+MIOS_RESERVED_255 EQU 0x2ffc
Index: trunk/java/org/midibox/utils/SimpleFileFilter.java
===================================================================
--- trunk/java/org/midibox/utils/SimpleFileFilter.java (revision 0)
+++ trunk/java/org/midibox/utils/SimpleFileFilter.java (revision 628)
@@ -0,0 +1,69 @@
+/*
+ * @(#)SimpleFileFilter.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Vector;
+
+public class SimpleFileFilter implements FileFilter {
+
+ private Vector fileTypes;
+
+ public SimpleFileFilter() {
+ fileTypes = new Vector();
+ }
+
+ public boolean accept(File pathname) {
+
+ if (pathname.isDirectory()) {
+ return true;
+ }
+
+ String extension = getExtension(pathname);
+
+ if (extension != null) {
+ if (fileTypes.contains(extension)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public void addFileType(String extension) {
+ fileTypes.add(extension);
+ }
+
+ private static String getExtension(File f) {
+ String ext = null;
+ if (f != null) {
+ String s = f.getName();
+ int i = s.lastIndexOf('.');
+
+ if (i > 0 && i < s.length() - 1) {
+ ext = s.substring(i + 1).toLowerCase();
+ }
+ }
+ return ext;
+ }
+}
Index: trunk/java/org/midibox/utils/Utils.java
===================================================================
--- trunk/java/org/midibox/utils/Utils.java (revision 0)
+++ trunk/java/org/midibox/utils/Utils.java (revision 628)
@@ -0,0 +1,121 @@
+/*
+ * @(#)Utils.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Jason Williams
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils;
+
+public class Utils {
+ private static char _acHexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
+ '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ public static String byteToHex(byte x) {
+ return "" + _acHexDigits[(x & 0xF0) >> 4] + _acHexDigits[x & 0x0F];
+ }
+
+ public static String intToHex(int n) {
+ return "" + _acHexDigits[(int) (n & 0x0000F000) >> 12]
+ + _acHexDigits[(int) (n & 0x00000F00) >> 8]
+ + _acHexDigits[(int) (n & 0x000000F0) >> 4]
+ + _acHexDigits[(int) (n & 0x0000000F)];
+ }
+
+ public static String longToHex(long l) {
+ return "" + _acHexDigits[(int) (l & 0xF0000000) >> 28]
+ + _acHexDigits[(int) (l & 0x0F000000) >> 24]
+ + _acHexDigits[(int) (l & 0x00F00000) >> 20]
+ + _acHexDigits[(int) (l & 0x000F0000) >> 16]
+ + _acHexDigits[(int) (l & 0x0000F000) >> 12]
+ + _acHexDigits[(int) (l & 0x00000F00) >> 8]
+ + _acHexDigits[(int) (l & 0x000000F0) >> 4]
+ + _acHexDigits[(int) (l & 0x0000000F)];
+ }
+
+ public static String bytesToString(byte[] axData) {
+ String s = new String();
+ for (int n = 0; n < axData.length; n++) {
+ s += byteToHex(axData[n]);
+ }
+ return s;
+ }
+
+ public static byte[] convertTo7Bit(byte[] axData) {
+ // 8-bit to 7-bit conversion:
+ // Each block is effectively treated as a set of bits
+ // which is then divided into 7-bit chunks.
+ // Thus: "FF 00 FF" => "7F 40 1F 70"
+ // "11111111 00000000 11111111" => "-1111111 -1000000 -0011111 -1110000"
+
+ // Calculate required 7-bit bytes to encode 8-bit bytes.
+ int nBytes = (axData.length * 8) / 7;
+ // Round up to nearest byte.
+ if ((axData.length * 8) % 7 != 0) {
+ nBytes++;
+ }
+
+ byte[] axOutData = new byte[nBytes];
+ int nOutDataIndex = 0;
+
+ byte xBitBucket = 0x00;
+ int nBitBucketBits = 0;
+ for (int n = 0; n < axData.length; n++) {
+ byte xData = axData[n];
+ for (int nBitCounter = 0; nBitCounter < 8; nBitCounter++) {
+ // Accumulate bits from 8 bit byte into 7 bit bucket.
+ xBitBucket = (byte) ((xBitBucket << 1) | ((xData & 0x80) == 0x80 ? 0x01
+ : 0x00));
+ xData = (byte) (xData << 1);
+
+ nBitBucketBits++;
+ // If bit bucket full
+ if (nBitBucketBits == 7) {
+ // Output bit bucket.
+ axOutData[nOutDataIndex] = xBitBucket;
+ // Clear bit bucket and counters.
+ xBitBucket = 0x00;
+ nBitBucketBits = 0;
+ nOutDataIndex++;
+ }
+ }
+ }
+
+ // Pad the remaining bit bucket bits and output.
+ if (nBitBucketBits > 0) {
+ while (nBitBucketBits < 7) {
+ xBitBucket = (byte) (xBitBucket << 1);
+ nBitBucketBits++;
+ }
+
+ // Output bit bucket.
+ axOutData[nOutDataIndex] = xBitBucket;
+ }
+
+ return axOutData;
+ }
+
+ public static byte calculateChecksum(byte[] axData1, byte[] axData2) {
+ byte xChecksum = 0x00;
+ for (int n1 = 0; n1 < axData1.length; n1++) {
+ xChecksum = (byte) ((xChecksum + axData1[n1]) & 0xFF);
+ }
+ for (int n2 = 0; n2 < axData2.length; n2++) {
+ xChecksum = (byte) ((xChecksum + axData2[n2]) & 0xFF);
+ }
+ return (byte) ((-xChecksum) & 0x7F);
+ }
+}
Index: trunk/java/org/midibox/utils/ObservableMessageWorker.java
===================================================================
--- trunk/java/org/midibox/utils/ObservableMessageWorker.java (revision 0)
+++ trunk/java/org/midibox/utils/ObservableMessageWorker.java (revision 628)
@@ -0,0 +1,63 @@
+/*
+ * @(#)ObservableMessageWorker.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils;
+
+public class ObservableMessageWorker extends ObservableMessage {
+
+ protected boolean cancelled;
+
+ protected boolean paused;
+
+ protected Thread workerThread;
+
+ public ObservableMessageWorker() {
+ super();
+ }
+
+ public void startWorker() {
+
+ }
+
+ public void stopWorker() {
+
+ }
+
+ public boolean isWorkerRunning() {
+ return false;
+ }
+
+ public void setPaused(boolean paused) {
+ this.paused = paused;
+ }
+
+ public boolean isPaused() {
+ return paused;
+ }
+
+ public void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+}
Index: trunk/java/org/midibox/utils/gui/HexFormatterFactory.java
===================================================================
--- trunk/java/org/midibox/utils/gui/HexFormatterFactory.java (revision 0)
+++ trunk/java/org/midibox/utils/gui/HexFormatterFactory.java (revision 628)
@@ -0,0 +1,30 @@
+/*
+ * @(#)HexFormatterFactory.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils.gui;
+
+import javax.swing.JFormattedTextField.AbstractFormatter;
+import javax.swing.text.DefaultFormatterFactory;
+
+public class HexFormatterFactory extends DefaultFormatterFactory {
+ public AbstractFormatter getDefaultFormatter() {
+ return new HexFormatter();
+ }
+}
\ No newline at end of file
Index: trunk/java/org/midibox/utils/gui/GuiUtils.java
===================================================================
--- trunk/java/org/midibox/utils/gui/GuiUtils.java (revision 627)
+++ trunk/java/org/midibox/utils/gui/GuiUtils.java (revision 628)
@@ -1,7 +1,7 @@
/*
- * @(#)GuiUtils.java beta7 2006/04/23
+ * @(#)GuiUtils.java beta8 2006/04/23
*
- * Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Index: trunk/java/org/midibox/utils/gui/SliderWheelUI.java
===================================================================
--- trunk/java/org/midibox/utils/gui/SliderWheelUI.java (revision 0)
+++ trunk/java/org/midibox/utils/gui/SliderWheelUI.java (revision 628)
@@ -0,0 +1,91 @@
+/*
+ * @(#)SliderWheelUI.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils.gui;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.plaf.basic.BasicSliderUI;
+
+public class SliderWheelUI extends BasicSliderUI {
+
+ private ImageIcon vertThumbIcon2;
+
+ private ImageIcon horizThumbIcon2;
+
+ private int thumbHeight;
+
+ public SliderWheelUI(ImageIcon horizThumbIcon2, ImageIcon vertThumbIcon2,
+ int thumbHeight) {
+ super(null);
+ this.horizThumbIcon2 = horizThumbIcon2;
+ this.vertThumbIcon2 = vertThumbIcon2;
+ this.thumbHeight = thumbHeight;
+ }
+
+ public void setThumbLocation(int x, int y) {
+ thumbRect.setLocation(x, y);
+ slider.repaint();
+ }
+
+ public void paint(Graphics g, JComponent c) {
+
+ if (c.hasFocus()) {
+ paintFocus(g);
+ }
+ paintThumb(g);
+ }
+
+ public void paintThumb(Graphics g) {
+
+ ImageIcon icon;
+
+ if (slider.getOrientation() == slider.VERTICAL) {
+ icon = vertThumbIcon2;
+ } else {
+ icon = horizThumbIcon2;
+ }
+
+ int noImages = (icon.getIconWidth() / icon.getIconHeight()) - 1;
+ int pos1 = (int) ((((icon.getIconHeight()) - slider.getWidth()) / 2));
+ int pos2 = (int) (((float) (slider.getValue()) / ((float) slider
+ .getMaximum())) * noImages)
+ * icon.getIconHeight();
+
+ icon.paintIcon(slider, g, -pos1 - pos2, (slider.getHeight() - icon
+ .getIconHeight()) / 2);
+ g.dispose();
+ }
+
+ public void paintTrack(Graphics g) {
+ return;
+ }
+
+ public Dimension getThumbSize() {
+ if (slider.getOrientation() == slider.VERTICAL) {
+ return new Dimension(vertThumbIcon2.getIconHeight(), thumbHeight);
+ } else {
+ return new Dimension(thumbHeight, horizThumbIcon2.getIconHeight());
+ }
+ }
+}
Index: trunk/java/org/midibox/utils/gui/HexFormatter.java
===================================================================
--- trunk/java/org/midibox/utils/gui/HexFormatter.java (revision 0)
+++ trunk/java/org/midibox/utils/gui/HexFormatter.java (revision 628)
@@ -0,0 +1,39 @@
+/*
+ * @(#)HexFormatter.java beta8 2006/04/23
+ *
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
+ *
+ * This application is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this application; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.midibox.utils.gui;
+
+import java.text.ParseException;
+
+import javax.swing.text.DefaultFormatter;
+
+class HexFormatter extends DefaultFormatter {
+ public Object stringToValue(String text) throws ParseException {
+ try {
+ return Integer.valueOf(text, 16);
+ } catch (NumberFormatException nfe) {
+ throw new ParseException(text, 0);
+ }
+ }
+
+ public String valueToString(Object value) throws ParseException {
+ return Integer.toHexString(((Integer) value).intValue()).toUpperCase();
+ }
+}
\ No newline at end of file
Index: trunk/java/org/midibox/utils/gui/ImageLoader.java
===================================================================
--- trunk/java/org/midibox/utils/gui/ImageLoader.java (revision 627)
+++ trunk/java/org/midibox/utils/gui/ImageLoader.java (revision 628)
@@ -1,7 +1,7 @@
/*
- * @(#)ImageLoader.java beta7 2006/04/23
+ * @(#)ImageLoader.java beta8 2006/04/23
*
- * Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
+ * Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
import java.util.Hashtable;
import javax.swing.ImageIcon;
-import java.io.File;
+
public class ImageLoader {
private static Hashtable images = new Hashtable();
@@ -36,9 +36,9 @@
if (images.containsKey(imageName)) {
imageIcon = (ImageIcon) images.get(imageName);
} else {
- //ClassLoader cl = ImageLoader.class.getClassLoader();
- //URL url = cl.getResource("images/" + imageName);
- URL url = ImageLoader.class.getResource("/images/" + imageName);
+
+ ClassLoader cl = ImageLoader.class.getClassLoader();
+ URL url = cl.getResource("images/" + imageName);
imageIcon = new ImageIcon(url);
images.put(imageName, imageIcon);
}
/trunk/java/org/midibox/utils/gui/DialogOwner.java
New file
0,0 → 1,27
package org.midibox.utils.gui;
 
import javax.swing.JDialog;
import javax.swing.JFrame;
 
public class DialogOwner {
 
private static JFrame frame;
 
private static JDialog dialog;
 
public static JFrame getFrame() {
return frame;
}
 
public static void setFrame(JFrame frame) {
DialogOwner.frame = frame;
}
 
public static JDialog getDialog() {
return dialog;
}
 
public static void setDialog(JDialog dialog) {
DialogOwner.dialog = dialog;
}
}
/trunk/java/org/midibox/utils/gui/MyButtonUI.java
1,7 → 1,7
/*
* @(#)MyButtonUI.java beta7 2006/04/23
* @(#)MyButtonUI.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/trunk/java/org/midibox/utils/gui/SeqButtonUI.java
57,14 → 57,26
ButtonModel model = b.getModel();
c.setBorder(null);
c.setOpaque(false);
switch(realValue) {
case 0:icon0.paintIcon(c, g, (c.getWidth() - icon0.getIconWidth()) / 2, (c.getHeight() - icon0.getIconHeight()) / 2);break;
case 1:icon1.paintIcon(c, g, (c.getWidth() - icon1.getIconWidth()) / 2, (c.getHeight() - icon1.getIconHeight()) / 2);break;
case 2:icon2.paintIcon(c, g, (c.getWidth() - icon2.getIconWidth()) / 2, (c.getHeight() - icon2.getIconHeight()) / 2);break;
case 3:icon3.paintIcon(c, g, (c.getWidth() - icon3.getIconWidth()) / 2, (c.getHeight() - icon3.getIconHeight()) / 2);break;
}
 
switch (realValue) {
case 0:
icon0.paintIcon(c, g, (c.getWidth() - icon0.getIconWidth()) / 2, (c
.getHeight() - icon0.getIconHeight()) / 2);
break;
case 1:
icon1.paintIcon(c, g, (c.getWidth() - icon1.getIconWidth()) / 2, (c
.getHeight() - icon1.getIconHeight()) / 2);
break;
case 2:
icon2.paintIcon(c, g, (c.getWidth() - icon2.getIconWidth()) / 2, (c
.getHeight() - icon2.getIconHeight()) / 2);
break;
case 3:
icon3.paintIcon(c, g, (c.getWidth() - icon3.getIconWidth()) / 2, (c
.getHeight() - icon3.getIconHeight()) / 2);
break;
}
 
if (b.hasFocus()) {
paintFocus(g, b);
}
72,7 → 84,7
}
 
public void setValue(int i) {
realValue = i;
realValue = i;
}
 
protected void paintFocus(Graphics g, AbstractButton c) {
/trunk/java/org/midibox/utils/gui/SimpleFileChooserFilter.java
New file
0,0 → 1,119
/*
* @(#)SimpleFileChooserFilter.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.utils.gui;
 
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
 
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
 
public class SimpleFileChooserFilter extends FileFilter {
 
private Hashtable fileTypes;
 
private String filterDescription;
 
public SimpleFileChooserFilter(String filterDescription) {
this.filterDescription = filterDescription;
fileTypes = new Hashtable();
}
 
public SimpleFileChooserFilter(String filterDescription, String extension,
String description) {
this.filterDescription = filterDescription;
fileTypes = new Hashtable();
addFileType(extension, description);
}
 
public void addFileType(String extension, String description) {
fileTypes.put(extension, description);
}
 
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
 
String extension = getExtension(f);
 
if (extension != null) {
if (fileTypes.containsKey(extension)) {
return true;
} else {
return false;
}
}
return false;
}
 
public String getDescription() {
 
String description = filterDescription + " (";
 
Enumeration e = fileTypes.keys();
 
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
description += ("*." + key + ((e.hasMoreElements()) ? ", " : ")"));
}
 
return description;
}
 
public void setFilterForChooser(JFileChooser fileChooser) {
 
Enumeration e = fileTypes.keys();
 
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = (String) fileTypes.get(key);
fileChooser.addChoosableFileFilter(new SimpleFileChooserFilter(
value, key, value));
}
 
fileChooser.addChoosableFileFilter(this);
}
 
public String getTypeDescription(File f) {
String extension = getExtension(f);
String type = null;
 
if (extension != null) {
type = (String) fileTypes.get(extension);
}
return type;
}
 
private static String getExtension(File f) {
String ext = null;
if (f != null) {
String s = f.getName();
int i = s.lastIndexOf('.');
 
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
}
return ext;
}
}
/trunk/java/org/midibox/utils/gui/Blinker.java
New file
0,0 → 1,71
/*
* @(#)Blinker.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
package org.midibox.utils.gui;
 
import java.util.Observable;
 
public class Blinker extends Observable implements Runnable {
 
private int delay;
 
private boolean pulse = false;
 
private transient Thread runner = null;
 
private boolean cancelled = false;
 
public Blinker(int frameRate) {
delay = 1000 / frameRate;
reset();
}
 
private void reset() {
runner = new Thread(this);
runner.start();
}
 
public void run() {
 
long tm = System.currentTimeMillis();
 
while (!cancelled) {
try {
 
pulse = !pulse;
 
setChanged();
notifyObservers();
clearChanged();
 
Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
tm += delay;
} catch (InterruptedException e) {
break;
}
}
return;
}
 
public void cancel() {
cancelled = true;
}
}
/trunk/java/org/midibox/utils/gui/SplitButton.java
1,42 → 1,42
package org.midibox.utils.gui;
 
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import java.awt.Component;
import java.awt.Insets;
 
public class SplitButton extends JToolBar implements ActionListener {
private JButton button, splitButton;
private JPopupMenu dropMenu;
public SplitButton(JButton button,JPopupMenu dropMenu) {
 
public SplitButton(JButton button, JPopupMenu dropMenu) {
this.button = button;
this.dropMenu = dropMenu;
this.dropMenu = dropMenu;
setFloatable(false);
this.setBorderPainted(false);
this.setBorderPainted(false);
ImageIcon icon = ImageLoader.getImageIcon("pulldown.png");
splitButton = new JButton();
splitButton.setIcon(icon);
splitButton.addActionListener(this);
splitButton.addActionListener(this);
splitButton.setFocusPainted(false);
splitButton.setPreferredSize(new Dimension(icon.getIconWidth(), splitButton.getPreferredSize().height));
splitButton.setMargin(new Insets(2,0,2,0));
setMargin(new Insets(-1,-2,-3,-2));
splitButton.setPreferredSize(new Dimension(icon.getIconWidth(),
splitButton.getPreferredSize().height));
splitButton.setMargin(new Insets(2, 0, 2, 0));
setMargin(new Insets(-1, -2, -3, -2));
add(button);
add(splitButton);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==splitButton) {
Component c = (Component)button;
dropMenu.show(c, 0, c.getHeight());
 
public void actionPerformed(ActionEvent e) {
if (e.getSource() == splitButton) {
Component c = (Component) button;
dropMenu.show(c, 0, c.getHeight());
}
}
}
}
 
 
/trunk/java/org/midibox/utils/gui/Knob.java
1,7 → 1,7
/*
* @(#)Knob.java beta7 2006/04/23
* @(#)Knob.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
110,7 → 110,7
PREF_SIZE = new Dimension(icon.getIconHeight() + 8, icon
.getIconHeight() + 8);
DRAG_SPEED = 0.0075F;// 0.01F;
CLICK_SPEED = 0.004F;
CLICK_SPEED = 0.01F;
 
hitArc.setAngleStart(235); // Degrees ??? Radians???
hitArc.setFrame(4, 4, icon.getIconHeight(), icon.getIconHeight());
/trunk/java/org/midibox/utils/gui/JVertLabel.java
20,25 → 20,26
 
package org.midibox.utils.gui;
 
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
 
import javax.swing.JLabel;
 
public class JVertLabel extends JLabel {
private String s;
public JVertLabel( String str )
{
super( str );
this.s = str;
setPreferredSize( new Dimension( 40, 110 ) );
setMinimumSize( new Dimension( 40, 110 ) );
}
 
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.translate(10.0, 50.0);
g2d.rotate( 300 );
g2d.drawString(s, -50, 10);
}
public JVertLabel(String str) {
super(str);
this.s = str;
setPreferredSize(new Dimension(40, 110));
setMinimumSize(new Dimension(40, 110));
}
 
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(10.0, 50.0);
g2d.rotate(300);
g2d.drawString(s, -50, 10);
}
}
/trunk/java/org/midibox/utils/gui/SplashScreen.java
New file
0,0 → 1,80
/*
* @(#)SplashScreen.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.utils.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
 
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JWindow;
 
public class SplashScreen extends JWindow {
 
protected String title;
 
public SplashScreen(String filename, String title) {
 
this.title = title;
 
ImageIcon image = ImageLoader.getImageIcon(filename);
setSize(image.getIconWidth(), image.getIconHeight());
 
getContentPane().add(new JLabel(image) {
 
public void paintComponent(Graphics g) {
 
super.paintComponent(g);
 
Graphics2D g2d = (Graphics2D) g;
 
g2d.setFont(new Font("Monospaced", Font.BOLD, 20));
 
FontMetrics fm = g2d.getFontMetrics();
 
int width = fm.stringWidth(getTitle());
 
int height = fm.getHeight();
 
int x = (getWidth() - width) / 2;
 
int y = 60;
 
g2d.setColor(Color.GREEN);
 
g2d.fillRect(x - 5, y - height + 5, width + 10, height + 5);
 
g2d.setColor(Color.BLACK);
 
g2d.drawString(getTitle(), x, y);
}
}, BorderLayout.CENTER);
}
 
protected String getTitle() {
 
return title;
}
}
/trunk/java/org/midibox/utils/gui/HelpPane.java
New file
0,0 → 1,200
/*
* @(#)HelpPane.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.utils.gui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.net.URL;
import java.util.Vector;
 
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
 
public class HelpPane extends JPanel implements ActionListener,
HyperlinkListener {
private JEditorPane JEP = new JEditorPane();
 
private PropertyChangeSupport listeners = new PropertyChangeSupport(this);
 
private JToolBar toolbar;
 
private URL homePage;
 
private JButton home;
 
private JButton back;
 
private JButton forward;
 
private Vector history = new Vector();
 
private int historyIndex = 0;
 
private static HelpPane singleton;
 
public HelpPane(URL homePage) {
super(new BorderLayout());
this.homePage = homePage;
add(makeHelpPanel(), BorderLayout.CENTER);
add(makeToolBar(), BorderLayout.NORTH);
if (homePage != null) {
goToURL(homePage);
}
updateButtons();
}
 
private JPanel makeHelpPanel() {
JPanel helpPane = new JPanel(new BorderLayout());
JEP.setEditable(false);
JEP.setContentType("text/html");
JEP.addHyperlinkListener(this);
JScrollPane scrollPane = new JScrollPane(JEP);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
helpPane.add(scrollPane);
return helpPane;
}
 
private JToolBar makeToolBar() {
 
toolbar = new JToolBar("Tool Bar", JToolBar.HORIZONTAL);
toolbar.setFloatable(false);
toolbar.setRollover(true);
 
Insets margin = new Insets(2, 2, 2, 2);
 
back = new JButton(ImageLoader.getImageIcon("back.png"));
back.addActionListener(this);
back.setMargin(margin);
back.setToolTipText("Back");
toolbar.add(back);
 
forward = new JButton(ImageLoader.getImageIcon("forward.png"));
forward.addActionListener(this);
forward.setMargin(margin);
forward.setToolTipText("Forward");
toolbar.add(forward);
 
home = new JButton(ImageLoader.getImageIcon("home.png"));
home.addActionListener(this);
home.setMargin(margin);
home.setToolTipText("Home");
toolbar.add(home);
 
return toolbar;
}
 
public void goToURL(URL url) {
try {
JEP.setPage(url);
listeners.firePropertyChange("page_changed", null, Boolean.TRUE);
 
for (int i = history.size() - 1; i > historyIndex; i--) {
history.remove(i);
}
 
history.add(url);
historyIndex = history.size() - 1;
updateButtons();
} catch (Exception err) {
JOptionPane.showMessageDialog(this, "Invalid Link: '" + url + "'",
"Invalid Link: '" + url + "'", JOptionPane.ERROR_MESSAGE);
}
}
 
public void goToHistory(int index) {
URL url = (URL) history.elementAt(index);
try {
JEP.setPage(url);
listeners.firePropertyChange("page_changed", null, Boolean.TRUE);
historyIndex = index;
updateButtons();
} catch (Exception err) {
JOptionPane.showMessageDialog(this, "Invalid Link: '" + url + "'",
"Invalid Link: '" + url + "'", JOptionPane.ERROR_MESSAGE);
}
}
 
private void updateButtons() {
back.setEnabled(historyIndex > 0);
forward.setEnabled(historyIndex < history.size() - 1);
}
 
public void hyperlinkUpdate(HyperlinkEvent hle) {
if (hle.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
goToURL(hle.getURL());
}
}
 
public Dimension getPreferredSize() {
return new Dimension(400, 300);
}
 
public URL getCurrentURL() {
return JEP.getPage();
}
 
public void addPropertyChangeListener(PropertyChangeListener l) {
if (listeners != null) {
listeners.addPropertyChangeListener(l);
}
}
 
public void removePropertyChangeListener(PropertyChangeListener l) {
listeners.removePropertyChangeListener(l);
}
 
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
 
if (source == back) {
goToHistory(historyIndex - 1);
}
 
if (source == forward) {
goToHistory(historyIndex + 1);
}
 
if (source == home) {
goToURL(homePage);
}
}
 
public static HelpPane createSingleton(URL url) {
if (singleton == null) {
singleton = new HelpPane(url);
}
return singleton;
}
}
/trunk/java/org/midibox/utils/gui/SimpleTransferHandler.java
New file
0,0 → 1,76
/*
* @(#)SimpleTransferHandler.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.utils.gui;
 
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
 
import javax.swing.JComponent;
import javax.swing.TransferHandler;
 
public class SimpleTransferHandler extends TransferHandler {
 
protected DataFlavor[] supportedDataFlavors;
 
protected boolean justImported = false;
 
protected boolean justExported = false;
 
protected boolean dropOnSelf = false;
 
public int getSourceActions(JComponent c) {
return COPY;
}
 
public boolean canImport(JComponent c, DataFlavor[] flavors) {
try {
if (justExported && !dropOnSelf) {
return false;
} else {
for (int f = 0; f < flavors.length; f++) {
if (hasFlavor(supportedDataFlavors, flavors[f])) {
return true;
}
}
return false;
}
} catch (Exception e) {
return false;
}
}
 
public void setDropOnSelf(boolean dropOnSelf) {
this.dropOnSelf = dropOnSelf;
}
 
protected boolean hasFlavor(DataFlavor[] flavors, DataFlavor flavor) {
for (int i = 0; i < flavors.length; i++) {
if (flavor.equals(flavors[i])) {
return true;
}
}
return false;
}
 
protected void exportDone(JComponent c, Transferable data, int action) {
justExported = false;
}
}
/trunk/java/org/midibox/utils/gui/FontLoader.java
1,7 → 1,7
/*
* @(#)FontLoader.java beta7 2006/04/23
* @(#)FontLoader.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
21,7 → 21,6
package org.midibox.utils.gui;
 
import java.awt.Font;
import java.net.URL;
import java.util.Hashtable;
 
public class FontLoader {
35,17 → 34,12
if (fonts.containsKey(fontName + fontSize)) {
font = (Font) fonts.get(fontName + fontSize);
} else {
//ClassLoader cl = ImageLoader.class.getClassLoader();
try {
/*
ClassLoader cl = ImageLoader.class.getClassLoader();
 
try {
font = Font.createFont(Font.TRUETYPE_FONT,
cl.getResourceAsStream("fonts/" + fontName))
.deriveFont(fontSize);
*/
font = Font.createFont(Font.TRUETYPE_FONT,
FontLoader.class.getResourceAsStream("/fonts/" + fontName))
.deriveFont(fontSize);
fonts.put(fontName + fontSize, font);
} catch (Exception e) {
font = null;
/trunk/java/org/midibox/utils/ObservableMessage.java
1,7 → 1,7
/*
* @(#)ObservableMessage.java beta7 2006/04/23
* @(#)ObservableMessage.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/trunk/java/org/midibox/utils/ResourceLoader.java
New file
0,0 → 1,43
/*
* @(#)ResourceLoader.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.utils;
 
import java.io.InputStream;
import java.net.URL;
 
public class ResourceLoader {
 
public static URL getResource(String resourceName) {
 
ClassLoader cl = ResourceLoader.class.getClassLoader();
URL url = cl.getResource(resourceName);
 
return url;
}
 
public static InputStream getResourceAsStream(String resourceName) {
 
ClassLoader cl = ResourceLoader.class.getClassLoader();
InputStream inputStream = cl.getResourceAsStream(resourceName);
 
return inputStream;
}
}
/trunk/java/org/midibox/midi/MidiParameterControlManagerDevice.java
New file
0,0 → 1,42
/*
* @(#)MidiParameterControlManagerDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiParameterControlManagerDevice extends VirtualMidiDevice {
 
protected MidiParameterControlManager midiParameterContainer;
 
public MidiParameterControlManagerDevice(String name, int globalChannel) {
super(name, -1, -1);
this.midiParameterContainer = new MidiParameterControlManager(
midiOutPort, globalChannel);
}
 
public MidiParameterControlManager getMidiParameterContainer() {
return midiParameterContainer;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiParameterContainer.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiActivity.java
New file
0,0 → 1,47
/*
* @(#)MidiActivity.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
 
public class MidiActivity extends Observable implements Receiver {
 
private long time;
 
public MidiActivity() {
time = System.currentTimeMillis();
}
 
public void send(MidiMessage message, long timestamp) {
time = System.currentTimeMillis();
}
 
public void close() {
 
}
 
public long getTime() {
return time;
}
}
/trunk/java/org/midibox/midi/MidiMapDevice.java
New file
0,0 → 1,41
/*
* @(#)MidiMapDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiMapDevice extends VirtualMidiDevice {
 
protected MidiMap midiMap;
 
public MidiMapDevice(String name) {
super(name, -1, -1);
this.midiMap = new MidiMap(midiOutPort);
}
 
public MidiMap getMidiMap() {
return midiMap;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiMap.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/SysexSendReceiveDeviceManager.java
New file
0,0 → 1,60
/*
* @(#)SysexSendReceiveDeviceManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
import java.util.Vector;
 
public class SysexSendReceiveDeviceManager extends Observable {
 
private Vector sysexSendReceiveDevices;
 
private int sysexSendReceiveDeviceNo;
 
public SysexSendReceiveDeviceManager() {
sysexSendReceiveDevices = new Vector();
}
 
public SysexSendReceiveDevice newSysexSendReceive() {
SysexSendReceiveDevice sysexSendReceiveDevice = new SysexSendReceiveDevice(
"Sysex Send/Receive " + ++sysexSendReceiveDeviceNo);
sysexSendReceiveDevices.add(sysexSendReceiveDevice);
 
setChanged();
notifyObservers(sysexSendReceiveDevice);
clearChanged();
 
return sysexSendReceiveDevice;
}
 
public void removeSysexSendReceiveDevice(
SysexSendReceiveDevice sysexSendReceiveDevice) {
sysexSendReceiveDevices.remove(sysexSendReceiveDevice);
 
setChanged();
notifyObservers(sysexSendReceiveDevice);
clearChanged();
}
 
public Vector getSysexSendReceiveDevices() {
return sysexSendReceiveDevices;
}
}
/trunk/java/org/midibox/midi/MidiUtils.java
1,7 → 1,7
/*
* @(#)MidiUtils.java beta7 2006/04/23
* @(#)MidiUtils.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
24,9 → 24,131
 
public class MidiUtils {
 
public static String[] ccNames = { "Bank Select", "Modulation Wheel",
"Breath Controller", "Undefined", "Foot Controller",
"Portamento Time", "Data Entry", "Volume", "Balance", "Undefined",
"Pan", "Expression Controller", "Effect Control 1",
"Effect Control 2", "Undefined", "Undefined", "GP Controller 1",
"GP Controller 2", "GP Controller 3", "GP Controller 4",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "LSB 0 (Bank Select)",
"LSB 1 (Modulation Wheel)", "LSB 2 (Breath Controller)",
"LSB 3 (Undefined)", "LSB 4 (Foot Controller)",
"LSB 5 (Portamento Time)", "LSB 6 (Data Entry)",
"LSB 7 (Channel Volume)", "LSB 8 (Balance)", "LSB 9 (Undefined)",
"LSB 10 (Pan)", "LSB 11 (Expression Controller)",
"LSB 12 (Effect 1)", "LSB 13 (Effect 2)", "LSB 14 (Undefined)",
"LSB 15 (Undefined)", "LSB 16 (GP ler 1)", "LSB 17 (GP ler 2)",
"LSB 18 (GP ler 3)", "LSB 19 (GP ler 4)", "LSB 20 (Undefined)",
"LSB 21 (Undefined)", "LSB 22 (Undefined)", "LSB 23 (Undefined)",
"LSB 24 (Undefined)", "LSB 25 (Undefined)", "LSB 26 (Undefined)",
"LSB 27 (Undefined)", "LSB 28 (Undefined)", "LSB 29 (Undefined)",
"LSB 30 (Undefined)", "LSB 31 (Undefined)",
"Damper Pedal On/Off (Sustain)", "Portamento On/Off",
"Sustenuto On/Off", "Soft Pedal On/Off", "Legato Footswitch",
"Hold 2", "Sound Controller 1", "Sound Controller 2",
"Sound Controller 3", "Sound Controller 4", "Sound Controller 5",
"Sound Controller 6", "Sound Controller 7", "Sound Controller 8",
"Sound Controller 9", "Sound Controller 10", "GP Controller 5",
"GP Controller 6", "GP Controller 7", "GP Controller 8",
"Portamento Control", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Effects 1 Depth",
"Effects 2 Depth", "Effects 3 Depth", "Effects 4 Depth",
"Effects 5 Depth", "Data Increment", "Data Decrement",
"Non-Reg. Param. No. - LSB", "Non-Reg. Param. No. - MSB",
"Reg. Param. No. - LSB", "Reg. Param. No. - MSB", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "All Sound Off", "Reset All Controllers",
"Local Control On/Off", "All Notes Off", "Omni Mode Off",
"Omni Mode On", "Poly Mode On/Off", "Poly Mode On" };
 
public static String[] cc14BitNames = { "Bank Select (14 bit)",
"Modulation Wheel (14 bit)", "Breath Controller (14 bit)",
"Undefined (14 bit)", "Foot Controller (14 bit)",
"Portamento Time (14 bit)", "Data Entry MSB (14 bit)",
"Volume (14 bit)", "Balance (14 bit)", "Undefined (14 bit)",
"Pan (14 bit)", "Expression Controller (14 bit)",
"Effect Control 1 (14 bit)", "Effect Control 2 (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)",
"GP Controller 1 (14 bit)", "GP Controller 2 (14 bit)",
"GP Controller 3 (14 bit)", "GP Controller 4 (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Bank Select (14 bit)", "Modulation Wheel (14 bit)",
"Breath Controller (14 bit)", "Undefined (14 bit)",
"Foot Controller (14 bit)", "Portamento Time (14 bit)",
"Data Entry MSB (14 bit)", "Volume (14 bit)", "Balance (14 bit)",
"Undefined (14 bit)", "Pan (14 bit)",
"Expression Controller (14 bit)", "Effect Control 1 (14 bit)",
"Effect Control 2 (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "GP Controller 1 (14 bit)",
"GP Controller 2 (14 bit)", "GP Controller 3 (14 bit)",
"GP Controller 4 (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
"Undefined (14 bit)", "Undefined (14 bit)",
"Damper Pedal On/Off (Sustain)", "Portamento On/Off",
"Sustenuto On/Off", "Soft Pedal On/Off", "Legato Footswitch",
"Hold 2", "Sound Controller 1", "Sound Controller 2",
"Sound Controller 3", "Sound Controller 4", "Sound Controller 5",
"Sound Controller 6", "Sound Controller 7", "Sound Controller 8",
"Sound Controller 9", "Sound Controller 10", "GP Controller 5",
"GP Controller 6", "GP Controller 7", "GP Controller 8",
"Portamento Control", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Effects 1 Depth",
"Effects 2 Depth", "Effects 3 Depth", "Effects 4 Depth",
"Effects 5 Depth", "Data Increment", "Data Decrement",
"Non-Reg. Param. No. (14 bit)", "Non-Reg. Param. No. (14 bit)",
"Reg. Param. No. (14 bit)", "Reg. Param. No. (14 bit)",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
"Undefined", "Undefined", "Undefined", "All Sound Off",
"Reset All Controllers", "Local Control On/Off", "All Notes Off",
"Omni Mode Off", "Omni Mode On", "Poly Mode On/Off", "Poly Mode On" };
 
public static final String[] s_astrKeyNames = { "C", "C#", "D", "D#", "E",
"F", "F#", "G", "G#", "A", "A#", "B" };
 
public static final String[] s_astrKeySignatures = { "Cb", "Gb", "Db",
"Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#" };
 
public static final String[] SYSTEM_MESSAGE_TEXT = {
"System Exclusive (should not be in ShortMessage!)",
"MTC Quarter Frame: ", "Song Position: ", "Song Select: ",
"Undefined", "Undefined", "Tune Request",
"End of SysEx (should not be in ShortMessage!)", "Timing clock",
"Undefined", "Start", "Continue", "Stop", "Undefined",
"Active Sensing", "System Reset" };
 
public static final String[] QUARTER_FRAME_MESSAGE_TEXT = {
"frame count LS: ", "frame count MS: ", "seconds count LS: ",
"seconds count MS: ", "minutes count LS: ", "minutes count MS: ",
"hours count LS: ", "hours count MS: " };
 
public static final String[] FRAME_TYPE_TEXT = { "24 frames/second",
"25 frames/second", "30 frames/second (drop)",
"30 frames/second (non-drop)", };
 
public static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
 
public static String getKeyName(int nKeyNumber) {
if (nKeyNumber > 127) {
return "illegal value";
} else {
int nNote = nKeyNumber % 12;
int nOctave = nKeyNumber / 12;
return s_astrKeyNames[nNote] + (nOctave - 1);
}
}
 
public static int get14bitValue(int nLowerPart, int nHigherPart) {
return (nLowerPart & 0x7F) | ((nHigherPart & 0x7F) << 7);
}
35,6 → 157,15
return b & 0xFF;
}
 
// convert from microseconds per quarter note to beats per minute and vice
// versa
public static float convertTempo(float value) {
if (value <= 0) {
value = 0.1f;
}
return 60000000.0f / value;
}
 
public static String getHexString(byte[] aByte) {
StringBuffer sbuf = new StringBuffer(aByte.length * 3 + 2);
for (int i = 0; i < aByte.length; i++) {
86,7 → 217,7
switch (status) {
case 0xF6: // Tune Request
case 0xF7: // EOX
// System real-time messages
// System real-time messages
case 0xF8: // Timing Clock
case 0xF9: // Undefined
case 0xFA: // Start
/trunk/java/org/midibox/midi/MidiRouterDevice.java
New file
0,0 → 1,34
/*
* @(#)MidiRouterDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiRouterDevice extends VirtualMidiDevice {
 
public MidiRouterDevice(String name) {
super(name, -1, -1);
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
sendToTransmitters(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiFilterDeviceManager.java
New file
0,0 → 1,59
/*
* @(#)MidiFilterDeviceManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
import java.util.Vector;
 
public class MidiFilterDeviceManager extends Observable {
 
private Vector midiFilterDevices;
 
private int midiFilterDeviceNo;
 
public MidiFilterDeviceManager() {
midiFilterDevices = new Vector();
}
 
public MidiFilterDevice addMidiFilterDevice() {
MidiFilterDevice midiFilterDevice = new MidiFilterDevice("Filter "
+ ++midiFilterDeviceNo);
midiFilterDevices.add(midiFilterDevice);
 
setChanged();
notifyObservers(midiFilterDevice);
clearChanged();
 
return midiFilterDevice;
}
 
public void removeMidiFilterDevice(MidiFilterDevice midiFilterDevice) {
midiFilterDevices.remove(midiFilterDevice);
 
setChanged();
notifyObservers(midiFilterDevice);
clearChanged();
}
 
public Vector getMidiFilterDevices() {
return midiFilterDevices;
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterProperties.java
New file
0,0 → 1,338
/*
* @(#)MidiParameterProperties.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JToggleButton;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
 
import org.midibox.midi.MidiParameter;
import org.midibox.midi.MidiParameterControl;
import org.midibox.midi.MidiUtils;
 
public class MidiParameterProperties extends JPanel implements Observer,
ActionListener, ListSelectionListener, ChangeListener {
 
protected MidiParameter midiParameter;
 
protected JToggleButton midiLearn;
 
protected JSpinner channelSpinner;
 
protected JComboBox statusComboBox;
 
protected JList nameList;
 
protected JScrollPane nameScrollPane;
 
protected JLabel defaultValueLabel;
 
protected JSpinner defaultValueSpinner;
 
protected JCheckBox highResolution;
 
protected JPanel statusPanel;
 
protected JPanel midiLearnPanel;
 
protected JPanel channelPanel;
 
protected JPanel defaultPanel;
 
protected JPanel mainPanel;
 
protected JPanel numberPanel;
 
protected boolean update = true;
 
public MidiParameterProperties(MidiParameter midiParameter) {
super(new BorderLayout());
this.midiParameter = midiParameter;
midiParameter.addObserver(this);
 
add(createMainPanel(), BorderLayout.CENTER);
 
midiLearnPanel = new JPanel(new BorderLayout());
 
midiLearn = new JToggleButton("MIDI Learn");
midiLearn.addActionListener(this);
 
midiLearnPanel.add(midiLearn);
midiLearnPanel
.setBorder(BorderFactory.createTitledBorder("MIDI Learn"));
 
add(midiLearnPanel, BorderLayout.NORTH);
 
updateControls();
}
 
protected JPanel createMainPanel() {
 
statusPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0;
 
statusComboBox = new JComboBox(new String[] { "Note Off/On",
"Aftertouch", "Control Change", "Program Change",
"Channel Pressure", "Pitch Bend" });
statusComboBox.addActionListener(this);
 
statusPanel.add(statusComboBox, gbc);
gbc.gridy++;
statusPanel.setBorder(BorderFactory.createTitledBorder("Status"));
 
highResolution = new JCheckBox("14 bit");
highResolution.addActionListener(this);
statusPanel.add(highResolution, gbc);
 
channelPanel = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0;
 
channelSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 16, 1));
channelSpinner.addChangeListener(this);
channelPanel.add(channelSpinner, gbc);
 
channelPanel.setBorder(BorderFactory.createTitledBorder("Channel"));
 
defaultPanel = new JPanel();
 
defaultValueLabel = new JLabel("Channel Pressure Value: ", JLabel.LEFT);
defaultPanel.add(defaultValueLabel);
 
defaultValueSpinner = new JSpinner(new SpinnerNumberModel(0, 0,
midiParameter.getMidiMaxValue(), 1));
defaultValueSpinner.addChangeListener(this);
defaultPanel.add(defaultValueSpinner);
 
defaultPanel.setBorder(BorderFactory
.createTitledBorder("Default \"On\" Value"));
 
numberPanel = new JPanel(new BorderLayout(0, 4));
 
nameList = new JList();
nameList.addListSelectionListener(this);
nameList.setVisibleRowCount(4);
nameScrollPane = new JScrollPane(nameList);
nameScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
numberPanel.add(nameScrollPane);
 
numberPanel.setBorder(BorderFactory.createTitledBorder("Number"));
 
mainPanel = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.weightx = 1.0;
 
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
 
mainPanel.add(statusPanel, gbc);
gbc.gridx++;
 
mainPanel.add(channelPanel, gbc);
 
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 2;
 
mainPanel.add(defaultPanel, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
 
mainPanel.add(numberPanel, gbc);
 
return mainPanel;
}
 
public void updateControls() {
 
boolean isLearn = midiParameter.isLearn();
 
midiLearn.setSelected(isLearn);
 
int status = midiParameter.getMidiStatus();
 
statusComboBox
.setSelectedIndex((midiParameter.getMidiStatus() >> 4) - 9);
statusComboBox.setEnabled(!isLearn);
 
String[] listData = new String[128];
 
for (int i = 0; i < listData.length; i++) {
listData[i] = i + ": " + MidiUtils.getKeyName(i);
}
 
if (status == MidiParameter.NOTE_ON) {
nameList.setEnabled(true && !isLearn);
nameScrollPane.setEnabled(true);
 
} else if (status == MidiParameter.AFTERTOUCH) {
nameList.setEnabled(true && !isLearn);
nameScrollPane.setEnabled(true && !isLearn);
 
} else if (status == MidiParameter.CONTROL_CHANGE) {
nameList.setEnabled(true && !isLearn);
nameScrollPane.setEnabled(true && !isLearn);
 
if (midiParameter.isHighResolution()) {
for (int i = 0; i < listData.length; i++) {
listData[i] = i + ": " + MidiUtils.cc14BitNames[i];
}
} else {
for (int i = 0; i < listData.length; i++) {
listData[i] = i + ": " + MidiUtils.ccNames[i];
}
}
} else if (status == MidiParameter.PROGRAM_CHANGE) {
nameList.setEnabled(false);
nameScrollPane.setEnabled(false);
 
} else if (status == MidiParameter.CHANNEL_PRESSURE) {
nameList.setEnabled(false);
nameScrollPane.setEnabled(false);
 
} else if (status == MidiParameter.PITCH_BEND) {
nameList.setEnabled(false);
nameScrollPane.setEnabled(false);
}
 
nameList.setListData(listData);
nameList.setSelectedIndex(midiParameter.getMidiNumber());
nameList.ensureIndexIsVisible(midiParameter.getMidiNumber());
 
if (status == MidiParameter.NOTE_ON) {
defaultValueLabel.setText("Note On Velocity: ");
 
} else if (status == MidiParameter.AFTERTOUCH) {
defaultValueLabel.setText("Aftertouch Pressure: ");
 
} else if (status == MidiParameter.CONTROL_CHANGE) {
defaultValueLabel.setText("Control Change Value: ");
 
} else if (status == MidiParameter.PROGRAM_CHANGE) {
defaultValueLabel.setText("Program Change No: ");
 
} else if (status == MidiParameter.CHANNEL_PRESSURE) {
defaultValueLabel.setText("Channel Pressure Value: ");
 
} else if (status == MidiParameter.PITCH_BEND) {
defaultValueLabel.setText("Pitch Bend Value: ");
}
 
channelSpinner.getModel().setValue(
new Integer(midiParameter.getMidiChannel() + 1));
channelSpinner.setEnabled(!isLearn);
 
((SpinnerNumberModel) defaultValueSpinner.getModel())
.setValue(new Integer(midiParameter.getMidiDefaultValue()));
((SpinnerNumberModel) defaultValueSpinner.getModel())
.setMaximum(new Integer(midiParameter.getMidiMaxValue()));
defaultValueSpinner.setEnabled(!isLearn);
 
highResolution.setSelected(((MidiParameterControl) midiParameter)
.isHighResolution());
highResolution
.setEnabled(!((MidiParameterControl) midiParameter).isLearn()
&& ((MidiParameterControl) midiParameter)
.getMidiStatus() == MidiParameterControl.CONTROL_CHANGE);
}
 
public void stateChanged(ChangeEvent ce) {
if (update) {
update = false;
Object source = ce.getSource();
 
if (source == channelSpinner) {
midiParameter.setMidiChannel(((Integer) channelSpinner
.getModel().getValue()).intValue() - 1);
}
if (source == defaultValueSpinner) {
midiParameter
.setMidiDefaultValue(((Integer) defaultValueSpinner
.getModel().getValue()).intValue());
}
update = true;
}
}
 
public void valueChanged(ListSelectionEvent lse) {
if (update) {
update = false;
if (nameList.getSelectedIndex() >= 0) {
midiParameter.setMidiNumber(nameList.getSelectedIndex());
}
update = true;
}
}
 
public void update(Observable observable, Object object) {
if (observable == midiParameter) {
if (object != MidiParameter.VALUE) {
updateControls();
}
}
}
 
public void actionPerformed(ActionEvent ae) {
if (update) {
update = false;
 
Object source = ae.getSource();
 
if (source == statusComboBox) {
midiParameter
.setMidiStatus((statusComboBox.getSelectedIndex() + 9) << 4);
} else if (source == midiLearn) {
midiParameter.setLearn(midiLearn.isSelected());
} else if (source == highResolution) {
midiParameter.setHighResolution(highResolution.isSelected());
}
update = true;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiMapDeviceManagerGUI.java
New file
0,0 → 1,232
/*
* @(#)MidiMapDeviceManagerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
 
import org.midibox.midi.MidiMapDevice;
import org.midibox.midi.MidiMapDeviceManager;
 
public class MidiMapDeviceManagerGUI extends JPanel implements Observer,
ActionListener, ListSelectionListener {
 
private MidiMapDeviceManager midiMapDeviceManager;
 
private JTable midiMapsTable;
 
private FiltersDataModel filtersDataModel;
 
private JButton propertiesButton;
 
private JButton removeButton;
 
private Hashtable mapPropertiesDialogs;
 
public MidiMapDeviceManagerGUI(MidiMapDeviceManager midiMapManager) {
super(new BorderLayout());
this.midiMapDeviceManager = midiMapManager;
midiMapManager.addObserver(this);
add(createMainPanel(), BorderLayout.CENTER);
add(createButtonPanel(), BorderLayout.SOUTH);
mapPropertiesDialogs = new Hashtable();
setButtonStates();
}
 
private JPanel createMainPanel() {
JPanel mainPanel = new JPanel(new BorderLayout());
filtersDataModel = new FiltersDataModel(midiMapDeviceManager
.getMidiMapDevices());
midiMapsTable = new JTable(filtersDataModel);
midiMapsTable.getSelectionModel().setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
midiMapsTable.getSelectionModel().addListSelectionListener(this);
midiMapsTable
.setPreferredScrollableViewportSize(new Dimension(200, 200));
JScrollPane scrollPane = new JScrollPane(midiMapsTable);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
mainPanel.add(scrollPane);
return mainPanel;
}
 
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 
JButton button = new JButton("Add Map");
button.setActionCommand("add");
button.addActionListener(this);
buttonPanel.add(button);
 
propertiesButton = new JButton("Map Properites");
propertiesButton.setActionCommand("properties");
propertiesButton.addActionListener(this);
buttonPanel.add(propertiesButton);
 
removeButton = new JButton("Remove Map");
removeButton.setActionCommand("remove");
removeButton.addActionListener(this);
buttonPanel.add(removeButton);
return buttonPanel;
}
 
public MidiMapDeviceManager getMidiMapDeviceManager() {
return midiMapDeviceManager;
}
 
private void showMapProperties() {
 
int[] selectedRows = midiMapsTable.getSelectedRows();
 
for (int m = 0; m < selectedRows.length; m++) {
 
final MidiMapDevice midiMapDevice = (MidiMapDevice) midiMapDeviceManager
.getMidiMapDevices().elementAt(selectedRows[m]);
 
if (!mapPropertiesDialogs.containsKey(midiMapDevice)) {
 
final MidiMapGUI midiMapGUI = new MidiMapGUI(midiMapDevice
.getMidiMap());
 
JDialog mapPropertiesDialog = new JDialog();
mapPropertiesDialog.setContentPane(midiMapGUI);
mapPropertiesDialog.setModal(false);
mapPropertiesDialog.setTitle(midiMapDevice.getDeviceInfo()
.getName());
mapPropertiesDialog.pack();
mapPropertiesDialog.setLocationRelativeTo(this);
Point location = mapPropertiesDialog.getLocation();
mapPropertiesDialog.setLocation(location.x + m * 20, location.y
+ m * 20);
mapPropertiesDialog.setVisible(true);
 
mapPropertiesDialogs.put(midiMapDevice, mapPropertiesDialog);
 
mapPropertiesDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiMapDevice.deleteObserver(midiMapGUI);
mapPropertiesDialogs.remove(midiMapDevice);
}
});
}
((JDialog) mapPropertiesDialogs.get(midiMapDevice)).requestFocus();
}
}
 
private void setButtonStates() {
boolean rowSelected = midiMapsTable.getSelectedRowCount() > 0;
propertiesButton.setEnabled(rowSelected);
removeButton.setEnabled(rowSelected);
}
 
public void valueChanged(ListSelectionEvent lse) {
setButtonStates();
}
 
public void update(Observable observable, Object object) {
if (observable == midiMapDeviceManager) {
filtersDataModel.fireTableDataChanged();
}
}
 
public void actionPerformed(ActionEvent ae) {
String actionCommand = ae.getActionCommand();
 
if (actionCommand.equals("add")) {
midiMapDeviceManager.addMidiMapDevice();
} else if (actionCommand.equals("properties")) {
showMapProperties();
} else if (actionCommand.equals("remove")) {
 
int[] selectedRows = midiMapsTable.getSelectedRows();
 
for (int m = selectedRows.length - 1; m >= 0; m--) {
midiMapDeviceManager
.removeMidiMapDevice((MidiMapDevice) midiMapDeviceManager
.getMidiMapDevices().elementAt(selectedRows[m]));
}
}
}
 
class FiltersDataModel extends DefaultTableModel {
private String[] headers = { "Map Name" };
 
private Vector midiMaps;
 
public FiltersDataModel(Vector midiMaps) {
this.midiMaps = midiMaps;
}
 
public int getColumnCount() {
return headers.length;
}
 
public int getRowCount() {
if (midiMaps != null) {
return midiMaps.size();
}
return 0;
}
 
public String getColumnName(int col) {
return headers[col];
}
 
public Object getValueAt(int row, int col) {
 
MidiMapDevice midiMapDevice = (MidiMapDevice) midiMaps
.elementAt(row);
 
if (col == 0) {
return midiMapDevice.getDeviceInfo().getName();
}
return null;
}
 
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
 
public boolean isCellEditable(int row, int col) {
return false;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlProperties.java
New file
0,0 → 1,125
/*
* @(#)MidiParameterControlProperties.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
 
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
 
import org.midibox.midi.MidiParameterControl;
 
public class MidiParameterControlProperties extends MidiParameterProperties {
 
protected JCheckBox receiveCheckBox;
 
protected JCheckBox sendCheckBox;
 
protected JCheckBox globalCheckBox;
 
public MidiParameterControlProperties(MidiParameterControl midiParameter) {
super(midiParameter);
globalCheckBox = new JCheckBox("Global");
globalCheckBox.addActionListener(this);
GridBagConstraints gbc = ((GridBagLayout) channelPanel.getLayout())
.getConstraints(channelSpinner);
gbc.gridy++;
channelPanel.add(globalCheckBox, gbc);
add(createBottomPanel(), BorderLayout.SOUTH);
updateControls();
}
 
public JPanel createBottomPanel() {
 
JPanel messagesPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0;
 
receiveCheckBox = new JCheckBox("Receive MIDI Messages");
receiveCheckBox.addActionListener(this);
messagesPanel.add(receiveCheckBox, gbc);
gbc.gridy++;
 
sendCheckBox = new JCheckBox("Send MIDI Messages");
sendCheckBox.addActionListener(this);
messagesPanel.add(sendCheckBox, gbc);
 
messagesPanel.setBorder(BorderFactory
.createTitledBorder("MIDI Controller"));
 
return messagesPanel;
}
 
public void updateControls() {
 
super.updateControls();
 
if (sendCheckBox != null && receiveCheckBox != null
&& globalCheckBox != null) {
 
sendCheckBox.setSelected(((MidiParameterControl) midiParameter)
.isSend());
sendCheckBox.setEnabled(!((MidiParameterControl) midiParameter)
.isLearn());
receiveCheckBox.setSelected(((MidiParameterControl) midiParameter)
.isReceive());
receiveCheckBox.setEnabled(!((MidiParameterControl) midiParameter)
.isLearn());
 
globalCheckBox.setSelected(((MidiParameterControl) midiParameter)
.isGlobal());
globalCheckBox.setEnabled(!((MidiParameterControl) midiParameter)
.isLearn());
 
channelSpinner.setEnabled(!((MidiParameterControl) midiParameter)
.isGlobal()
&& !((MidiParameterControl) midiParameter).isLearn());
}
}
 
public void actionPerformed(ActionEvent ae) {
 
super.actionPerformed(ae);
 
if (update) {
update = false;
 
Object source = ae.getSource();
 
if (source == receiveCheckBox) {
((MidiParameterControl) midiParameter)
.setReceive(receiveCheckBox.isSelected());
} else if (source == sendCheckBox) {
((MidiParameterControl) midiParameter).setSend(sendCheckBox
.isSelected());
} else if (source == globalCheckBox) {
((MidiParameterControl) midiParameter).setGlobal(globalCheckBox
.isSelected());
}
update = true;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiDeviceManagerGUI.java
New file
0,0 → 1,209
/*
* @(#)MidiDeviceManagerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.sound.midi.MidiDevice;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
 
import org.midibox.midi.MidiDeviceManager;
 
public class MidiDeviceManagerGUI extends JPanel implements Observer,
ActionListener {
 
private MidiDeviceManager midiDeviceManager;
 
private JTable midiReadDevices;
 
private JTable midiWriteDevices;
 
public MidiDeviceManagerGUI(MidiDeviceManager midiDeviceManager) {
super(new GridBagLayout());
 
this.midiDeviceManager = midiDeviceManager;
midiDeviceManager.addObserver(this);
 
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.insets = new Insets(5, 5, 5, 5);
 
gbc.weighty = 0.0;
add(new JLabel("MIDI Devices - Readable", JLabel.CENTER), gbc);
gbc.gridx++;
 
add(new JLabel("MIDI Devices - Writeable", JLabel.CENTER), gbc);
gbc.gridx--;
gbc.gridy++;
 
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 1.0;
midiReadDevices = new JTable(new MidiDeviceTableModel(midiDeviceManager
.getMidiReadDevices(), midiDeviceManager
.getSelectedMidiReadDevices()));
midiReadDevices.setPreferredScrollableViewportSize(new Dimension(200,
200));
midiReadDevices.setCellSelectionEnabled(false);
midiReadDevices.setShowGrid(false);
 
JScrollPane scrollPane = new JScrollPane(midiReadDevices);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
add(scrollPane, gbc);
gbc.gridx++;
 
midiWriteDevices = new JTable(new MidiDeviceTableModel(
midiDeviceManager.getMidiWriteDevices(), midiDeviceManager
.getSelectedMidiWriteDevices()));
midiWriteDevices.setPreferredScrollableViewportSize(new Dimension(200,
200));
midiWriteDevices.setCellSelectionEnabled(false);
midiWriteDevices.setShowGrid(false);
 
scrollPane = new JScrollPane(midiWriteDevices);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
add(scrollPane, gbc);
 
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.WEST;
 
JButton button = new JButton("Rescan Devices");
button.setActionCommand("rescan");
button.addActionListener(this);
add(button, gbc);
}
 
public void update(Observable observable, Object object) {
if (observable == midiDeviceManager) {
((DefaultTableModel) midiReadDevices.getModel())
.fireTableDataChanged();
((DefaultTableModel) midiWriteDevices.getModel())
.fireTableDataChanged();
}
}
 
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("rescan")) {
midiDeviceManager.rescanDevices();
}
}
 
class MidiDeviceTableModel extends DefaultTableModel {
private String[] headers = { "Selected", "MIDI Device Name" };
 
private Vector midiDevices;
 
private Vector selectedMidiDevices;
 
public MidiDeviceTableModel(Vector midiDevices,
Vector selectedMidiDevices) {
this.midiDevices = midiDevices;
this.selectedMidiDevices = selectedMidiDevices;
}
 
public int getColumnCount() {
return headers.length;
}
 
public int getRowCount() {
if (midiDevices != null) {
return midiDevices.size();
}
return 0;
}
 
public String getColumnName(int col) {
return headers[col];
}
 
public Object getValueAt(int row, int col) {
 
MidiDevice midiDevice = (MidiDevice) midiDevices.elementAt(row);
 
if (col == 0) {
return new Boolean(selectedMidiDevices.contains(midiDevices
.elementAt(row)));
} else if (col == 1) {
return midiDevice.getDeviceInfo().getName();
}
return null;
}
 
public void setValueAt(Object aValue, int row, int column) {
if (column == 0) {
if (((Boolean) aValue).booleanValue()) {
 
if (midiDevices == midiDeviceManager.getMidiReadDevices()) {
midiDeviceManager
.selectMidiReadDevice((MidiDevice) midiDevices
.elementAt(row));
} else {
midiDeviceManager
.selectMidiWriteDevice((MidiDevice) midiDevices
.elementAt(row));
}
} else {
if (midiDevices == midiDeviceManager.getMidiReadDevices()) {
midiDeviceManager
.deselectMidiReadDevice((MidiDevice) midiDevices
.elementAt(row));
} else {
midiDeviceManager
.deselectMidiWriteDevice((MidiDevice) midiDevices
.elementAt(row));
}
}
}
}
 
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
 
public boolean isCellEditable(int row, int col) {
return col == 0;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiRouterDeviceManagerGUI.java
New file
0,0 → 1,178
/*
* @(#)MidiRouterDeviceManagerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
 
import org.midibox.midi.MidiRouterDevice;
import org.midibox.midi.MidiRouterDeviceManager;
 
public class MidiRouterDeviceManagerGUI extends JPanel implements Observer,
ActionListener, ListSelectionListener {
 
private MidiRouterDeviceManager midiRouterDeviceManager;
 
private JTable routerTable;
 
private RouterDataModel routerDataModel;
 
private JButton removeButton;
 
public MidiRouterDeviceManagerGUI(
MidiRouterDeviceManager midiRouterDeviceManager) {
super(new BorderLayout());
this.midiRouterDeviceManager = midiRouterDeviceManager;
midiRouterDeviceManager.addObserver(this);
add(createMainPanel(), BorderLayout.CENTER);
add(createButtonPanel(), BorderLayout.SOUTH);
setButtonStates();
}
 
private JPanel createMainPanel() {
JPanel mainPanel = new JPanel(new BorderLayout());
routerDataModel = new RouterDataModel(midiRouterDeviceManager
.getMidiRouterDevices());
routerTable = new JTable(routerDataModel);
routerTable.getSelectionModel().setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
routerTable.getSelectionModel().addListSelectionListener(this);
routerTable.setPreferredScrollableViewportSize(new Dimension(200, 200));
JScrollPane scrollPane = new JScrollPane(routerTable);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
mainPanel.add(scrollPane);
return mainPanel;
}
 
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 
JButton button = new JButton("Add Virtual Port");
button.setActionCommand("add");
button.addActionListener(this);
buttonPanel.add(button);
 
removeButton = new JButton("Remove Virtual Port");
removeButton.setActionCommand("remove");
removeButton.addActionListener(this);
buttonPanel.add(removeButton);
return buttonPanel;
}
 
public MidiRouterDeviceManager getMidiRouterDeviceManager() {
return midiRouterDeviceManager;
}
 
private void setButtonStates() {
boolean rowSelected = routerTable.getSelectedRowCount() > 0;
removeButton.setEnabled(rowSelected);
}
 
public void valueChanged(ListSelectionEvent lse) {
setButtonStates();
}
 
public void update(Observable observable, Object object) {
if (observable == midiRouterDeviceManager) {
routerDataModel.fireTableDataChanged();
}
}
 
public void actionPerformed(ActionEvent ae) {
String actionCommand = ae.getActionCommand();
 
if (actionCommand.equals("add")) {
midiRouterDeviceManager.addMidiRouterDevice();
} else if (actionCommand.equals("remove")) {
 
int[] selectedRows = routerTable.getSelectedRows();
 
for (int v = selectedRows.length - 1; v >= 0; v--) {
 
midiRouterDeviceManager
.removeMidiRouter((MidiRouterDevice) midiRouterDeviceManager
.getMidiRouterDevices().elementAt(
selectedRows[v]));
 
}
}
}
 
class RouterDataModel extends DefaultTableModel {
private String[] headers = { "Virtual Port Name" };
 
private Vector midiRouters;
 
public RouterDataModel(Vector midiRouters) {
this.midiRouters = midiRouters;
}
 
public int getColumnCount() {
return headers.length;
}
 
public int getRowCount() {
if (midiRouters != null) {
return midiRouters.size();
}
return 0;
}
 
public String getColumnName(int col) {
return headers[col];
}
 
public Object getValueAt(int row, int col) {
 
MidiRouterDevice midiRouter = (MidiRouterDevice) midiRouters
.elementAt(row);
 
if (col == 0) {
return midiRouter.getDeviceInfo().getName();
}
return null;
}
 
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
 
public boolean isCellEditable(int row, int col) {
return false;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiActivityGUI.java
New file
0,0 → 1,89
/*
* @(#)MidiActivityGUIjava beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.ImageIcon;
import javax.swing.JComponent;
 
import org.midibox.midi.MidiActivity;
 
public class MidiActivityGUI extends JComponent implements Observer {
 
private MidiActivity midiActivity;
 
private ImageIcon offImage, onImage;
 
private Dimension d;
 
private ImageIcon image;
 
public MidiActivityGUI(MidiActivity midiActivity, ImageIcon offImage,
ImageIcon onImage) {
this.midiActivity = midiActivity;
 
this.offImage = offImage;
this.onImage = onImage;
image = offImage;
d = new Dimension(offImage.getIconWidth(), offImage.getIconHeight());
 
midiActivity.addObserver(this);
}
 
public void close() {
 
}
 
private void check() {
if (System.currentTimeMillis() - midiActivity.getTime() < 100) {
image = onImage;
} else {
image = offImage;
}
repaint();
}
 
public void paintComponent(Graphics g) {
super.paintComponent(g);
image.paintIcon(this, g, (getWidth() - image.getIconWidth()) / 2,
(getHeight() - image.getIconHeight()) / 2);
}
 
public Dimension getMinimumSize() {
return d;
}
 
public Dimension getPreferredSize() {
return d;
}
 
public Dimension getMaximumSize() {
return d;
}
 
public void update(Observable observable, Object object) {
check();
}
}
/trunk/java/org/midibox/midi/gui/SysexSendReceiveDeviceManagerGUI.java
New file
0,0 → 1,187
/*
* @(#)SysexSendReceiveDeviceManagerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
 
import org.midibox.midi.SysexSendReceiveDevice;
import org.midibox.midi.SysexSendReceiveDeviceManager;
import org.midibox.utils.gui.ImageLoader;
 
public class SysexSendReceiveDeviceManagerGUI extends JPanel implements
ActionListener, Observer {
 
private SysexSendReceiveDeviceManager sysexSendReceiveDeviceManager;
 
private JTabbedPane tabbedPane;
 
private Vector sysexSendReceiveGUIs;
 
public SysexSendReceiveDeviceManagerGUI(
SysexSendReceiveDeviceManager uploadTaskManager) {
super(new BorderLayout());
 
this.sysexSendReceiveDeviceManager = uploadTaskManager;
uploadTaskManager.addObserver(this);
 
sysexSendReceiveGUIs = new Vector();
 
add(createButtonPanel(), BorderLayout.NORTH);
add(createTabPanel(), BorderLayout.CENTER);
 
createGUIs();
}
 
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 4));
 
JLabel label = new JLabel("Sysex Send/Receive:", JLabel.LEFT);
label.setOpaque(true);
buttonPanel.add(label);
buttonPanel.add(Box.createHorizontalStrut(10));
 
JButton button = new JButton("New Tab");
button.setActionCommand("newSendReceive");
button.setToolTipText("Open new upload tab");
button.addActionListener(this);
buttonPanel.add(button);
 
button = new JButton("Close Tab");
button.setActionCommand("closeSendReceive");
button.setToolTipText("Close current upload tab");
button.addActionListener(this);
buttonPanel.add(button);
 
return buttonPanel;
}
 
private JPanel createTabPanel() {
JPanel tabPanel = new JPanel(new BorderLayout());
tabbedPane = new JTabbedPane();
tabPanel.add(tabbedPane, BorderLayout.CENTER);
tabPanel.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH);
 
return tabPanel;
}
 
private void createGUIs() {
 
Iterator it = sysexSendReceiveDeviceManager
.getSysexSendReceiveDevices().iterator();
 
while (it.hasNext()) {
 
SysexSendReceiveDevice ssrd = (SysexSendReceiveDevice) it.next();
 
boolean hasGUI = false;
 
Iterator it2 = sysexSendReceiveGUIs.iterator();
 
while (it2.hasNext()) {
SysexSendReceiveGUI ssrg = (SysexSendReceiveGUI) it2.next();
if (ssrg.getSysexSendReceive() == ssrd.getSysexSendReceive()) {
hasGUI = true;
}
}
 
if (!hasGUI) {
SysexSendReceiveGUI ssrg = new SysexSendReceiveGUI(ssrd
.getSysexSendReceive());
sysexSendReceiveGUIs.add(ssrg);
tabbedPane.addTab(ssrd.getDeviceInfo().getName(), ImageLoader
.getImageIcon("sysex.png"), ssrg);
}
}
 
it = ((Vector) sysexSendReceiveGUIs.clone()).iterator();
 
while (it.hasNext()) {
 
SysexSendReceiveGUI ssrg = (SysexSendReceiveGUI) it.next();
 
boolean hasDevice = false;
 
Iterator it2 = sysexSendReceiveDeviceManager
.getSysexSendReceiveDevices().iterator();
 
while (it2.hasNext()) {
SysexSendReceiveDevice ssrd = (SysexSendReceiveDevice) it2
.next();
if (ssrg.getSysexSendReceive() == ssrd.getSysexSendReceive()) {
hasDevice = true;
}
}
 
if (!hasDevice) {
sysexSendReceiveGUIs.remove(ssrg);
tabbedPane.remove(ssrg);
}
}
}
 
public void addNewSendReceiveTab() {
sysexSendReceiveDeviceManager.newSysexSendReceive();
}
 
public void closeSendReceiveTab() {
int selectedTab = tabbedPane.getSelectedIndex();
 
if (selectedTab > -1) {
sysexSendReceiveDeviceManager
.removeSysexSendReceiveDevice((SysexSendReceiveDevice) sysexSendReceiveDeviceManager
.getSysexSendReceiveDevices()
.elementAt(selectedTab));
}
}
 
public void update(Observable observable, Object object) {
if (observable == sysexSendReceiveDeviceManager) {
createGUIs();
}
}
 
public void actionPerformed(ActionEvent ae) {
 
String command = ae.getActionCommand();
 
if (command.equals("newSendReceive")) {
addNewSendReceiveTab();
}
 
if (command.equals("closeSendReceive")) {
closeSendReceiveTab();
}
}
}
/trunk/java/org/midibox/midi/gui/MidiFilterDeviceManagerGUI.java
New file
0,0 → 1,237
/*
* @(#)MidiFilterDeviceManagerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
 
import org.midibox.midi.MidiFilterDevice;
import org.midibox.midi.MidiFilterDeviceManager;
import org.midibox.utils.gui.DialogOwner;
 
public class MidiFilterDeviceManagerGUI extends JPanel implements Observer,
ActionListener, ListSelectionListener {
 
private MidiFilterDeviceManager midiFilterDeviceManager;
 
private JTable midiFiltersTable;
 
private FiltersDataModel filtersDataModel;
 
private JButton propertiesButton;
 
private JButton removeButton;
 
private Hashtable filterPropertiesDialogs;
 
public MidiFilterDeviceManagerGUI(MidiFilterDeviceManager midiFilterManager) {
super(new BorderLayout());
this.midiFilterDeviceManager = midiFilterManager;
midiFilterManager.addObserver(this);
add(createMainPanel(), BorderLayout.CENTER);
add(createButtonPanel(), BorderLayout.SOUTH);
filterPropertiesDialogs = new Hashtable();
setButtonStates();
}
 
private JPanel createMainPanel() {
JPanel mainPanel = new JPanel(new BorderLayout());
filtersDataModel = new FiltersDataModel(midiFilterDeviceManager
.getMidiFilterDevices());
midiFiltersTable = new JTable(filtersDataModel);
midiFiltersTable.getSelectionModel().setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
midiFiltersTable.getSelectionModel().addListSelectionListener(this);
midiFiltersTable.setPreferredScrollableViewportSize(new Dimension(200,
200));
JScrollPane scrollPane = new JScrollPane(midiFiltersTable);
scrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
mainPanel.add(scrollPane);
return mainPanel;
}
 
private JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 
JButton button = new JButton("Add Filter");
button.setActionCommand("add");
button.addActionListener(this);
buttonPanel.add(button);
 
propertiesButton = new JButton("Filter Properites");
propertiesButton.setActionCommand("properties");
propertiesButton.addActionListener(this);
buttonPanel.add(propertiesButton);
 
removeButton = new JButton("Remove Filter");
removeButton.setActionCommand("remove");
removeButton.addActionListener(this);
buttonPanel.add(removeButton);
return buttonPanel;
}
 
public MidiFilterDeviceManager getMidiFilterDeviceManager() {
return midiFilterDeviceManager;
}
 
private void showFilterProperties() {
 
int[] selectedRows = midiFiltersTable.getSelectedRows();
 
for (int f = 0; f < selectedRows.length; f++) {
 
final MidiFilterDevice midiFilterDevice = (MidiFilterDevice) midiFilterDeviceManager
.getMidiFilterDevices().elementAt(selectedRows[f]);
 
if (!filterPropertiesDialogs.containsKey(midiFilterDevice)) {
 
final MidiFilterGUI midiFilterGUI = new MidiFilterGUI(
midiFilterDevice.getMidiFilter());
 
JDialog filterPropertiesDialog = new JDialog(DialogOwner
.getFrame(),
midiFilterDevice.getDeviceInfo().getName(), false);
filterPropertiesDialog.setContentPane(midiFilterGUI);
filterPropertiesDialog.pack();
filterPropertiesDialog.setLocationRelativeTo(this);
Point location = filterPropertiesDialog.getLocation();
filterPropertiesDialog.setLocation(location.x + f * 20,
location.y + f * 20);
filterPropertiesDialog.setVisible(true);
 
filterPropertiesDialogs.put(midiFilterDevice,
filterPropertiesDialog);
 
filterPropertiesDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiFilterDevice.deleteObserver(midiFilterGUI);
filterPropertiesDialogs.remove(midiFilterDevice);
}
});
}
((JDialog) filterPropertiesDialogs.get(midiFilterDevice))
.requestFocus();
 
}
}
 
private void setButtonStates() {
boolean rowSelected = midiFiltersTable.getSelectedRowCount() > 0;
propertiesButton.setEnabled(rowSelected);
removeButton.setEnabled(rowSelected);
}
 
public void valueChanged(ListSelectionEvent lse) {
setButtonStates();
}
 
public void update(Observable observable, Object object) {
if (observable == midiFilterDeviceManager) {
filtersDataModel.fireTableDataChanged();
}
}
 
public void actionPerformed(ActionEvent ae) {
String actionCommand = ae.getActionCommand();
 
if (actionCommand.equals("add")) {
midiFilterDeviceManager.addMidiFilterDevice();
} else if (actionCommand.equals("properties")) {
showFilterProperties();
} else if (actionCommand.equals("remove")) {
 
int[] selectedRows = midiFiltersTable.getSelectedRows();
 
for (int f = selectedRows.length - 1; f >= 0; f--) {
 
midiFilterDeviceManager
.removeMidiFilterDevice((MidiFilterDevice) midiFilterDeviceManager
.getMidiFilterDevices().elementAt(
selectedRows[f]));
}
}
}
 
class FiltersDataModel extends DefaultTableModel {
private String[] headers = { "Filter Name" };
 
private Vector midiFilterDevices;
 
public FiltersDataModel(Vector midiFilterDevices) {
this.midiFilterDevices = midiFilterDevices;
}
 
public int getColumnCount() {
return headers.length;
}
 
public int getRowCount() {
if (midiFilterDevices != null) {
return midiFilterDevices.size();
}
return 0;
}
 
public String getColumnName(int col) {
return headers[col];
}
 
public Object getValueAt(int row, int col) {
 
MidiFilterDevice midiFilterDevice = (MidiFilterDevice) midiFilterDevices
.elementAt(row);
 
if (col == 0) {
return midiFilterDevice.getDeviceInfo().getName();
}
return null;
}
 
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
 
public boolean isCellEditable(int row, int col) {
return false;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiKeyboardControllerGUI.java
New file
0,0 → 1,665
/*
* @(#)MidiKeyboardControllerGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
/*
* Portions based on MidiSynth.java by Brian Lichtenwalter
* Original copyright below:
*
* MidiSynth.java 1.15 99/12/03
*
* Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JToggleButton;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.MouseInputAdapter;
 
import org.midibox.midi.MidiKeyboardController;
import org.midibox.midi.MidiParameterControl;
import org.midibox.utils.gui.FontLoader;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.Knob;
import org.midibox.utils.gui.MyButtonUI;
import org.midibox.utils.gui.SliderWheelUI;
 
/**
* Description
*
* @version 1.0 05 April 2005
* @author Adam King
*/
 
public class MidiKeyboardControllerGUI extends JPanel implements Observer,
ChangeListener, ActionListener {
 
private MidiKeyboardController midiKeyboardController;
 
protected static Color menuForegroundColor = Color.BLACK;
 
protected static Color menuBorderColor = new Color(91, 91, 91);
 
protected static Color menuBackgroundColor = new Color(180, 180, 180);
 
private final Color[] channelColours = { new Color(245, 145, 255),
new Color(0, 255, 255), new Color(255, 255, 0),
new Color(141, 245, 197), new Color(206, 186, 244),
new Color(192, 192, 192), new Color(0, 178, 176),
new Color(255, 0, 0), new Color(253, 124, 53),
new Color(128, 0, 128), new Color(128, 128, 0),
new Color(10, 140, 80), new Color(0, 117, 225),
new Color(128, 64, 8), new Color(224, 0, 238), new Color(0, 0, 255) };
 
private Piano piano;
 
private JSpinner channelNo;
 
private JSpinner velocity;
 
private JSpinner bankSelect;
 
private JSpinner programNo;
 
private JSlider modWheel;
 
private JSlider pitchWheel;
 
private JPanel mainPanel;
 
public MidiKeyboardControllerGUI(
MidiKeyboardController midiKeyboardController) {
 
this.midiKeyboardController = midiKeyboardController;
midiKeyboardController.addObserver(this);
 
setLayout(new BorderLayout());
 
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
 
JPanel topPanel = new JPanel(new BorderLayout());
 
JPanel spinnerPanel = new JPanel(new GridBagLayout());
spinnerPanel.setOpaque(false);
 
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridheight = 1;
gbc.gridwidth = 1;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 2, 4, 2);
gbc.fill = GridBagConstraints.HORIZONTAL;
 
JLabel channelNoLabel = new JLabel("CHANNEL", SwingConstants.CENTER);
channelNoLabel.setFont(FontLoader.getFont("uni05_53.ttf", 8));
spinnerPanel.add(channelNoLabel, gbc);
gbc.gridy++;
 
channelNo = new JSpinner(new SpinnerNumberModel(midiKeyboardController
.getGlobalChannel() + 1, 1, 16, 1));
channelNo.addChangeListener(this);
channelNo.setFont(FontLoader.getFont("uni05_53.ttf", 8));
((JSpinner.DefaultEditor) channelNo.getEditor()).getTextField()
.setBackground(
channelColours[midiKeyboardController
.getGlobalChannel()]);
spinnerPanel.add(channelNo, gbc);
gbc.gridx++;
gbc.gridy = 0;
 
JLabel velocityLabel = new JLabel("VELOCITY", SwingConstants.CENTER);
velocityLabel.setFont(FontLoader.getFont("uni05_53.ttf", 8));
spinnerPanel.add(velocityLabel, gbc);
gbc.gridy++;
 
velocity = new JSpinner(new SpinnerNumberModel(midiKeyboardController
.getVelocityVal(), 0, 127, 1));
velocity.addChangeListener(this);
velocity.setFont(FontLoader.getFont("uni05_53.ttf", 8));
spinnerPanel.add(velocity, gbc);
gbc.gridx = 0;
gbc.gridy++;
 
gbc.insets = new Insets(4, 2, 2, 2);
 
bankSelect = new JSpinner(new SpinnerNumberModel(0, 0,
midiKeyboardController.getBankSelect().getMidiMaxValue(), 1));
spinnerPanel.add(new MidiParameterControlSpinner(midiKeyboardController
.getBankSelect(), bankSelect, "BANK"), gbc);
gbc.gridx++;
 
programNo = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1));
spinnerPanel.add(new MidiParameterControlSpinner(midiKeyboardController
.getProgramChange(), programNo, "PROGRAM"), gbc);
 
topPanel.add(spinnerPanel, BorderLayout.WEST);
 
JPanel controllersPanel = new JPanel(new BorderLayout());
controllersPanel.setOpaque(false);
 
JPanel knobPanel = new JPanel(new GridLayout(1, midiKeyboardController
.getControllers().size()));
knobPanel.setOpaque(false);
 
for (int c = 0; c < midiKeyboardController.getControllers().size(); c++) {
Knob knob = new Knob(ImageLoader
.getImageIcon("plasticknob_strip.png"));
MidiParameterControl midiParameter = (MidiParameterControl) midiKeyboardController
.getControllers().elementAt(c);
MidiParameterControlGUI midiParameterGUI = new MidiParameterControlKnob(
midiParameter, knob, true, BorderLayout.SOUTH, false, false);
knobPanel.add(midiParameterGUI);
}
 
controllersPanel.add(knobPanel, BorderLayout.NORTH);
 
JPanel buttonPanel = new JPanel(new GridLayout(1,
midiKeyboardController.getControllers().size()));
buttonPanel.setOpaque(false);
 
for (int b = 0; b < midiKeyboardController.getButtons().size(); b++) {
JToggleButton button = new JToggleButton();
button.setUI(new MyButtonUI(ImageLoader
.getImageIcon("metal_button_small_on.png"), ImageLoader
.getImageIcon("metal_button_small_off.png")));
MidiParameterControl midiParameter = (MidiParameterControl) midiKeyboardController
.getButtons().elementAt(b);
MidiParameterControlGUI midiParameterGUI = new MidiParameterControlToggleButton(
midiParameter, button, false, true, BorderLayout.SOUTH,
false, false);
buttonPanel.add(midiParameterGUI);
}
 
controllersPanel.add(buttonPanel, BorderLayout.SOUTH);
 
topPanel.add(controllersPanel, BorderLayout.CENTER);
 
topPanel.setOpaque(false);
topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
mainPanel.add(topPanel);
 
JPanel bottomPanel = new JPanel(new BorderLayout());
JPanel expressionPanel = createExpressionPanel();
 
piano = new Piano();
bottomPanel.add(piano, BorderLayout.CENTER);
bottomPanel.add(expressionPanel, BorderLayout.WEST);
bottomPanel.setOpaque(false);
 
Dimension d1 = piano.getPreferredSize();
Dimension d2 = expressionPanel.getPreferredSize();
bottomPanel.setPreferredSize(new Dimension(d1.width + d2.width,
d1.height));
 
mainPanel.add(bottomPanel);
topPanel.setPreferredSize(new Dimension(
bottomPanel.getPreferredSize().width, topPanel
.getPreferredSize().height));
 
mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
mainPanel.setOpaque(false);
add(mainPanel, BorderLayout.SOUTH);
// add(menuPanel, BorderLayout.NORTH);
}
 
public MidiKeyboardController getMidiKeyboardController() {
return midiKeyboardController;
}
 
public void setMidiKeyboardController(
MidiKeyboardController midiKeyboardController) {
this.midiKeyboardController = midiKeyboardController;
}
 
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(0, 0, new Color(245, 245,
245), getWidth(), getHeight(), new Color(205, 205, 205), true);
g2d.setPaint(gradient);
g2d.fillRect(0, 0, getWidth(), getHeight());
}
 
public JPanel createExpressionPanel() {
JPanel expressionPanel = new JPanel(new GridLayout(1, 2));
expressionPanel.setOpaque(false);
 
pitchWheel = new JSlider(JSlider.VERTICAL, 0, 100, 50);
pitchWheel.setPreferredSize(new Dimension(30, 71));
pitchWheel.setUI(new SliderWheelUI(ImageLoader
.getImageIcon("expressionwheel_horizontal_strip.png"),
ImageLoader.getImageIcon("expressionwheel_vertical_strip.png"),
15));
pitchWheel.setOpaque(false);
 
pitchWheel.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent me) {
pitchWheel.setValue(pitchWheel.getMaximum() / 2);
}
 
public void mouseExited(MouseEvent me) {
pitchWheel.setValue(pitchWheel.getMaximum() / 2);
}
});
 
pitchWheel.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent ke) {
pitchWheel.setValue(pitchWheel.getMaximum() / 2);
}
});
 
expressionPanel.add(new MidiParameterControlSlider(
midiKeyboardController.getPitchWheel(), pitchWheel, false,
BorderLayout.SOUTH, false, false));
 
modWheel = new JSlider(JSlider.VERTICAL, 0, 100, 50);
modWheel.setPreferredSize(new Dimension(30, 71));
modWheel.setUI(new SliderWheelUI(ImageLoader
.getImageIcon("expressionwheel_horizontal_strip.png"),
ImageLoader.getImageIcon("expressionwheel_vertical_strip.png"),
15));
modWheel.setOpaque(false);
 
expressionPanel.add(new MidiParameterControlSlider(
midiKeyboardController.getModWheel(), modWheel, false,
BorderLayout.SOUTH, false, false));
 
expressionPanel.setOpaque(false);
 
return expressionPanel;
}
 
public void stateChanged(ChangeEvent ce) {
Object source = ce.getSource();
 
if (source == channelNo) {
midiKeyboardController.setGlobalChannel(((Integer) channelNo
.getModel().getValue()).intValue() - 1);
} else if (source == velocity) {
midiKeyboardController.setVelocityVal(((Integer) velocity
.getModel().getValue()).intValue());
}
}
 
public void update(Observable observable, Object object) {
((JSpinner.DefaultEditor) channelNo.getEditor()).getTextField()
.setBackground(
channelColours[midiKeyboardController
.getGlobalChannel()]);
if (midiKeyboardController.getGlobalChannel() < 7) {
((JSpinner.DefaultEditor) channelNo.getEditor()).getTextField()
.setForeground(Color.BLACK);
} else {
((JSpinner.DefaultEditor) channelNo.getEditor()).getTextField()
.setForeground(Color.WHITE);
}
piano.repaint();
}
 
public void actionPerformed(ActionEvent ae) {
 
}
 
public class Piano extends JPanel implements MouseListener {
 
private Color highlightColour = new Color(0, 255, 0, 180);
 
private ImageIcon wKeyD = ImageLoader.getImageIcon("wKeyD.png");
 
private ImageIcon wKeyU = ImageLoader.getImageIcon("wKeyU.png");
 
private ImageIcon bKeyD = ImageLoader.getImageIcon("bKeyD.png");
 
private ImageIcon bKeyU = ImageLoader.getImageIcon("bKeyU.png");
 
private boolean release = true;
 
private boolean clearChannel = false;
 
Vector keys = new Vector();
 
Vector whiteKeys = new Vector();
 
Vector blackKeys = new Vector();
 
Key prevKey;
 
final int kw = 16, kh = 70;
 
public Piano() {
setLayout(new BorderLayout());
setPreferredSize(new Dimension(midiKeyboardController
.getNoOctaves()
* 7 * kw, kh + 7));
 
int whiteIDs[] = { 0, 2, 4, 5, 7, 9, 11 };
 
for (int i = 0, x = 0; i < midiKeyboardController.getNoOctaves(); i++) {
for (int j = 0; j < 7; j++, x += kw) {
int keyNum = i * 12 + whiteIDs[j];
whiteKeys
.add(new Key(
(MidiParameterControl) midiKeyboardController
.getKeys().elementAt(keyNum), x, 0,
kw, kh));
}
}
for (int i = 0, x = 0; i < midiKeyboardController.getNoOctaves(); i++, x += kw) {
int keyNum = i * 12;
blackKeys.add(new Key(
(MidiParameterControl) midiKeyboardController.getKeys()
.elementAt(keyNum + 1), (x += kw) - 4, 0,
kw / 2, 40));
blackKeys.add(new Key(
(MidiParameterControl) midiKeyboardController.getKeys()
.elementAt(keyNum + 3), (x += kw) - 4, 0,
kw / 2, 40));
x += kw;
blackKeys.add(new Key(
(MidiParameterControl) midiKeyboardController.getKeys()
.elementAt(keyNum + 6), (x += kw) - 4, 0,
kw / 2, 40));
blackKeys.add(new Key(
(MidiParameterControl) midiKeyboardController.getKeys()
.elementAt(keyNum + 8), (x += kw) - 4, 0,
kw / 2, 40));
blackKeys.add(new Key(
(MidiParameterControl) midiKeyboardController.getKeys()
.elementAt(keyNum + 10), (x += kw) - 4, 0,
kw / 2, 40));
}
 
keys.addAll(blackKeys);
keys.addAll(whiteKeys);
 
addMouseMotionListener(new MouseInputAdapter() {
 
public void mouseDragged(MouseEvent e) {
if (e.isShiftDown()) {
Key key = getKey(e.getPoint());
if (key != null && prevKey != key) {
key.assignChannel();
}
prevKey = key;
repaint();
} else {
Key key = getKey(e.getPoint());
if (prevKey != null && prevKey != key) {
prevKey.setKeyOn(false);
}
if (key != null && prevKey != key) {
key.setKeyOn(true);
}
prevKey = key;
repaint();
}
}
});
addMouseListener(this);
}
 
public void mousePressed(MouseEvent e) {
if (e.isShiftDown()) {
prevKey = getKey(e.getPoint());
if (prevKey != null) {
if (e.getButton() == MouseEvent.BUTTON3) {
clearChannel = true;
} else {
clearChannel = false;
}
prevKey.assignChannel();
repaint();
}
} else {
if (e.getButton() == MouseEvent.BUTTON3) {
release = false;
} else {
release = true;
}
prevKey = getKey(e.getPoint());
if (prevKey != null) {
prevKey.setKeyOn(true);
}
}
}
 
public void mouseReleased(MouseEvent e) {
if (e.isShiftDown()) {
 
} else {
if (prevKey != null) {
prevKey.setKeyOn(false);
}
if (e.getButton() == MouseEvent.BUTTON3) {
release = true;
}
prevKey = null;
}
}
 
public void mouseExited(MouseEvent e) {
if (e.isShiftDown()) {
prevKey = null;
} else {
if (prevKey != null) {
if (prevKey.isKeyOn()) {
prevKey.setKeyOn(false);
}
repaint();
prevKey = null;
}
}
}
 
public void mouseClicked(MouseEvent e) {
}
 
public void mouseEntered(MouseEvent e) {
}
 
public Key getKey(Point point) {
for (int i = 0; i < keys.size(); i++) {
if (((Key) keys.get(i)).contains(point)) {
return (Key) keys.get(i);
}
}
return null;
}
 
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
 
Dimension d = getSize();
 
g2d.setBackground(getBackground());
g2d.clearRect(0, 0, d.width, d.height);
 
g2d.setColor(Color.white);
g2d.fillRect(0, 0, midiKeyboardController.getNoOctaves() * 7 * kw,
kh);
 
for (int i = 0; i < whiteKeys.size(); i++) {
Key key = (Key) whiteKeys.get(i);
if (key.isKeyOn()) {
wKeyD.paintIcon(this, g, key.x, 7);
 
if (key.midiParameter.getMidiNumber() == 60) {
g.setColor(Color.LIGHT_GRAY);
g.fillOval((key.x + key.width / 2) - 3,
(key.y + key.height) - 15, 6, 6);
}
 
g.setColor(highlightColour);
g.fillRect(key.x, key.y + 8, key.width, key.height - 6);
} else {
wKeyU.paintIcon(this, g, key.x, 7);
 
if (key.midiParameter.getMidiNumber() == 60) {
g.setColor(Color.LIGHT_GRAY);
g.fillOval((key.x + key.width / 2) - 3,
(key.y + key.height) - 15, 6, 6);
}
}
 
if (!key.midiParameter.isGlobal()) {
g.setColor(channelColours[key.midiParameter
.getMidiChannel()]);
} else {
g.setColor(Color.WHITE);
}
g.fillRect(key.x, key.y + 4, key.width, 3);
 
g.setColor(channelColours[midiKeyboardController
.getGlobalChannel()]);
g.fillRect(key.x, key.y, key.width, 4);
}
 
for (int i = 0; i < blackKeys.size(); i++) {
Key key = (Key) blackKeys.get(i);
if (key.isKeyOn()) {
bKeyD.paintIcon(this, g, key.x, 7);
g.setColor(highlightColour);
g2d.fillRect(key.x, key.y + 8, key.width, key.height - 7);
} else {
bKeyU.paintIcon(this, g, key.x, 7);
}
if (!key.midiParameter.isGlobal()) {
g.setColor(channelColours[key.midiParameter
.getMidiChannel()]);
} else {
g.setColor(Color.WHITE);
}
g.fillRect(key.x, key.y + 4, key.width, 3);
g.setColor(channelColours[midiKeyboardController
.getGlobalChannel()]);
g.fillRect(key.x, key.y, key.width, 4);
}
 
g.setColor(Color.DARK_GRAY);
g.drawLine(0, 0,
midiKeyboardController.getNoOctaves() * 7 * kw - 1, 0);
g.drawLine(0, 0, 0, 6);
g.drawLine((midiKeyboardController.getNoOctaves() * 7 * kw) - 1, 0,
(midiKeyboardController.getNoOctaves() * 7 * kw) - 1, 6);
}
 
public class Key extends Rectangle implements Observer {
 
private MidiParameterControl midiParameter;
 
public Key(MidiParameterControl midiParameter, int x, int y,
int width, int height) {
super(x, y, width, height + 6);
this.midiParameter = midiParameter;
midiParameter.addObserver(this);
}
 
public boolean isKeyOn() {
return (midiParameter.isMidiValueOn());
}
 
public void setKeyOn(boolean sendVal) {
if (sendVal) {
if (!isKeyOn()) {
midiParameter.setMidiValueOn(true, true);
}
} else {
if (release && isKeyOn()) {
midiParameter.setMidiValueOn(false, true);
}
}
}
 
public void assignChannel() {
if (clearChannel) {
midiParameter.setGlobal(true);
} else {
midiParameter.setGlobal(false);
}
}
 
public void update(Observable observable, Object object) {
piano.repaint(x, y, width, height + 1);
}
}
}
}
/trunk/java/org/midibox/midi/gui/MidiMonitorFilteredGUI.java
New file
0,0 → 1,229
/*
* @(#)MidiMonitorFilteredGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Observer;
 
import javax.sound.midi.MetaMessage;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
 
import org.midibox.midi.MidiMessageReceived;
import org.midibox.midi.MidiMonitorFiltered;
import org.midibox.utils.gui.ImageLoader;
 
public class MidiMonitorFilteredGUI extends JPanel implements ActionListener,
Observer {
private MidiMonitorFiltered midiMonitorFiltered;
 
private JTextPane textArea;
 
private JButton clearButton;
 
private JButton filterButton;
 
private JDialog filterDialog;
 
int maxLength = 50000;
 
public MidiMonitorFilteredGUI(MidiMonitorFiltered midiFilteredPortMonitor) {
 
super(new BorderLayout());
this.midiMonitorFiltered = midiFilteredPortMonitor;
midiFilteredPortMonitor.getMidiMonitor().addObserver(this);
 
// Create a text area.
textArea = new JTextPane();
textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
textArea.setBackground(Color.BLACK);
textArea.setForeground(Color.LIGHT_GRAY);
textArea.setEditable(false);
JScrollPane areaScrollPane = new JScrollPane(textArea);
areaScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
areaScrollPane.setPreferredSize(new Dimension(100, 100));
 
JToolBar toolbar = new JToolBar("Tool Bar", JToolBar.HORIZONTAL);
toolbar.setRollover(true);
toolbar.setFloatable(false);
 
filterButton = new JButton(ImageLoader.getImageIcon("filterView.png"));
filterButton.addActionListener(this);
filterButton.setMargin(new Insets(2, 2, 2, 2));
filterButton.setToolTipText("Filter Messages");
toolbar.add(filterButton);
 
clearButton = new JButton(ImageLoader.getImageIcon("clearScreen.png"));
clearButton.addActionListener(this);
clearButton.setMargin(new Insets(2, 2, 2, 2));
clearButton.setToolTipText("Clear Screen");
toolbar.add(clearButton);
 
add(toolbar, BorderLayout.NORTH);
add(areaScrollPane, BorderLayout.CENTER);
 
// Voice Messages
setColour(ShortMessage.NOTE_OFF, new Color(0x008000));
setColour(ShortMessage.NOTE_ON, Color.GREEN);
setColour(ShortMessage.POLY_PRESSURE, Color.YELLOW);
setColour(ShortMessage.CONTROL_CHANGE, Color.CYAN);
setColour(ShortMessage.PROGRAM_CHANGE, Color.YELLOW);
setColour(ShortMessage.CHANNEL_PRESSURE, Color.YELLOW);
setColour(ShortMessage.PITCH_BEND, new Color(0x8080FF));
 
setColour(SysexMessage.SYSTEM_EXCLUSIVE, Color.LIGHT_GRAY);
 
// System Common
setColour(ShortMessage.MIDI_TIME_CODE, Color.BLUE);
setColour(ShortMessage.SONG_POSITION_POINTER, Color.BLUE);
setColour(ShortMessage.SONG_SELECT, Color.BLUE);
setColour(ShortMessage.TUNE_REQUEST, Color.BLUE);
 
// System Realtime
setColour(ShortMessage.TIMING_CLOCK, Color.MAGENTA);
setColour(ShortMessage.START, Color.MAGENTA);
setColour(ShortMessage.CONTINUE, Color.MAGENTA);
setColour(ShortMessage.STOP, Color.MAGENTA);
setColour(ShortMessage.ACTIVE_SENSING, Color.MAGENTA);
setColour(ShortMessage.SYSTEM_RESET, Color.MAGENTA);
 
// Meta Messages
setColour(MetaMessage.META, Color.WHITE);
 
setSize(300, 300);
setLocation(0, 0);
}
 
public void setColour(int status, Color colour) {
 
Style def = StyleContext.getDefaultStyleContext().getStyle(
StyleContext.DEFAULT_STYLE);
 
StyledDocument doc = textArea.getStyledDocument();
 
Style style = doc.addStyle("" + status, def);
StyleConstants.setForeground(style, colour);
}
 
public void check() {
 
LinkedList messages = midiMonitorFiltered.getMidiMonitor()
.getReceivedMessages();
 
if (!messages.isEmpty()) {
 
while (!messages.isEmpty()) {
 
MidiMessageReceived message = (MidiMessageReceived) messages
.removeFirst();
 
String string = midiMonitorFiltered.getMidiMonitor()
.decodeMessage(message.midiMessage, message.timeStamp);
 
// return value is null if message should be filtered (required
// for SysEx messages)
if (string != null) {
StyledDocument doc = textArea.getStyledDocument();
 
int status = message.midiMessage.getStatus();
 
if (message.midiMessage instanceof ShortMessage) {
status = ((ShortMessage) message.midiMessage)
.getCommand();
}
 
try {
doc.remove(0, Math.max(doc.getLength() - maxLength, 0));
 
doc.insertString(doc.getLength(), string + "\n", doc
.getStyle("" + status));
 
} catch (BadLocationException ble) {
System.out.println(ble.getMessage());
}
}
}
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}
 
private void showFilterDialog() {
if (filterDialog == null) {
final MidiFilterGUI midiFilterGUI = new MidiFilterGUI(
midiMonitorFiltered.getMidiFilter());
 
filterDialog = new JDialog();
filterDialog.setContentPane(midiFilterGUI);
filterDialog.setModal(false);
filterDialog.setTitle("MIDI Filter Properties");
filterDialog.pack();
filterDialog.setLocationRelativeTo(this);
filterDialog.setVisible(true);
 
filterDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
filterDialog = null;
}
});
}
filterDialog.requestFocus();
}
 
public void update(Observable observable, Object object) {
check();
}
 
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
 
if (source == filterButton) {
showFilterDialog();
} else if (source == clearButton) {
textArea.setText("");
}
}
 
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
/trunk/java/org/midibox/midi/gui/MidiDeviceProperties.java
New file
0,0 → 1,71
/*
* @(#)MidiDeviceProperties.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
 
import javax.sound.midi.MidiDevice;
import javax.swing.JLabel;
import javax.swing.JPanel;
 
public class MidiDeviceProperties extends JPanel {
 
protected MidiDevice midiDevice;
 
public MidiDeviceProperties(MidiDevice midiDevice) {
super(new GridBagLayout());
this.midiDevice = midiDevice;
 
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.BOTH;
 
add(new JLabel("Name: "), gbc);
gbc.gridx++;
 
add(new JLabel(midiDevice.getDeviceInfo().getName()), gbc);
gbc.gridx--;
gbc.gridy++;
 
add(new JLabel("Vendor: "), gbc);
gbc.gridx++;
 
add(new JLabel(midiDevice.getDeviceInfo().getVendor()), gbc);
gbc.gridx--;
gbc.gridy++;
 
add(new JLabel("Version: "), gbc);
gbc.gridx++;
 
add(new JLabel(midiDevice.getDeviceInfo().getVersion()), gbc);
gbc.gridx--;
gbc.gridy++;
 
add(new JLabel("Description: "), gbc);
gbc.gridx++;
 
add(new JLabel(midiDevice.getDeviceInfo().getDescription()), gbc);
}
}
/trunk/java/org/midibox/midi/gui/MidiDeviceRoutingGUI.java
1,7 → 1,7
/*
* @(#)MidiDeviceRoutingGUI.java beta7 2006/04/23
* @(#)MidiDeviceRoutingGUI.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
20,19 → 20,32
 
package org.midibox.midi.gui;
 
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.sound.midi.MidiDevice;
import javax.swing.BorderFactory;
39,11 → 52,18
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
52,16 → 72,23
import javax.swing.event.ListSelectionListener;
 
import org.midibox.midi.MidiDeviceRouting;
import org.midibox.midi.MidiFilterDevice;
import org.midibox.midi.MidiMapDevice;
import org.midibox.midi.MidiRouterDevice;
import org.midibox.utils.gui.DialogOwner;
import org.midibox.utils.gui.GuiUtils;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.SimpleTransferHandler;
 
public class MidiDeviceRoutingGUI extends JPanel implements ChangeListener, ListSelectionListener, ActionListener, Observer {
public class MidiDeviceRoutingGUI extends JPanel implements MouseListener,
ChangeListener, ListSelectionListener, ActionListener, Observer {
 
private MidiDeviceRouting midiDeviceRouting;
 
private static Icon openIcon = ImageLoader.getImageIcon("midiPortOpen.png");
 
private static Icon closedIcon = ImageLoader.getImageIcon("midiPortClosed.png");
private static Icon closedIcon = ImageLoader
.getImageIcon("midiPortClosed.png");
 
private Hashtable icons = new Hashtable();
 
76,9 → 103,41
private JList midiWriteDevicesList;
 
private JScrollPane midiWriteDevicesScroller;
private JButton rescan;
 
private JPopupMenu connectionMenu;
 
private JButton connectButton;
 
private JButton disconnectButton;
 
private JButton disconnectallButton;
 
private JButton midiDeviceManagerButton;
 
private JButton midiRouterButton;
 
private JButton filterButton;
 
/*
* private JButton mapButton;
*/
 
private JToggleButton releaseButton;
 
private JPanel wirePanel;
 
private JDialog midiDeviceManagerDialog;
 
private JDialog midiRouterManagerGUI;
 
private JDialog midiFilterManagerDialog;
 
/*
* private JDialog midiMapManagerDialog;
*/
 
private Hashtable midiDevicePropertiesDialogs;
 
public MidiDeviceRoutingGUI(MidiDeviceRouting midiDeviceRouting) {
super(new BorderLayout());
 
85,20 → 144,35
this.midiDeviceRouting = midiDeviceRouting;
midiDeviceRouting.addObserver(this);
 
midiDevicePropertiesDialogs = new Hashtable();
 
addMouseListener(this);
 
addMidiDeviceIcon(MidiRouterDevice.class, ImageLoader
.getImageIcon("virtualMidiDevice.png"));
addMidiDeviceIcon(MidiFilterDevice.class, ImageLoader
.getImageIcon("filter.png"));
addMidiDeviceIcon(MidiMapDevice.class, ImageLoader
.getImageIcon("map.png"));
 
midiReadDevicesListModel = new DefaultListModel();
midiWriteDevicesListModel = new DefaultListModel();
 
midiReadDevicesList = new JList(midiReadDevicesListModel);
midiReadDevicesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
midiReadDevicesList
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
midiReadDevicesList.setLayoutOrientation(JList.VERTICAL);
midiReadDevicesList.setVisibleRowCount(10);
midiReadDevicesList.setVisibleRowCount(6);
midiReadDevicesList.setCellRenderer(new MyListCellRenderer());
midiReadDevicesList.addMouseListener(this);
midiReadDevicesList.setBackground(Color.WHITE);
midiWriteDevicesList = new JList(midiWriteDevicesListModel);
midiWriteDevicesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
midiWriteDevicesList
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
midiWriteDevicesList.setLayoutOrientation(JList.VERTICAL);
midiWriteDevicesList.setVisibleRowCount(10);
midiWriteDevicesList.setVisibleRowCount(6);
midiWriteDevicesList.setCellRenderer(new MyListCellRenderer());
midiWriteDevicesList.addMouseListener(this);
midiWriteDevicesList.setBackground(Color.WHITE);
 
JPanel listPane = new JPanel(new GridBagLayout());
115,7 → 189,8
 
listPane.setOpaque(false);
 
listPane.add(new JLabel("MIDI Input devices",SwingConstants.CENTER), gbc);
listPane.add(new JLabel("MIDI Devices - Readable",
SwingConstants.CENTER), gbc);
gbc.gridy++;
 
midiReadDevicesScroller = new JScrollPane(midiReadDevicesList);
132,6 → 207,79
listPane.add(midiReadDevicesScroller, gbc);
gbc.gridx++;
 
wirePanel = new JPanel() {
 
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
 
Iterator it = getMidiDeviceRouting().getMidiReadDevices()
.iterator();
 
int i = 0;
 
while (it.hasNext()) {
 
MidiDevice transmittingDevice = (MidiDevice) it.next();
 
Iterator it2 = getMidiDeviceRouting().getMidiWriteDevices()
.iterator();
 
int o = 0;
while (it2.hasNext()) {
MidiDevice receivingDevice = (MidiDevice) it2.next();
 
int connected = getMidiDeviceRouting()
.devicesConnected(transmittingDevice,
receivingDevice);
 
if (connected != MidiDeviceRouting.DISCONNECTED) {
 
Rectangle rec1 = midiReadDevicesList.getCellBounds(
i, i);
Point p1 = new Point(0,
((rec1.height / 2) + rec1.y)
+ midiReadDevicesScroller.getY()
- midiReadDevicesScroller
.getVerticalScrollBar()
.getValue()
- wirePanel.getY());
 
Rectangle rec2 = midiWriteDevicesList
.getCellBounds(o, o);
Point p2 = new Point(getWidth(),
((rec2.height / 2) + rec2.y)
+ midiReadDevicesScroller.getY()
- midiWriteDevicesScroller
.getVerticalScrollBar()
.getValue()
- wirePanel.getY());
 
if (connected == MidiDeviceRouting.LOGICALLY_CONNECTED) {
g2d.setStroke(new BasicStroke(2f,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_ROUND, 1f,
new float[] { 3f, 6f }, 0f));
} else {
g2d.setStroke(new BasicStroke(2));
}
g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
}
o++;
}
i++;
}
}
};
 
wirePanel.setOpaque(false);
 
listPane.add(wirePanel, gbc);
 
GuiUtils.setComponentSize(wirePanel, 80, 80);
 
gbc.gridx++;
gbc.gridy--;
 
139,7 → 287,7
gbc.weightx = 1.0;
gbc.weighty = 0.0;
 
listPane.add(new JLabel("MIDI Output devices",
listPane.add(new JLabel("MIDI Devices - Writeable",
SwingConstants.CENTER), gbc);
gbc.gridy++;
 
168,6 → 316,12
GuiUtils.setComponentSize(midiWriteDevicesScroller, maxPreferredWidth,
maxPreferredHeight);
 
midiReadDevicesList.setDragEnabled(true);
midiWriteDevicesList.setDragEnabled(true);
midiReadDevicesList.setTransferHandler(new MidiDevicesTransferHandler(
false));
midiWriteDevicesList.setTransferHandler(new MidiDevicesTransferHandler(
true));
midiReadDevicesList.addListSelectionListener(this);
midiWriteDevicesList.addListSelectionListener(this);
 
174,9 → 328,86
listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
listPane.setOpaque(false);
add(listPane, BorderLayout.CENTER);
rescan = new JButton("Rescan");
rescan.addActionListener(this);
add(rescan, BorderLayout.SOUTH);
 
JPanel buttonPane = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
 
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.BOTH;
 
gbc.insets = new Insets(5, 5, 5, 5);
 
connectButton = new JButton("Connect");
connectButton.setToolTipText("Connect Selected Devices");
connectButton.addActionListener(this);
buttonPane.add(connectButton, gbc);
gbc.gridy++;
 
gbc.insets = new Insets(5, 5, 10, 5);
 
midiDeviceManagerButton = new JButton("Select Devices");
midiDeviceManagerButton.setToolTipText("Select Hardware Devices");
midiDeviceManagerButton.addActionListener(this);
buttonPane.add(midiDeviceManagerButton, gbc);
gbc.gridx++;
gbc.gridy--;
 
gbc.insets = new Insets(5, 5, 5, 5);
 
gbc.gridwidth = 2;
disconnectButton = new JButton("Disconnect");
disconnectButton.setToolTipText("Disconnect Selected Devices");
disconnectButton.addActionListener(this);
buttonPane.add(disconnectButton, gbc);
gbc.gridy++;
 
gbc.insets = new Insets(5, 5, 10, 5);
 
gbc.gridwidth = 1;
midiRouterButton = new JButton(ImageLoader
.getImageIcon("virtualMidiDevice.png"));
midiRouterButton.setToolTipText("Add/Remove Virtual Ports");
midiRouterButton.addActionListener(this);
buttonPane.add(midiRouterButton, gbc);
gbc.gridx++;
 
filterButton = new JButton(ImageLoader.getImageIcon("filter.png"));
filterButton.setToolTipText("Add/Remove Filters");
filterButton.addActionListener(this);
buttonPane.add(filterButton, gbc);
gbc.gridx++;
 
/*
* gbc.insets = new Insets(5, 4, 10, 5);
*
* mapButton = new JButton(ImageLoader.getImageIcon("map.png"));
* mapButton.setToolTipText("Add/Remove Maps");
* mapButton.addActionListener(this); mapButton.setMargin(new Insets(2,
* 8, 2, 8)); buttonPane.add(mapButton, gbc); gbc.gridx++;
*/
 
gbc.gridy--;
 
gbc.insets = new Insets(5, 5, 5, 5);
 
disconnectallButton = new JButton("Disconnect All");
disconnectallButton.setToolTipText("Disconnect All Devices");
disconnectallButton.addActionListener(this);
buttonPane.add(disconnectallButton, gbc);
gbc.gridy++;
 
gbc.insets = new Insets(5, 5, 10, 5);
 
releaseButton = new JToggleButton("Release Ports", midiDeviceRouting
.getPortsReleased());
releaseButton.setToolTipText("Release MIDI Ports");
releaseButton.addActionListener(this);
buttonPane.add(releaseButton, gbc);
 
buttonPane.setOpaque(false);
add(buttonPane, BorderLayout.SOUTH);
populateTrees();
}
 
184,6 → 415,10
return midiDeviceRouting;
}
 
public void addMidiDeviceIcon(Object object, Icon icon) {
icons.put(object, icon);
}
 
public Icon getMidiDeviceIcon(MidiDevice md) {
if (icons.containsKey(md)) {
return (Icon) icons.get(md);
207,11 → 442,188
 
public void redrawAll() {
midiReadDevicesList.repaint();
midiWriteDevicesList.repaint();
midiWriteDevicesList.repaint();
wirePanel.repaint();
setButtonStates();
}
 
private void buildConnectionMenu(boolean output) {
 
final MidiDevice sourceDevice = (MidiDevice) ((output) ? midiDeviceRouting
.getMidiWriteDevices()
: midiDeviceRouting.getMidiReadDevices())
.elementAt(((output) ? midiWriteDevicesList
: midiReadDevicesList).getSelectedIndex());
final Vector targetDevices = ((output) ? midiDeviceRouting
.getMidiReadDevices() : midiDeviceRouting.getMidiWriteDevices());
 
connectionMenu = new JPopupMenu(sourceDevice.getDeviceInfo().getName());
 
JMenu connectMenu = new JMenu("Connect to ...");
 
connectionMenu.add(connectMenu);
 
connectionMenu.setLabel(sourceDevice.getDeviceInfo().getName());
 
Iterator it = targetDevices.iterator();
 
while (it.hasNext()) {
 
MidiDevice targetDevice = (MidiDevice) it.next();
 
final MidiDevice transmittingDevice = ((output) ? targetDevice
: sourceDevice);
final MidiDevice receivingDevice = ((output) ? sourceDevice
: targetDevice);
final JCheckBoxMenuItem connect = new JCheckBoxMenuItem(
targetDevice.getDeviceInfo().getName(),
midiDeviceRouting.devicesConnected(transmittingDevice,
receivingDevice) != MidiDeviceRouting.DISCONNECTED);
 
connect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (connect.isSelected()) {
midiDeviceRouting.connectDevices(transmittingDevice,
receivingDevice);
} else {
midiDeviceRouting.disconnectDevices(transmittingDevice,
receivingDevice);
}
}
});
connectMenu.add(connect);
}
 
JMenuItem properties = new JMenuItem("MIDI Device Properties");
properties.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
showMidiDevicePropertyDialog(sourceDevice);
}
});
connectionMenu.add(properties);
}
 
private void showMidiDevicePropertyDialog(MidiDevice midiDeviceIn) {
 
final MidiDevice midiDevice = midiDeviceIn;
 
if (!midiDevicePropertiesDialogs.containsKey(midiDevice)) {
 
final MidiDeviceProperties midiDeviceProperties = new MidiDeviceProperties(
midiDevice);
 
JDialog midiDevicePropertiesDialog = new JDialog(DialogOwner
.getFrame(), midiDevice.getDeviceInfo().getName(), false);
midiDevicePropertiesDialog.setContentPane(midiDeviceProperties);
midiDevicePropertiesDialog.pack();
midiDevicePropertiesDialog.setLocationRelativeTo(this);
midiDevicePropertiesDialog.setVisible(true);
 
midiDevicePropertiesDialogs.put(midiDevice,
midiDevicePropertiesDialog);
 
midiDevicePropertiesDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiDevicePropertiesDialogs.remove(midiDevice);
}
});
}
((JDialog) midiDevicePropertiesDialogs.get(midiDevice)).requestFocus();
}
 
private void showMidiDeviceManagerDialog() {
if (midiDeviceManagerDialog == null) {
final MidiDeviceManagerGUI midiDeviceManagerGUI = new MidiDeviceManagerGUI(
midiDeviceRouting.getMidiDeviceManager());
 
midiDeviceManagerDialog = new JDialog(DialogOwner.getFrame(),
"MIDI Devices", false);
midiDeviceManagerDialog.setContentPane(midiDeviceManagerGUI);
midiDeviceManagerDialog.pack();
midiDeviceManagerDialog.setLocationRelativeTo(this);
midiDeviceManagerDialog.setVisible(true);
 
midiDeviceManagerDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiDeviceRouting.getMidiDeviceManager().deleteObserver(
midiDeviceManagerGUI);
midiDeviceManagerDialog = null;
}
});
}
midiDeviceManagerDialog.requestFocus();
}
 
private void showMidiRouterManagerDialog() {
if (midiRouterManagerGUI == null) {
final MidiRouterDeviceManagerGUI midiRouterDeviceManagerGUI = new MidiRouterDeviceManagerGUI(
midiDeviceRouting.getMidiRouterDeviceManager());
 
midiRouterManagerGUI = new JDialog(DialogOwner.getFrame(),
"Virtual Ports", false);
midiRouterManagerGUI.setContentPane(midiRouterDeviceManagerGUI);
midiRouterManagerGUI.pack();
midiRouterManagerGUI.setLocationRelativeTo(this);
midiRouterManagerGUI.setVisible(true);
 
midiRouterManagerGUI.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiDeviceRouting.getMidiRouterDeviceManager()
.deleteObserver(midiRouterDeviceManagerGUI);
midiRouterManagerGUI = null;
}
});
}
midiRouterManagerGUI.requestFocus();
}
 
private void showFilterManagerDialog() {
if (midiFilterManagerDialog == null) {
final MidiFilterDeviceManagerGUI midiFilterManagerGUI = new MidiFilterDeviceManagerGUI(
midiDeviceRouting.getMidiFilterManager());
 
midiFilterManagerDialog = new JDialog(DialogOwner.getFrame(),
"Filters", false);
midiFilterManagerDialog.setContentPane(midiFilterManagerGUI);
midiFilterManagerDialog.pack();
midiFilterManagerDialog.setLocationRelativeTo(this);
midiFilterManagerDialog.setVisible(true);
 
midiFilterManagerDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiDeviceRouting.getMidiFilterManager().deleteObserver(
midiFilterManagerGUI);
midiFilterManagerDialog = null;
}
});
}
midiFilterManagerDialog.requestFocus();
}
 
/*
* private void showMapManagerDialog() { if (midiMapManagerDialog == null) {
* final MidiMapDeviceManagerGUI midiMapManagerGUI = new
* MidiMapDeviceManagerGUI( midiDeviceRouting.getMidiMapManager());
*
* midiMapManagerDialog = new JDialog();
* midiMapManagerDialog.setModal(false);
* midiMapManagerDialog.setTitle("Maps");
* midiMapManagerDialog.setContentPane(midiMapManagerGUI);
* midiMapManagerDialog.pack();
* midiMapManagerDialog.setLocationRelativeTo(this);
* midiMapManagerDialog.setVisible(true);
*
* midiMapManagerDialog.addWindowListener(new WindowAdapter() { public void
* windowClosing(WindowEvent we) {
* midiDeviceRouting.getMidiMapManager().deleteObserver( midiMapManagerGUI);
* midiMapManagerDialog = null; } }); } midiMapManagerDialog.requestFocus();
* }
*/
 
private void populateTrees() {
 
midiReadDevicesListModel.removeAllElements();
 
Iterator it = midiDeviceRouting.getMidiReadDevices().iterator();
 
while (it.hasNext()) {
218,30 → 630,93
midiReadDevicesListModel.addElement(((MidiDevice) it.next())
.getDeviceInfo().getName());
}
 
midiReadDevicesList.setSelectedIndex(0);
 
midiWriteDevicesListModel.removeAllElements();
 
it = midiDeviceRouting.getMidiWriteDevices().iterator();
 
while (it.hasNext()) {
midiWriteDevicesListModel.addElement(((MidiDevice) it.next())
.getDeviceInfo().getName());
}
 
midiWriteDevicesList.setSelectedIndex(0);
 
updateUI();
}
 
private void setButtonStates() {
 
int[] selectedReadIndices = midiReadDevicesList.getSelectedIndices();
int[] selectedWriteIndices = midiWriteDevicesList.getSelectedIndices();
 
connectButton.setEnabled(false);
disconnectButton.setEnabled(false);
releaseButton.setSelected(midiDeviceRouting.getPortsReleased());
 
if (selectedReadIndices.length > 0 && selectedWriteIndices.length > 0) {
 
for (int r = 0; r < selectedReadIndices.length; r++) {
 
MidiDevice transmittingDevice = (MidiDevice) midiDeviceRouting
.getMidiReadDevices().elementAt(selectedReadIndices[r]);
 
for (int w = 0; w < selectedWriteIndices.length; w++) {
 
MidiDevice receivingDevice = (MidiDevice) midiDeviceRouting
.getMidiWriteDevices().elementAt(
selectedWriteIndices[w]);
 
if (midiDeviceRouting.devicesConnected(transmittingDevice,
receivingDevice) != MidiDeviceRouting.DISCONNECTED) {
disconnectButton.setEnabled(true);
} else {
connectButton.setEnabled(true);
}
}
}
}
}
 
public void valueChanged(ListSelectionEvent lse) {
if (lse.getSource()==midiReadDevicesList) {
if (midiReadDevicesList.getSelectedIndex() > 0) {
midiDeviceRouting.setInputDevice(midiReadDevicesList.getSelectedIndex());
setButtonStates();
}
 
public void mouseClicked(MouseEvent me) {
 
}
 
public void mouseReleased(MouseEvent me) {
Object source = me.getSource();
 
if (source == midiReadDevicesList || source == midiWriteDevicesList) {
JList source2 = (JList) source;
if (me.getButton() == MouseEvent.BUTTON3) {
int index = source2.locationToIndex(me.getPoint());
source2.setSelectedIndex(index);
buildConnectionMenu((source == midiWriteDevicesList) ? true
: false);
connectionMenu.show(source2, me.getX(), me.getY());
}
} else if (lse.getSource()==midiWriteDevicesList) {
if (midiWriteDevicesList.getSelectedIndex() > 0) {
midiDeviceRouting.setOutputDevice(midiWriteDevicesList.getSelectedIndex());
}
}
}
}
 
public void mousePressed(MouseEvent me) {
 
}
 
public void mouseEntered(MouseEvent me) {
 
}
 
public void mouseExited(MouseEvent me) {
 
}
 
public void stateChanged(ChangeEvent ce) {
wirePanel.repaint();
}
 
public Dimension getMinimumSize() {
250,19 → 725,73
 
public void update(Observable observable, Object object) {
if (observable == midiDeviceRouting) {
if (object == midiDeviceRouting.getMidiReadDevices() || object == midiDeviceRouting.getMidiWriteDevices()) {
if (object == midiDeviceRouting.getMidiReadDevices()
|| object == midiDeviceRouting.getMidiWriteDevices()) {
populateTrees();
}
midiReadDevicesList.setSelectedIndex(midiDeviceRouting.getInputDeviceIndex());
midiWriteDevicesList.setSelectedIndex(midiDeviceRouting.getOutputDeviceIndex());
redrawAll();
}
}
 
public void actionPerformed(ActionEvent ae) {
if (ae.getSource()==rescan) {
midiDeviceRouting.rescanDevices();
Object source = ae.getSource();
 
if (source == connectButton) {
 
int[] selectedReadIndices = midiReadDevicesList
.getSelectedIndices();
int[] selectedWriteIndices = midiWriteDevicesList
.getSelectedIndices();
 
for (int r = 0; r < selectedReadIndices.length; r++) {
 
MidiDevice transmittingDevice = (MidiDevice) midiDeviceRouting
.getMidiReadDevices().elementAt(selectedReadIndices[r]);
 
for (int w = 0; w < selectedWriteIndices.length; w++) {
MidiDevice receivingDevice = (MidiDevice) midiDeviceRouting
.getMidiWriteDevices().elementAt(
selectedWriteIndices[w]);
 
midiDeviceRouting.connectDevices(transmittingDevice,
receivingDevice);
}
 
}
} else if (source == disconnectButton) {
 
int[] selectedReadIndices = midiReadDevicesList
.getSelectedIndices();
int[] selectedWriteIndices = midiWriteDevicesList
.getSelectedIndices();
 
for (int r = 0; r < selectedReadIndices.length; r++) {
 
MidiDevice transmittingDevice = (MidiDevice) midiDeviceRouting
.getMidiReadDevices().elementAt(selectedReadIndices[r]);
 
for (int w = 0; w < selectedWriteIndices.length; w++) {
MidiDevice receivingDevice = (MidiDevice) midiDeviceRouting
.getMidiWriteDevices().elementAt(
selectedWriteIndices[w]);
 
midiDeviceRouting.disconnectDevices(transmittingDevice,
receivingDevice);
}
}
} else if (source == disconnectallButton) {
midiDeviceRouting.disconnectAll();
} else if (source == midiDeviceManagerButton) {
showMidiDeviceManagerDialog();
} else if (source == midiRouterButton) {
showMidiRouterManagerDialog();
} else if (source == filterButton) {
showFilterManagerDialog();
} /*
* else if (source == mapButton) { showMapManagerDialog(); }
*/
else if (source == releaseButton) {
midiDeviceRouting.setPortsReleased(releaseButton.isSelected());
}
}
 
279,5 → 808,71
 
return this;
}
}
}
 
public class MidiDevicesTransferHandler extends SimpleTransferHandler {
 
private boolean output;
 
public MidiDevicesTransferHandler(boolean output) {
super();
this.output = output;
dropOnSelf = false;
supportedDataFlavors = new DataFlavor[] { MidiDeviceTransferable.LOCAL_JVM_MIDI_DEVICE_FLAVOR };
}
 
public boolean importData(JComponent c, Transferable t) {
 
if (canImport(c, supportedDataFlavors)) {
 
int[] indices = ((output) ? midiWriteDevicesList
: midiReadDevicesList).getSelectedIndices();
 
for (int d = 0; d < indices.length; d++) {
 
MidiDevice localDevice = (MidiDevice) ((output) ? midiDeviceRouting
.getMidiWriteDevices()
: midiDeviceRouting.getMidiReadDevices())
.elementAt(indices[d]);
 
try {
MidiDevice[] remoteDevices = (MidiDevice[]) t
.getTransferData(MidiDeviceTransferable.LOCAL_JVM_MIDI_DEVICE_FLAVOR);
 
for (int d2 = 0; d2 < remoteDevices.length; d2++) {
 
MidiDevice remoteDevice = remoteDevices[d2];
 
if (output) {
midiDeviceRouting.connectDevices(remoteDevice,
localDevice);
} else {
midiDeviceRouting.connectDevices(localDevice,
remoteDevice);
}
}
} catch (Exception e) {
return false;
}
}
return true;
}
return false;
}
 
protected Transferable createTransferable(JComponent c) {
justExported = true;
int[] indices = ((output) ? midiWriteDevicesList
: midiReadDevicesList).getSelectedIndices();
 
MidiDevice[] midiDevices = new MidiDevice[indices.length];
 
for (int d = 0; d < midiDevices.length; d++) {
midiDevices[d] = (MidiDevice) ((output) ? midiDeviceRouting
.getMidiWriteDevices() : midiDeviceRouting
.getMidiReadDevices()).elementAt(indices[d]);
}
return new MidiDeviceTransferable(midiDevices);
}
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlToggleButton.java
New file
0,0 → 1,77
/*
* @(#)MidiParameterControlToggleButton.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
 
import javax.swing.JPanel;
import javax.swing.JToggleButton;
 
import org.midibox.midi.MidiParameterControl;
 
public class MidiParameterControlToggleButton extends MidiParameterControlGUI {
 
private JToggleButton toggleButton;
 
private boolean momentary = false;
 
public MidiParameterControlToggleButton(MidiParameterControl midiParameter,
JToggleButton toggleButton, boolean momentary, boolean showLabel,
String labelLocation, boolean valueBelow, boolean showValue) {
super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
this.toggleButton = toggleButton;
this.momentary = momentary;
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
panel.setOpaque(false);
panel.add(toggleButton);
add(panel, BorderLayout.CENTER);
toggleButton.addActionListener(this);
toggleButton.addMouseListener(this);
updateGraphics();
}
 
public void actionPerformed(ActionEvent ae) {
 
super.actionPerformed(ae);
 
if (ae.getSource() == toggleButton) {
if (update) {
update = false;
midiParameter.setMidiValueOn(toggleButton.isSelected(), true);
update = true;
}
if (momentary && toggleButton.isSelected()) {
toggleButton.doClick();
}
}
}
 
public void updateGraphics() {
super.updateGraphics();
if (update) {
update = false;
toggleButton.setSelected(midiParameter.isMidiValueOn());
update = true;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlSpinner.java
New file
0,0 → 1,119
/*
* @(#)MidiParameterControlSpinner.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
 
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import org.midibox.midi.MidiParameterControl;
import org.midibox.utils.gui.FontLoader;
 
public class MidiParameterControlSpinner extends MidiParameterControlGUI
implements ChangeListener {
 
private JSpinner spinner;
 
public MidiParameterControlSpinner(MidiParameterControl midiParameter,
JSpinner spinner, String name) {
super(midiParameter, true, BorderLayout.NORTH, false, false);
this.spinner = spinner;
midiParameterLabel.setText(name);
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
panel.setOpaque(false);
panel.add(spinner);
add(panel, BorderLayout.CENTER);
spinner.addChangeListener(this);
spinner.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
spinner.addMouseListener(this);
updateGraphics();
}
 
public void stateChanged(ChangeEvent ce) {
if (update) {
update = false;
midiParameter
.setMidiValue(
(int) (((float) ((Integer) spinner.getModel()
.getValue()).intValue() / (float) ((Integer) ((SpinnerNumberModel) spinner
.getModel()).getMaximum()).intValue()) * (float) midiParameter
.getMidiMaxValue()), true);
update = true;
}
}
 
protected JPopupMenu createPopMenu() {
JPopupMenu popup = new JPopupMenu();
 
final JCheckBoxMenuItem channelMenuItem = new JCheckBoxMenuItem(
"Global Channel", (midiParameter.isGlobal()));
channelMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
midiParameter.setGlobal(channelMenuItem.isSelected());
}
});
 
popup.add(channelMenuItem);
 
for (int i = 0; i < 16; i++) {
JCheckBoxMenuItem channelItem = new JCheckBoxMenuItem("Channel "
+ (i + 1), (midiParameter.getMidiChannel() == i));
channelItem.setEnabled(!midiParameter.isGlobal());
popup.add(channelItem);
 
final int channelNo = i;
 
channelItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
midiParameter.setMidiChannel(channelNo);
}
});
}
return popup;
}
 
public void updateGraphics() {
super.updateGraphics();
if (update) {
update = false;
spinner
.setValue(new Integer(
(int) ((((float) midiParameter.getMidiValue() / (float) midiParameter
.getMidiMaxValue())) * (float) (((Integer) ((SpinnerNumberModel) spinner
.getModel()).getMaximum()).intValue()))));
update = true;
}
}
 
public void update(Observable observable, Object object) {
 
}
}
/trunk/java/org/midibox/midi/gui/MidiMapGUI.java
New file
0,0 → 1,49
/*
* @(#)MidiMapGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import org.midibox.midi.MidiMap;
 
public class MidiMapGUI extends JPanel implements Observer {
 
private MidiMap midiMap;
 
public MidiMapGUI(MidiMap midiMap) {
super(new BorderLayout());
add(new JLabel("*** TODO ***", JLabel.CENTER));
this.midiMap = midiMap;
}
 
public MidiMap getMidiMap() {
return midiMap;
}
 
public void update(Observable observable, Object object) {
 
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlSlider.java
New file
0,0 → 1,84
/*
* @(#)MidiParameterControlSlider.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
 
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import org.midibox.midi.MidiParameterControl;
 
public class MidiParameterControlSlider extends MidiParameterControlGUI
implements ChangeListener, MouseWheelListener {
 
public static float mouseWheelResolution = 10.0f;
 
private JSlider slider;
 
public MidiParameterControlSlider(MidiParameterControl midiParameter,
JSlider slider, boolean showLabel, String labelLocation,
boolean valueBelow, boolean showValue) {
super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
this.slider = slider;
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
panel.setOpaque(false);
panel.add(slider);
add(panel, BorderLayout.CENTER);
slider.addChangeListener(this);
slider.addMouseWheelListener(this);
slider.addMouseListener(this);
updateGraphics();
}
 
public void mouseWheelMoved(MouseWheelEvent mwe) {
slider
.setValue((int) (slider.getValue() - (mwe.getWheelRotation() * ((mouseWheelResolution / 100f) * (float) ((slider
.getMaximum() - slider.getMinimum()))))));
}
 
public void updateGraphics() {
super.updateGraphics();
if (update) {
update = false;
slider
.setValue((int) ((((float) midiParameter.getMidiValue() / (float) midiParameter
.getMidiMaxValue())) * (float) (slider.getMaximum())));
update = true;
}
}
 
public void stateChanged(ChangeEvent ce) {
if (update) {
update = false;
midiParameter.setMidiValue(Math
.round(((float) slider.getValue() / (float) slider
.getMaximum())
* (float) midiParameter.getMidiMaxValue()), true);
update = true;
}
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlGUI.java
New file
0,0 → 1,246
/*
* @(#)MidiParameterControlGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
 
import org.midibox.midi.MidiParameter;
import org.midibox.midi.MidiParameterControl;
import org.midibox.utils.gui.FontLoader;
 
public class MidiParameterControlGUI extends JPanel implements Observer,
ActionListener, MouseListener {
 
protected MidiParameterControl midiParameter;
 
protected boolean showLabel;
 
protected String labelLocation;
 
protected boolean valueBelow;
 
protected boolean showValue;
 
protected JLabel midiParameterLabel;
 
protected JTextField valueField;
 
protected StringBuffer valueBuffer;
 
protected Color valueFieldColor = new Color(150, 20, 0);
 
protected Color labelFieldColor = Color.BLACK;
 
protected boolean update = true;
 
protected JDialog midiParameterPropertiesDialog;
 
public MidiParameterControlGUI(MidiParameterControl midiParameter,
boolean showLabel, String labelLocation, boolean valueBelow,
boolean showValue) {
 
super(new BorderLayout());
 
this.midiParameter = midiParameter;
this.showLabel = showLabel;
this.labelLocation = labelLocation;
this.valueBelow = valueBelow;
this.showValue = showValue;
 
midiParameter.addObserver(this);
 
valueBuffer = new StringBuffer();
 
if (showLabel) {
add(createLabelPanel(), labelLocation);
}
 
addMouseListener(this);
 
setOpaque(false);
}
 
protected JPopupMenu createPopMenu() {
JPopupMenu popupMenu = new JPopupMenu(midiParameter.getMidiName());
 
JMenuItem menuItem = new JMenuItem("MIDI Properties");
menuItem.setActionCommand("midiproperties");
menuItem.addActionListener(this);
popupMenu.add(menuItem);
 
return popupMenu;
}
 
protected JPanel createLabelPanel() {
 
JPanel labelPanel = new JPanel((showValue) ? new GridLayout(
(valueBelow ? 2 : 1), (valueBelow ? 1 : 2)) : new GridLayout(1,
1));
labelPanel.setOpaque(false);
 
midiParameterLabel = new JLabel(midiParameter.getMidiName()
.toUpperCase(),
(showValue) ? ((valueBelow ? SwingConstants.CENTER
: SwingConstants.RIGHT)) : SwingConstants.CENTER);
midiParameterLabel.setOpaque(false);
midiParameterLabel.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
midiParameterLabel.setForeground(labelFieldColor);
labelPanel.add(midiParameterLabel);
 
if (showValue) {
valueField = new JTextField();
valueField.setHorizontalAlignment(JTextField.CENTER);
valueField.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
valueField.setForeground(valueFieldColor);
valueField.addActionListener(this);
valueField.setOpaque(false);
valueField.setBorder(null);
labelPanel.add(valueField);
}
 
return labelPanel;
}
 
protected JTextField createValueField() {
valueField = new JTextField();
return valueField;
}
 
public void setValueFieldColor(Color valueFieldColor) {
this.valueFieldColor = valueFieldColor;
this.valueField.setForeground(valueFieldColor);
}
 
public void setLabelFieldColor(Color labelFieldColor) {
this.labelFieldColor = labelFieldColor;
this.midiParameterLabel.setForeground(labelFieldColor);
}
 
public MidiParameterControl getMidiParameterControl() {
return midiParameter;
}
 
public void updateGraphics() {
if (valueField != null) {
updateValueField();
}
}
 
public void updateValueField() {
valueBuffer.delete(0, valueBuffer.length());
valueBuffer.insert(0, midiParameter.getMidiValue());
valueField.setText(valueBuffer.toString());
}
 
private void showMidiParameterProperties() {
if (midiParameterPropertiesDialog == null) {
final MidiParameterControlProperties midiParameterProperties = new MidiParameterControlProperties(
getMidiParameterControl());
 
midiParameterPropertiesDialog = new JDialog();
midiParameterPropertiesDialog
.setContentPane(midiParameterProperties);
midiParameterPropertiesDialog.setModal(false);
midiParameterPropertiesDialog.setTitle("MIDI Properties");
midiParameterPropertiesDialog.pack();
midiParameterPropertiesDialog.setLocationRelativeTo(this);
midiParameterPropertiesDialog.setVisible(true);
 
midiParameterPropertiesDialog
.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
midiParameter
.deleteObserver(midiParameterProperties);
midiParameterPropertiesDialog = null;
}
});
}
midiParameterPropertiesDialog.requestFocus();
}
 
public void mouseClicked(MouseEvent e) {
 
}
 
public void mouseEntered(MouseEvent e) {
 
}
 
public void mouseExited(MouseEvent e) {
 
}
 
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
createPopMenu().show(this, e.getX(), e.getY());
}
}
 
public void mouseReleased(MouseEvent e) {
 
}
 
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if (source == valueField) {
try {
midiParameter.setMidiValue(Integer.parseInt(valueField
.getText()), true);
} catch (Exception e) {
midiParameter.setMidiValue(midiParameter.getMidiValue(), true);
}
} else if (ae.getActionCommand().equals("midilearn")) {
 
} else if (ae.getActionCommand().equals("midiproperties")) {
showMidiParameterProperties();
}
}
 
public void update(Observable observable, Object object) {
if (observable == midiParameter) {
if (object != MidiParameter.VALUE) {
if (showLabel) {
midiParameterLabel.setText(midiParameter.getMidiName()
.toUpperCase());
}
}
updateGraphics();
}
}
}
/trunk/java/org/midibox/midi/gui/MidiDeviceTransferable.java
New file
0,0 → 1,65
/*
* @(#)MidiDeviceTransferable beta8 2006/04/03
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
 
import javax.sound.midi.MidiDevice;
 
public class MidiDeviceTransferable implements Transferable {
 
public static final DataFlavor LOCAL_JVM_MIDI_DEVICE_FLAVOR = new DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + "; class=\""
+ MidiDevice.class.getName() + "\"", "Local Audio Files");
 
private MidiDevice[] midiDevices;
 
private DataFlavor[] dataFlavors;
 
public MidiDeviceTransferable(MidiDevice[] midiDevices) {
this.midiDevices = midiDevices;
dataFlavors = new DataFlavor[] { MidiDeviceTransferable.LOCAL_JVM_MIDI_DEVICE_FLAVOR };
}
 
public Object getTransferData(DataFlavor flavor) {
 
if (flavor.equals(MidiDeviceTransferable.LOCAL_JVM_MIDI_DEVICE_FLAVOR)) {
// System.out.println("JVM");
return midiDevices;
 
}
return null;
}
 
public DataFlavor[] getTransferDataFlavors() {
return dataFlavors;
}
 
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (int f = 0; f < dataFlavors.length; f++) {
if (flavor.equals(dataFlavors[f])) {
return true;
}
}
return false;
}
}
/trunk/java/org/midibox/midi/gui/MidiFilterGUI.java
New file
0,0 → 1,424
/*
* @(#)MidiFilterGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
 
import org.midibox.midi.MidiFilter;
import org.midibox.midi.MidiUtils;
 
public class MidiFilterGUI extends JPanel implements ActionListener,
TableModelListener, Observer {
 
private MidiFilter midiFilter;
 
// sysex messages
private JCheckBox sysexMessage;
 
// meta messages
private JCheckBox metaMessage;
 
// short messages
private JCheckBox activeSensing;
 
private JCheckBox channelPressure;
 
private JCheckBox continueMessage;
 
private JCheckBox controlChange;
 
private JCheckBox midiTimeCode;
 
private JCheckBox noteOff;
 
private JCheckBox noteOn;
 
private JCheckBox pitchBend;
 
private JCheckBox pollyPressure;
 
private JCheckBox programChange;
 
private JCheckBox songPositionPointer;
 
private JCheckBox songSelect;
 
private JCheckBox start;
 
private JCheckBox stop;
 
private JCheckBox systemReset;
 
private JCheckBox timingClock;
 
private JCheckBox tuneRequest;
 
private JTable cc;
 
private DefaultTableModel ccModel;
 
private JTable channels;
 
private DefaultTableModel channelsModel;
 
public MidiFilterGUI(MidiFilter midiFilter) {
super(new BorderLayout(5, 5));
this.midiFilter = midiFilter;
 
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 
// voice messages
JPanel voicePanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
 
voicePanel
.setBorder(BorderFactory.createTitledBorder("Voice Messages"));
 
noteOff = new JCheckBox("Note Off", midiFilter.noteOff);
noteOff.addActionListener(this);
voicePanel.add(noteOff, gbc);
gbc.gridy++;
 
noteOn = new JCheckBox("Note On", midiFilter.noteOn);
noteOn.addActionListener(this);
voicePanel.add(noteOn, gbc);
gbc.gridy++;
 
pollyPressure = new JCheckBox("Aftertouch", midiFilter.pollyPressure);
pollyPressure.addActionListener(this);
voicePanel.add(pollyPressure, gbc);
gbc.gridy++;
 
controlChange = new JCheckBox("Control Change",
midiFilter.controlChange);
controlChange.addActionListener(this);
voicePanel.add(controlChange, gbc);
gbc.gridy++;
 
programChange = new JCheckBox("Program Change",
midiFilter.programChange);
programChange.addActionListener(this);
voicePanel.add(programChange, gbc);
gbc.gridy++;
 
channelPressure = new JCheckBox("Channel Pressure",
midiFilter.channelPressure);
channelPressure.addActionListener(this);
voicePanel.add(channelPressure, gbc);
gbc.gridy++;
 
pitchBend = new JCheckBox("Pitch Bend", midiFilter.pitchBend);
pitchBend.addActionListener(this);
voicePanel.add(pitchBend, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
voicePanel.add(Box.createVerticalGlue(), gbc);
 
// sysex messages
JPanel sysexPanel = new JPanel(new GridBagLayout());
gbc.gridy = 0;
gbc.weighty = 0.0;
sysexPanel
.setBorder(BorderFactory.createTitledBorder("Sysex Messages"));
 
sysexMessage = new JCheckBox("Sysex Message", midiFilter.sysexMessage);
sysexMessage.addActionListener(this);
sysexPanel.add(sysexMessage, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
sysexPanel.add(Box.createVerticalGlue(), gbc);
 
// system common
JPanel sysCommon = new JPanel(new GridBagLayout());
gbc.gridy = 0;
gbc.weighty = 0.0;
sysCommon.setBorder(BorderFactory.createTitledBorder("System Common"));
 
midiTimeCode = new JCheckBox("MIDI Time Code", midiFilter.midiTimeCode);
midiTimeCode.addActionListener(this);
sysCommon.add(midiTimeCode, gbc);
gbc.gridy++;
 
songPositionPointer = new JCheckBox("Song Position Pointer",
midiFilter.songPositionPointer);
songPositionPointer.addActionListener(this);
sysCommon.add(songPositionPointer, gbc);
gbc.gridy++;
 
songSelect = new JCheckBox("Song Select", midiFilter.songSelect);
songSelect.addActionListener(this);
sysCommon.add(songSelect, gbc);
gbc.gridy++;
 
tuneRequest = new JCheckBox("Tune Request", midiFilter.tuneRequest);
tuneRequest.addActionListener(this);
sysCommon.add(tuneRequest, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
sysCommon.add(Box.createVerticalGlue(), gbc);
 
// system realtime
JPanel sysReal = new JPanel(new GridBagLayout());
gbc.gridy = 0;
gbc.weighty = 0.0;
sysReal.setBorder(BorderFactory.createTitledBorder("System Realtime"));
 
timingClock = new JCheckBox("Timing Clock", midiFilter.timingClock);
timingClock.addActionListener(this);
sysReal.add(timingClock, gbc);
gbc.gridy++;
 
start = new JCheckBox("Start", midiFilter.start);
start.addActionListener(this);
sysReal.add(start, gbc);
gbc.gridy++;
 
continueMessage = new JCheckBox("Continue", midiFilter.continueMessage);
continueMessage.addActionListener(this);
sysReal.add(continueMessage, gbc);
gbc.gridy++;
 
stop = new JCheckBox("Stop", midiFilter.stop);
stop.addActionListener(this);
sysReal.add(stop, gbc);
gbc.gridy++;
 
activeSensing = new JCheckBox("Active Sensing",
midiFilter.activeSensing);
activeSensing.addActionListener(this);
sysReal.add(activeSensing, gbc);
gbc.gridy++;
 
systemReset = new JCheckBox("System Reset", midiFilter.systemReset);
systemReset.addActionListener(this);
sysReal.add(systemReset, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
sysReal.add(Box.createVerticalGlue(), gbc);
 
// meta messages
JPanel metaPanel = new JPanel(new GridBagLayout());
gbc.gridy = 0;
gbc.weighty = 0.0;
metaPanel.setBorder(BorderFactory.createTitledBorder("Meta Messages"));
 
metaMessage = new JCheckBox("Meta Message", midiFilter.metaMessage);
metaMessage.addActionListener(this);
metaPanel.add(metaMessage, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
metaPanel.add(Box.createVerticalGlue(), gbc);
 
channelsModel = new MyTableModel(
new String[] { "Selected", "Channel" }, 0);
channels = new JTable(channelsModel);
 
for (int i = 0; i < 16; i++) {
channelsModel.addRow(new Object[] {
new Boolean(midiFilter.channel[i]), "Channel " + (i + 1) });
}
 
JScrollPane channelsScroll = new JScrollPane(channels);
channelsScroll
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
channelsScroll.setPreferredSize(new Dimension(150, 200));
channelsScroll.setBorder(BorderFactory.createTitledBorder("Channels"));
channels.setCellSelectionEnabled(false);
channels.setShowGrid(false);
channelsModel.addTableModelListener(this);
 
ccModel = new MyTableModel(new String[] { "Selected", "Controller" }, 0);
cc = new JTable(ccModel);
 
for (int i = 0; i < 128; i++) {
ccModel.addRow(new Object[] { new Boolean(midiFilter.cc[i]),
i + ": " + MidiUtils.ccNames[i] });
}
 
JScrollPane ccScroll = new JScrollPane(cc);
ccScroll
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ccScroll.setPreferredSize(new Dimension(200, 200));
ccScroll.setBorder(BorderFactory.createTitledBorder("Control Change"));
cc.setRowSelectionAllowed(false);
cc.setShowGrid(false);
ccModel.addTableModelListener(this);
 
JPanel mainPanel = new JPanel(new GridBagLayout());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 2;
 
mainPanel.add(voicePanel, gbc);
gbc.gridx++;
 
gbc.gridheight = 1;
 
mainPanel.add(sysCommon, gbc);
gbc.gridy++;
 
mainPanel.add(sysexPanel, gbc);
gbc.gridx++;
gbc.gridy = 0;
 
mainPanel.add(sysReal, gbc);
gbc.gridy++;
 
mainPanel.add(metaPanel, gbc);
 
gbc.gridx++;
gbc.gridy = 0;
 
gbc.gridheight = 2;
 
mainPanel.add(channelsScroll, gbc);
gbc.gridx++;
 
mainPanel.add(ccScroll, gbc);
 
add(mainPanel);
}
 
public void actionPerformed(ActionEvent ae) {
 
Object source = ae.getSource();
 
if (source == sysexMessage)
midiFilter.sysexMessage = sysexMessage.isSelected();
 
if (source == metaMessage)
midiFilter.metaMessage = metaMessage.isSelected();
 
if (source == activeSensing)
midiFilter.activeSensing = activeSensing.isSelected();
 
if (source == channelPressure)
midiFilter.channelPressure = channelPressure.isSelected();
 
if (source == continueMessage)
midiFilter.continueMessage = continueMessage.isSelected();
 
if (source == controlChange)
midiFilter.controlChange = controlChange.isSelected();
 
if (source == midiTimeCode)
midiFilter.midiTimeCode = midiTimeCode.isSelected();
 
if (source == noteOff)
midiFilter.noteOff = noteOff.isSelected();
 
if (source == noteOn)
midiFilter.noteOn = noteOn.isSelected();
 
if (source == pitchBend)
midiFilter.pitchBend = pitchBend.isSelected();
 
if (source == pollyPressure)
midiFilter.pollyPressure = pollyPressure.isSelected();
 
if (source == programChange)
midiFilter.programChange = programChange.isSelected();
 
if (source == songPositionPointer)
midiFilter.songPositionPointer = songPositionPointer.isSelected();
 
if (source == songSelect)
midiFilter.songSelect = songSelect.isSelected();
 
if (source == start)
midiFilter.start = start.isSelected();
 
if (source == stop)
midiFilter.stop = stop.isSelected();
 
if (source == systemReset)
midiFilter.systemReset = systemReset.isSelected();
 
if (source == timingClock)
midiFilter.timingClock = timingClock.isSelected();
 
if (source == tuneRequest)
midiFilter.tuneRequest = tuneRequest.isSelected();
}
 
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
 
TableModel model = (TableModel) e.getSource();
Boolean data = (Boolean) model.getValueAt(row, 0);
 
if (model == channelsModel) {
midiFilter.channel[row] = data.booleanValue();
} else {
midiFilter.cc[row] = data.booleanValue();
}
}
 
public void update(Observable observable, Object object) {
 
}
 
class MyTableModel extends DefaultTableModel {
 
public MyTableModel(Object[] a, int b) {
super(a, b);
}
 
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
 
public boolean isCellEditable(int row, int col) {
if (col > 0) {
return false;
} else {
return true;
}
}
}
}
/trunk/java/org/midibox/midi/gui/SysexSendReceiveGUI.java
New file
0,0 → 1,295
/*
* @(#)SysexSendReceiveGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
 
import org.midibox.midi.MidiUtils;
import org.midibox.midi.SysexSendReceive;
import org.midibox.utils.gui.ImageLoader;
import org.midibox.utils.gui.SimpleFileChooserFilter;
 
public class SysexSendReceiveGUI extends JPanel implements ActionListener,
ItemListener, ChangeListener, Observer {
 
public static String currentDirectory = "";
 
private static JFileChooser fc = null;
 
private SysexSendReceive sysexSendReceive;
 
// GUI components
 
private JButton browseButton;
 
private JTextField fileName;
 
private JButton startButton;
 
private JButton stopButton;
 
private JTextPane sysexSendTextArea;
 
private JTextPane sysexReceiveTextArea;
 
private JSpinner sendBufferSizeSpinner;
 
public SysexSendReceiveGUI(SysexSendReceive sysexSendReceive) {
super(new BorderLayout());
 
this.sysexSendReceive = sysexSendReceive;
sysexSendReceive.addObserver(this);
 
browseButton = new JButton("SysEx File", ImageLoader
.getImageIcon("browse.png"));
fileName = new JTextField();
fileName.setEditable(false);
browseButton.setActionCommand("browse");
browseButton.addActionListener(this);
 
startButton = new JButton("Send/Receive");
startButton.setActionCommand("start");
startButton.addActionListener(this);
stopButton = new JButton("Stop");
stopButton.addActionListener(this);
stopButton.setActionCommand("stop");
 
startButton.setAlignmentX(Component.LEFT_ALIGNMENT);
stopButton.setAlignmentX(Component.LEFT_ALIGNMENT);
 
JPanel fileButtonsPanel = new JPanel(new BorderLayout(2, 2));
fileButtonsPanel.add(browseButton, BorderLayout.WEST);
fileButtonsPanel.add(fileName, BorderLayout.CENTER);
fileButtonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 
JPanel controlButtonsPanel = new JPanel(new GridBagLayout());
 
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
 
gbc.insets = new Insets(5, 5, 5, 5);
 
controlButtonsPanel.add(startButton, gbc);
gbc.gridx++;
 
gbc.insets = new Insets(5, 13, 5, 5);
 
controlButtonsPanel.add(stopButton, gbc);
gbc.gridx++;
 
gbc.insets = new Insets(2, 2, 2, 2);
 
gbc.weightx = 1.0;
controlButtonsPanel.add(new JPanel(), gbc);
gbc.gridx++;
gbc.weightx = 0.0;
 
gbc.fill = GridBagConstraints.NONE;
 
JLabel label = new JLabel("Send Buffer Size (bytes): ");
controlButtonsPanel.add(label, gbc);
gbc.gridx++;
 
sendBufferSizeSpinner = new JSpinner(new SpinnerNumberModel(
sysexSendReceive.getSendBufferSize(), 1, 1000, 1));
sendBufferSizeSpinner.addChangeListener(this);
controlButtonsPanel.add(sendBufferSizeSpinner, gbc);
 
JPanel sendPanel = new JPanel(new GridBagLayout());
 
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
 
sendPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createEmptyBorder(2, 2, 2, 2), BorderFactory
.createTitledBorder("Send")));
 
sysexSendTextArea = new JTextPane();
sysexSendTextArea.setBackground(Color.WHITE);
sysexSendTextArea.setEditable(false);
 
StyledDocument doc = sysexSendTextArea.getStyledDocument();
 
Style def = StyleContext.getDefaultStyleContext().getStyle(
StyleContext.DEFAULT_STYLE);
 
doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Monospaced");
 
JScrollPane sysexSendTextAreaScrollPane = new JScrollPane(
sysexSendTextArea);
sysexSendTextAreaScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
 
// Make preferred width smaller than the other panel's minimum width.
sysexSendTextAreaScrollPane.setPreferredSize(new Dimension(300, 100));
 
sendPanel.add(fileButtonsPanel, gbc);
gbc.gridy++;
gbc.weighty = 1.0;
gbc.insets = new Insets(5, 5, 5, 5);
sendPanel.add(sysexSendTextAreaScrollPane, gbc);
 
JPanel receivePanel = new JPanel(new GridBagLayout());
receivePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
.createEmptyBorder(2, 2, 2, 2), BorderFactory
.createTitledBorder("Receive")));
 
sysexReceiveTextArea = new JTextPane();
sysexReceiveTextArea.setBackground(Color.WHITE);
 
sysexReceiveTextArea.setEditable(false);
JScrollPane sysexReceiveTextAreaScrollPane = new JScrollPane(
sysexReceiveTextArea);
sysexReceiveTextAreaScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
 
// Make preferred width smaller than the other panel's minimum width.
sysexReceiveTextAreaScrollPane
.setPreferredSize(new Dimension(300, 100));
 
gbc.gridy = 0;
receivePanel.add(sysexReceiveTextAreaScrollPane, gbc);
 
JPanel mainPanel = new JPanel(new GridBagLayout());
 
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(4, 4, 4, 4);
 
mainPanel.add(controlButtonsPanel, gbc);
gbc.gridy++;
 
gbc.weighty = 1.0;
mainPanel.add(sendPanel, gbc);
gbc.gridy++;
mainPanel.add(receivePanel, gbc);
 
// add(controlButtonsPanel, BorderLayout.NORTH);
// add(mainPanel, BorderLayout.CENTER);
 
add(new JLabel("*** TODO ***", JLabel.CENTER), BorderLayout.CENTER);
 
UIUpdate();
}
 
public void UIUpdate() {
 
}
 
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "start") {
 
} else if (e.getActionCommand() == "stop") {
 
} else if (e.getActionCommand() == "browse") {
onOpenSysexFile();
}
}
 
protected void onOpenSysexFile() {
 
if (fc == null) {
fc = new JFileChooser(currentDirectory);
fc.addChoosableFileFilter(new SimpleFileChooserFilter(
"SysEx files (*.syx)", "syx", "Sysex File"));
}
 
File noFile = new File("");
File noFiles[] = { noFile };
fc.setSelectedFile(noFile);
fc.setSelectedFiles(noFiles);
 
int nRetVal = fc.showOpenDialog(this);
 
if (nRetVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
sysexSendReceive.setFile(file);
currentDirectory = fc.getCurrentDirectory().toString();
}
}
 
public void itemStateChanged(ItemEvent e) {
UIUpdate();
}
 
public void stateChanged(ChangeEvent e) {
 
UIUpdate();
}
 
public void update(Observable observable, Object object) {
if (observable == sysexSendReceive) {
if (object == sysexSendReceive.getFile()) {
sysexSendTextArea.setText("");
StyledDocument doc = sysexSendTextArea.getStyledDocument();
try {
doc
.insertString(0, MidiUtils
.getHexString(sysexSendReceive
.getSysexFile().getData()), doc
.getStyle("regular"));
} catch (Exception e) {
 
}
} else if (object == sysexSendReceive.getReceivedBytes()) {
 
}
}
}
 
public SysexSendReceive getSysexSendReceive() {
return sysexSendReceive;
}
}
/trunk/java/org/midibox/midi/gui/MidiParameterControlKnob.java
New file
0,0 → 1,82
/*
* @(#)MidiParameterControlKnob.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi.gui;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
 
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import org.midibox.midi.MidiParameterControl;
import org.midibox.utils.gui.Knob;
 
public class MidiParameterControlKnob extends MidiParameterControlGUI implements
ChangeListener, MouseWheelListener {
 
public static float mouseWheelResolution = 10.0f;
 
private Knob knob;
 
public MidiParameterControlKnob(MidiParameterControl midiParameter,
Knob knob, boolean showLabel, String labelLocation,
boolean valueBelow, boolean showValue) {
super(midiParameter, showLabel, labelLocation, valueBelow, showValue);
this.knob = knob;
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
panel.setOpaque(false);
panel.add(knob);
add(panel, BorderLayout.CENTER);
knob.addChangeListener(this);
knob.addMouseListener(this);
knob.addMouseWheelListener(this);
updateGraphics();
}
 
public void mouseWheelMoved(MouseWheelEvent mwe) {
knob
.setValue(knob.getValue()
- (mwe.getWheelRotation() * ((mouseWheelResolution / 100) * (knob
.getMaxValue() - knob.getMinValue()))));
}
 
public void stateChanged(ChangeEvent ce) {
if (update) {
update = false;
midiParameter.setMidiValue((int) ((knob.getValue() / knob
.getMaxValue()) * midiParameter.getMidiMaxValue()), true);
update = true;
}
}
 
public void updateGraphics() {
super.updateGraphics();
if (update) {
update = false;
knob.setValue((float) midiParameter.getMidiValue()
/ (float) midiParameter.getMidiMaxValue());
update = true;
}
}
}
/trunk/java/org/midibox/midi/MidiKeyboardController.java
New file
0,0 → 1,193
/*
* @(#)MidiKeyboardController.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Vector;
 
import javax.sound.midi.Receiver;
 
public class MidiKeyboardController extends MidiParameterControlManager {
 
private Vector controllers;
 
private Vector buttons;
 
private Vector keys;
 
private int velocityVal = 100;
 
private int noOctaves = 6;
 
private int transpose = 24;
 
private MidiParameterControl bankSelect;
 
private MidiParameterControl programChange;
 
private MidiParameterControl modWheel;
 
private MidiParameterControl pitchWheel;
 
public MidiKeyboardController(Receiver receiver, int globalChannel) {
 
super(receiver, globalChannel);
 
controllers = new Vector();
 
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 7, 127,
64));
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 8, 64,
64));
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 10, 64,
64));
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 11, 127,
64));
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 12, 0,
64));
controllers.add(new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 13, 0,
64));
 
for (int c = 0; c < controllers.size(); c++) {
MidiParameterControl midiParameter = (MidiParameterControl) controllers
.elementAt(c);
addMidiParameter(midiParameter);
}
 
buttons = new Vector();
 
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 64, 0,
64));
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 69, 0,
64));
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 124, 0,
64));
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 125, 0,
64));
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 126, 0,
64));
buttons.add(new MidiParameterControl(MidiParameterControl.BOOLEAN,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 127, 0,
64));
 
for (int b = 0; b < buttons.size(); b++) {
MidiParameterControl midiParameter = (MidiParameterControl) buttons
.elementAt(b);
addMidiParameter(midiParameter);
}
 
keys = new Vector();
 
for (int o = 0; o < noOctaves; o++) {
for (int note = 0; note < 12; note++) {
MidiParameterControl midiParameter = new MidiParameterControl(
MidiParameterControl.BOOLEAN, receiver,
MidiParameter.NOTE_ON, globalChannel, (o * 12) + note
+ transpose, 0, velocityVal);
keys.add(midiParameter);
addMidiParameter(midiParameter);
}
}
 
bankSelect = new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 0, 0, 0);
bankSelect.addObserver(this);
bankSelect.setReceive(false);
bankSelect.setHighResolution(true);
addMidiParameter(bankSelect);
 
programChange = new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.PROGRAM_CHANGE, globalChannel, 0, 0, 64);
programChange.addObserver(this);
programChange.setReceive(false);
addMidiParameter(programChange);
 
modWheel = new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.CONTROL_CHANGE, globalChannel, 1, 0, 64);
modWheel.addObserver(this);
addMidiParameter(modWheel);
 
pitchWheel = new MidiParameterControl(MidiParameterControl.RANGE,
receiver, MidiParameter.PITCH_BEND, globalChannel, 0, 8192,
8192);
pitchWheel.addObserver(this);
addMidiParameter(pitchWheel);
}
 
public Vector getControllers() {
return controllers;
}
 
public Vector getButtons() {
return buttons;
}
 
public Vector getKeys() {
return keys;
}
 
public int getVelocityVal() {
return velocityVal;
}
 
public void setVelocityVal(int velocityVal) {
this.velocityVal = velocityVal;
for (int k = 0; k < keys.size(); k++) {
MidiParameterControl midiParameter = (MidiParameterControl) keys
.elementAt(k);
midiParameter.setMidiDefaultValue(velocityVal);
}
}
 
public MidiParameterControl getBankSelect() {
return bankSelect;
}
 
public MidiParameterControl getProgramChange() {
return programChange;
}
 
public MidiParameterControl getModWheel() {
return modWheel;
}
 
public MidiParameterControl getPitchWheel() {
return pitchWheel;
}
 
public int getNoOctaves() {
return noOctaves;
}
 
public int getTranspose() {
return transpose;
}
}
/trunk/java/org/midibox/midi/SysexSendReceiveDevice.java
New file
0,0 → 1,41
/*
* @(#)SysexSendReceiveDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class SysexSendReceiveDevice extends VirtualMidiDevice {
 
protected SysexSendReceive sysexSendReceive;
 
public SysexSendReceiveDevice(String name) {
super(name, 1, 1);
this.sysexSendReceive = new SysexSendReceive(midiOutPort);
}
 
public SysexSendReceive getSysexSendReceive() {
return sysexSendReceive;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
sysexSendReceive.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiFilterDevice.java
New file
0,0 → 1,41
/*
* @(#)MidiFilterDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiFilterDevice extends VirtualMidiDevice {
 
protected MidiFilter midiFilter;
 
public MidiFilterDevice(String name) {
super(name, -1, -1);
this.midiFilter = new MidiFilter(midiOutPort);
}
 
public MidiFilter getMidiFilter() {
return midiFilter;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiFilter.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/VirtualMidiDevice.java
1,7 → 1,7
/*
* @(#)VitualMidiDevice.java beta7 2006/04/23
* @(#)VitualMidiDevice.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
23,6 → 23,7
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;
 
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiMessage;
30,10 → 31,8
import javax.sound.midi.Receiver;
import javax.sound.midi.Transmitter;
 
import org.midibox.utils.ObservableMessage;
public class VirtualMidiDevice extends Observable implements MidiDevice {
 
public class VirtualMidiDevice extends ObservableMessage implements MidiDevice {
 
protected VirtualMidiDevice.Info info;
 
protected int maxNoTransmitters;
46,6 → 45,8
 
protected MidiOutPort midiOutPort;
 
protected long timeStart = System.currentTimeMillis();
 
public VirtualMidiDevice(String name, int maxNoTransmitters,
int maxNoReceivers) {
this.info = new VirtualMidiDevice.MyInfo(name, "midibox.org",
70,7 → 71,7
}
 
public long getMicrosecondPosition() {
return -1;
return (System.currentTimeMillis() - timeStart) * 1000;
}
 
public Receiver getReceiver() throws MidiUnavailableException {
/trunk/java/org/midibox/midi/MidiMonitorFiltered.java
New file
0,0 → 1,55
/*
* @(#)MidiMonitorFiltered.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
 
public class MidiMonitorFiltered implements Receiver {
protected MidiFilter midiFilter;
 
protected MidiMonitor midiMonitor;
 
public MidiMonitorFiltered() {
this(new MidiMonitor());
}
 
public MidiMonitorFiltered(MidiMonitor midiMonitor) {
this.midiMonitor = midiMonitor;
midiFilter = new MidiFilter(midiMonitor);
}
 
public MidiFilter getMidiFilter() {
return midiFilter;
}
 
public MidiMonitor getMidiMonitor() {
return midiMonitor;
}
 
public void close() {
 
}
 
public void send(MidiMessage midiMessage, long timestamp) {
midiFilter.send(midiMessage, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiDeviceRouting.java
1,8 → 1,8
/*
* @(#)MidiDeviceRouting.java beta7 2006/04/23
* @(#)MidiDeviceRouting.java beta8 2006/04/23
*
* Copyright (C) 2006 Adam King (adamjking@optusnet.com.au)
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
20,49 → 20,64
 
package org.midibox.midi;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.Vector;
 
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
import javax.sound.midi.Sequencer;
import javax.sound.midi.Synthesizer;
import javax.sound.midi.Transmitter;
import javax.swing.JOptionPane;
 
import org.midibox.sidlibr.SysExControllerDevice;
public class MidiDeviceRouting extends Observable implements Observer {
 
import java.util.prefs.*;
public class MidiDeviceRouting extends Observable {
public static int DISCONNECTED = 0;
 
public static int LOGICALLY_CONNECTED = 1;
 
public static int PHYSICALLY_CONNECTED = 2;
 
private Vector midiReadDevices;
 
private Vector midiWriteDevices;
private MidiDevice localMidiDevice;
private MidiDevice inputMidiDevice;
private MidiDevice outputMidiDevice;
public MidiDeviceRouting(MidiDevice localMidiDevice) {
this.localMidiDevice = localMidiDevice;
 
private Vector logicalConnections;
 
private MidiDeviceManager midiDeviceManager;
 
private MidiRouterDeviceManager midiRouterDeviceManager;
 
private MidiFilterDeviceManager midiFilterManager;
 
/*
* private MidiMapDeviceManager midiMapManager;
*/
 
private boolean portsReleased;
 
public MidiDeviceRouting() {
midiReadDevices = new Vector();
midiWriteDevices = new Vector();
rescanDevices();
if (getMidiReadDevices().size() < 1) {
JOptionPane.showMessageDialog(null,"Your system does not appear to have any MIDI-devices connected (please close program)!.","Error",JOptionPane.OK_OPTION);
} else {
inputMidiDevice = (MidiDevice)getMidiReadDevices().elementAt(0);
outputMidiDevice = (MidiDevice)getMidiWriteDevices().elementAt(0);
connectDevices(inputMidiDevice, localMidiDevice);
connectDevices(localMidiDevice, outputMidiDevice);
}
midiWriteDevices = new Vector();
 
logicalConnections = new Vector();
 
midiDeviceManager = new MidiDeviceManager();
midiDeviceManager.addObserver(this);
 
midiRouterDeviceManager = new MidiRouterDeviceManager();
midiRouterDeviceManager.addObserver(this);
 
midiFilterManager = new MidiFilterDeviceManager();
midiFilterManager.addObserver(this);
 
/*
* midiMapManager = new MidiMapDeviceManager();
* midiMapManager.addObserver(this);
*/
}
 
public Vector getMidiReadDevices() {
72,88 → 87,123
public Vector getMidiWriteDevices() {
return midiWriteDevices;
}
public int getInputDeviceIndex() {
return midiReadDevices.indexOf(inputMidiDevice);
 
public void addMidiReadDevice(MidiDevice midiDevice) {
midiReadDevices.add(midiDevice);
setChanged();
notifyObservers(midiReadDevices);
clearChanged();
}
public int getOutputDeviceIndex() {
return midiWriteDevices.indexOf(outputMidiDevice);
 
public void addMidiWriteDevice(MidiDevice midiDevice) {
midiWriteDevices.add(midiDevice);
setChanged();
notifyObservers(midiReadDevices);
clearChanged();
}
 
public void reconnectAllDevices() { // This function is a workaround for the SysEx (string length doesn't reset) bug in the javax.sound.midi class
System.out.println("Now reconnecting!");
disconnectDevices(inputMidiDevice, localMidiDevice);
System.out.println("Disconnection of " + inputMidiDevice.getDeviceInfo() + " succesfull");
disconnectDevices(localMidiDevice, outputMidiDevice);
System.out.println("Disconnection of " + outputMidiDevice.getDeviceInfo() + " succesfull");
public void addMidiReadDevices(Collection midiDevices) {
Iterator it = midiDevices.iterator();
 
connectDevices(inputMidiDevice, localMidiDevice);
System.out.println("Reconnection of " + inputMidiDevice.getDeviceInfo() + " succesfull");
connectDevices(localMidiDevice, outputMidiDevice);
System.out.println("Reconnection of " + outputMidiDevice.getDeviceInfo() + " succesfull");
}
public int findInputDeviceHash(int hash) {
int temp = -1;
for(int i=0;i<midiReadDevices.size();i++) {
if (((MidiDevice)midiReadDevices.elementAt(i)).getDeviceInfo().toString().hashCode()==hash) {
temp = i;
break;
}
while (it.hasNext()) {
MidiDevice midiDevice = (MidiDevice) it.next();
addMidiReadDevice(midiDevice);
}
return temp;
}
public int findOuputDeviceHash(int hash) {
int temp = -1;
for(int i=0;i<midiWriteDevices.size();i++) {
if (((MidiDevice)midiWriteDevices.elementAt(i)).getDeviceInfo().toString().hashCode()==hash) {
temp = i;
break;
}
 
public void addMidiWriteDevices(Collection midiDevices) {
Iterator it = midiDevices.iterator();
 
while (it.hasNext()) {
MidiDevice midiDevice = (MidiDevice) it.next();
addMidiWriteDevice(midiDevice);
}
return temp;
}
public int getInputDeviceHash() {
return inputMidiDevice.getDeviceInfo().toString().hashCode();
 
public void removeMidiReadDevice(MidiDevice midiDevice) {
midiReadDevices.remove(midiDevice);
setChanged();
notifyObservers(midiReadDevices);
clearChanged();
}
public int getOutputDeviceHash() {
return outputMidiDevice.getDeviceInfo().toString().hashCode();
 
public void removeMidiWriteDevice(MidiDevice midiDevice) {
midiWriteDevices.remove(midiDevice);
setChanged();
notifyObservers(midiWriteDevices);
clearChanged();
}
public void closeMidi() {
disconnectDevices(inputMidiDevice, localMidiDevice);
disconnectDevices(localMidiDevice, outputMidiDevice);
 
public void removeMidiReadDevices(Collection midiDevices) {
Iterator it = midiDevices.iterator();
 
while (it.hasNext()) {
MidiDevice midiDevice = (MidiDevice) it.next();
removeMidiReadDevice(midiDevice);
}
}
public void setInputDevice(int index) {
if (index != getInputDeviceIndex()) {
disconnectDevices(inputMidiDevice, localMidiDevice);
inputMidiDevice = (MidiDevice)midiReadDevices.elementAt(index);
connectDevices(inputMidiDevice, localMidiDevice);
System.out.println("Connection of " + inputMidiDevice.getDeviceInfo() + " succesfull");
setChanged();
notifyObservers();
clearChanged();
 
public void removeMidiWriteDevices(Collection midiDevices) {
Iterator it = midiDevices.iterator();
 
while (it.hasNext()) {
MidiDevice midiDevice = (MidiDevice) it.next();
removeMidiWriteDevice(midiDevice);
}
}
public void setOutputDevice(int index) {
if (index != getOutputDeviceIndex()) {
disconnectDevices(localMidiDevice, outputMidiDevice);
outputMidiDevice = (MidiDevice)midiWriteDevices.elementAt(index);
connectDevices(localMidiDevice, outputMidiDevice);
System.out.println("Connection of " + outputMidiDevice.getDeviceInfo() + " succesfull");
setChanged();
notifyObservers();
clearChanged();
 
public void removeAllMidiReadDevices() {
midiReadDevices.removeAllElements();
setChanged();
notifyObservers(midiReadDevices);
clearChanged();
}
 
public void removeAllMidiWriteDevices() {
midiWriteDevices.removeAllElements();
setChanged();
notifyObservers(midiWriteDevices);
clearChanged();
}
 
public MidiDeviceManager getMidiDeviceManager() {
return midiDeviceManager;
}
 
public MidiRouterDeviceManager getMidiRouterDeviceManager() {
return midiRouterDeviceManager;
}
 
public MidiFilterDeviceManager getMidiFilterManager() {
return midiFilterManager;
}
 
/*
* public MidiMapDeviceManager getMidiMapManager() { return midiMapManager;
* }
*/
 
public void connectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
 
if (devicesConnected(transmittingDevice, receivingDevice) == PHYSICALLY_CONNECTED) {
return;
}
 
logicallyConnectDevices(transmittingDevice, receivingDevice);
 
if (!portsReleased
|| ((transmittingDevice instanceof VirtualMidiDevice) && (receivingDevice instanceof VirtualMidiDevice))) {
 
physicallyConnectDevices(transmittingDevice, receivingDevice);
}
 
setChanged();
notifyObservers();
clearChanged();
}
private void connectDevices(MidiDevice transmittingDevice,
 
private void physicallyConnectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
try {
if (!receivingDevice.isOpen()) {
167,19 → 217,46
}
 
transmittingDevice.getTransmitter().setReceiver(receiver);
 
} catch (MidiUnavailableException e) {
 
} catch (NullPointerException e) {
 
}
 
}
private void disconnectDevices(MidiDevice transmittingDevice,
 
private void logicallyConnectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
logicalConnections.add(new LogicalConnection(transmittingDevice,
receivingDevice));
}
 
// TK: to avoid a "java.util.ConcurrentModificationException" under MacOS (using mmj)
// when a transmitter or receiver is closed, we put them into a list and execute close()
public void disconnectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
 
if (devicesConnected(transmittingDevice, receivingDevice) == DISCONNECTED) {
return;
}
 
logicallyDisconnectDevices(transmittingDevice, receivingDevice);
if (!portsReleased
|| ((transmittingDevice instanceof VirtualMidiDevice) && (receivingDevice instanceof VirtualMidiDevice))) {
 
physicallyDisconnectDevices(transmittingDevice, receivingDevice);
}
setChanged();
notifyObservers();
clearChanged();
}
 
private void physicallyDisconnectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
 
// TK: to avoid a "java.util.ConcurrentModificationException" under
// MacOS (using mmj)
// when a transmitter or receiver is closed, we put them into a list and
// execute close()
// after iteration
List closeTransmitters = new ArrayList();
List closeReceivers = new ArrayList();
198,41 → 275,24
 
// transmitter.close();
closeTransmitters.add(transmitter);
System.out.println("Disconnecting transmitter: " + transmittingDevice.getDeviceInfo());
 
// TK: for mmj under MacOS it is required to check, if getTransmitters()/getReceivers() are != null
int num_transmitters = (transmittingDevice.getTransmitters() != null) ? transmittingDevice.getTransmitters().size() : 0;
int num_receivers = (transmittingDevice.getReceivers() != null) ? transmittingDevice.getReceivers().size() : 0;
System.out.println("Number of transmitters: " + num_transmitters);
System.out.println("Number of receivers: " + num_receivers);
 
// receiver.close();
closeReceivers.add(receiver);
System.out.println("Disconnecting receiver: " + receivingDevice.getDeviceInfo());
 
// TK: for mmj under MacOS it is required to check, if getTransmitters()/getReceivers() are != null
num_transmitters = (receivingDevice.getTransmitters() != null) ? receivingDevice.getTransmitters().size() : 0;
num_receivers = (receivingDevice.getReceivers() != null) ? receivingDevice.getReceivers().size() : 0;
System.out.println("Number of transmitters: " + num_transmitters);
System.out.println("Number of receivers: " + num_receivers);
}
}
}
 
int i;
for(i=0; i<closeTransmitters.size(); ++i) {
Transmitter transmitter = (Transmitter)closeTransmitters.get(i);
transmitter.close();
for (i = 0; i < closeTransmitters.size(); ++i) {
Transmitter transmitter = (Transmitter) closeTransmitters.get(i);
transmitter.close();
}
 
for(i=0; i<closeReceivers.size(); ++i) {
Receiver receiver = (Receiver)closeReceivers.get(i);
receiver.close();
for (i = 0; i < closeReceivers.size(); ++i) {
Receiver receiver = (Receiver) closeReceivers.get(i);
receiver.close();
}
 
int num_transmitters = (transmittingDevice.getTransmitters() != null) ? transmittingDevice
.getTransmitters().size()
: 0;
251,55 → 311,241
.getReceivers().size()
: 0;
 
if (receivingDevice.getTransmitters().size() == 0
&& receivingDevice.getReceivers().size() == 0) {
if (num_transmitters == 0 && num_receivers == 0) {
receivingDevice.close();
}
}
public void rescanDevices() {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
 
Vector tempWriteDevices = new Vector();
Vector tempReadDevices = new Vector();
for (int i = 0; i < infos.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if (!(device instanceof Sequencer)
&& !(device instanceof Synthesizer)) {
private void logicallyDisconnectDevices(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
logicalConnections.remove(new LogicalConnection(transmittingDevice,
receivingDevice));
}
 
int noReceivers = device.getMaxReceivers();
int noTransmitters = device.getMaxTransmitters();
public void disconnectDevice(MidiDevice midiDevice) {
 
if (noReceivers != 0) {
tempWriteDevices.add(device);
setChanged();
notifyObservers(device);
clearChanged();
}
Vector matches = new Vector();
 
if (noTransmitters != 0) {
tempReadDevices.add(device);
setChanged();
notifyObservers(device);
clearChanged();
Iterator it = logicalConnections.iterator();
 
while (it.hasNext()) {
LogicalConnection logicalConnection = (LogicalConnection) it.next();
if (logicalConnection.getSourceDevice() == midiDevice
|| logicalConnection.getTargetDevice() == midiDevice) {
matches.add(logicalConnection);
}
}
 
it = matches.iterator();
 
while (it.hasNext()) {
LogicalConnection logicalConnection = (LogicalConnection) it.next();
disconnectDevices(logicalConnection.getSourceDevice(),
logicalConnection.getTargetDevice());
}
}
 
public void disconnectAll() {
 
Iterator it = midiReadDevices.iterator();
 
while (it.hasNext()) {
 
MidiDevice transmittingDevice = (MidiDevice) it.next();
 
Iterator it2 = midiWriteDevices.iterator();
while (it2.hasNext()) {
 
MidiDevice receivingDevice = (MidiDevice) it2.next();
 
disconnectDevices(transmittingDevice, receivingDevice);
}
}
}
 
public void setPortsReleased(boolean portsReleased) {
 
this.portsReleased = portsReleased;
 
if (portsReleased) {
 
Iterator it = logicalConnections.iterator();
 
while (it.hasNext()) {
LogicalConnection logicalConnection = (LogicalConnection) it
.next();
MidiDevice sourceDevice = logicalConnection.getSourceDevice();
MidiDevice targetDevice = logicalConnection.getTargetDevice();
 
if (!(sourceDevice instanceof VirtualMidiDevice)
|| !(targetDevice instanceof VirtualMidiDevice)) {
 
physicallyDisconnectDevices(sourceDevice, targetDevice);
}
}
} else {
 
Iterator it = logicalConnections.iterator();
 
while (it.hasNext()) {
LogicalConnection logicalConnection = (LogicalConnection) it
.next();
MidiDevice sourceDevice = logicalConnection.getSourceDevice();
MidiDevice targetDevice = logicalConnection.getTargetDevice();
 
if (!(sourceDevice instanceof VirtualMidiDevice)
|| !(targetDevice instanceof VirtualMidiDevice)) {
physicallyConnectDevices(sourceDevice, targetDevice);
}
}
}
 
setChanged();
notifyObservers();
clearChanged();
}
 
public boolean getPortsReleased() {
return portsReleased;
}
 
public int devicesConnected(MidiDevice transmittingDevice,
MidiDevice receivingDevice) {
 
try {
 
Iterator it = transmittingDevice.getTransmitters().iterator();
 
while (it.hasNext()) {
Transmitter transmitter = (Transmitter) it.next();
 
Iterator it2 = receivingDevice.getReceivers().iterator();
 
while (it2.hasNext()) {
 
Receiver receiver = (Receiver) it2.next();
 
if (transmitter.getReceiver() == receiver) {
return PHYSICALLY_CONNECTED;
}
}
} catch (MidiUnavailableException e) {
}
} catch (Exception e) {
return DISCONNECTED;
}
 
if (logicalConnections.contains(new LogicalConnection(
transmittingDevice, receivingDevice))) {
return LOGICALLY_CONNECTED;
}
 
return DISCONNECTED;
}
 
public void reorder() {
midiReadDevices.removeAll(midiDeviceManager
.getSelectedMidiReadDevices());
midiWriteDevices.removeAll(midiDeviceManager
.getSelectedMidiWriteDevices());
midiReadDevices.removeAll(midiRouterDeviceManager
.getMidiRouterDevices());
midiWriteDevices.removeAll(midiRouterDeviceManager
.getMidiRouterDevices());
midiReadDevices.removeAll(midiFilterManager.getMidiFilterDevices());
midiWriteDevices.removeAll(midiFilterManager.getMidiFilterDevices());
 
/*
* midiReadDevices.removeAll(midiMapManager.getMidiMapDevices());
* midiWriteDevices.removeAll(midiMapManager.getMidiMapDevices());
*/
 
Iterator it = midiDeviceManager.getMidiReadDevices().iterator();
while (it.hasNext()) {
 
Object object = it.next();
 
if (midiDeviceManager.getSelectedMidiReadDevices().contains(object)) {
midiReadDevices.add(object);
}
}
midiReadDevices = tempReadDevices;
 
it = midiDeviceManager.getMidiWriteDevices().iterator();
while (it.hasNext()) {
 
Object object = it.next();
 
if (midiDeviceManager.getSelectedMidiWriteDevices()
.contains(object)) {
midiWriteDevices.add(object);
}
}
 
midiReadDevices.addAll(midiRouterDeviceManager.getMidiRouterDevices());
midiWriteDevices.addAll(midiRouterDeviceManager.getMidiRouterDevices());
midiReadDevices.addAll(midiFilterManager.getMidiFilterDevices());
midiWriteDevices.addAll(midiFilterManager.getMidiFilterDevices());
 
/*
* midiReadDevices.addAll(midiMapManager.getMidiMapDevices());
* midiWriteDevices.addAll(midiMapManager.getMidiMapDevices());
*/
 
setChanged();
notifyObservers(midiReadDevices);
clearChanged();
midiWriteDevices = tempWriteDevices;
 
setChanged();
notifyObservers(midiWriteDevices);
clearChanged();
}
}
 
public void update(Observable observable, Object object) {
if (observable == midiDeviceManager
|| observable == midiRouterDeviceManager
|| observable == midiFilterManager
/* || observable == midiMapManager */) {
 
MidiDevice midiDevice = (MidiDevice) object;
 
if (midiReadDevices.contains(midiDevice)
|| midiWriteDevices.contains(midiDevice)) {
disconnectDevice(midiDevice);
removeMidiReadDevice(midiDevice);
removeMidiWriteDevice(midiDevice);
} else {
reorder();
}
}
}
 
public static class LogicalConnection {
 
private MidiDevice sourceDevice;
 
private MidiDevice targetDevice;
 
public LogicalConnection(MidiDevice sourceDevice,
MidiDevice targetDevice) {
this.sourceDevice = sourceDevice;
this.targetDevice = targetDevice;
}
 
public MidiDevice getSourceDevice() {
return sourceDevice;
}
 
public MidiDevice getTargetDevice() {
return targetDevice;
}
 
public boolean equals(Object object) {
if (object instanceof LogicalConnection) {
if (((LogicalConnection) object).getSourceDevice() == sourceDevice
&& ((LogicalConnection) object).getTargetDevice() == targetDevice) {
return true;
}
}
return false;
}
}
}
/trunk/java/org/midibox/midi/SysexFile.java
New file
0,0 → 1,78
/*
* @(#)SysexFile.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
 
public class SysexFile {
private byte[] data;
 
public boolean read(String sFilename) {
try {
 
File file = new File(sFilename);
 
InputStream is = new FileInputStream(file);
 
// Get the size of the file
long length = file.length();
 
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
 
// Create the byte array to hold the data
data = new byte[(int) length];
 
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < data.length
&& (numRead = is.read(data, offset, data.length - offset)) >= 0) {
offset += numRead;
}
 
// Ensure all the bytes have been read in
if (offset < data.length) {
throw new IOException("Could not completely read file "
+ file.getName());
}
 
// Close the input stream and return bytes
is.close();
} catch (Exception e) {
System.out.println(e.toString());
return false;
}
return true;
}
 
public byte[] getData() {
return data;
}
}
/trunk/java/org/midibox/midi/MidiActivityDevice.java
New file
0,0 → 1,41
/*
* @(#)MidiActivityDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiActivityDevice extends VirtualMidiDevice {
 
protected MidiActivity midiActivity;
 
public MidiActivityDevice(String name, MidiActivity midiActivity) {
super(name, 0, -1);
this.midiActivity = midiActivity;
}
 
public MidiActivity getMidiActivity() {
return midiActivity;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiActivity.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiParameterControlManager.java
New file
0,0 → 1,124
/*
* @(#)MidiParameterControlManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Observer;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
 
public class MidiParameterControlManager extends Observable implements
Observer, Receiver {
 
protected LinkedList midiParameters;
 
protected int globalChannel = 0;
 
protected Receiver receiver;
 
public MidiParameterControlManager(Receiver receiver, int globalChannel) {
this.globalChannel = globalChannel;
this.receiver = receiver;
midiParameters = new LinkedList();
}
 
public Receiver getReceiver() {
return receiver;
}
 
public void setReceiver(Receiver receiver) {
this.receiver = receiver;
 
Iterator it = midiParameters.iterator();
 
while (it.hasNext()) {
MidiParameterControl midiParameter = (MidiParameterControl) it
.next();
if (midiParameter.isGlobal()) {
midiParameter.setReceiver(receiver);
}
}
}
 
public LinkedList getMidiParameters() {
return midiParameters;
}
 
public void addMidiParameter(MidiParameter midiParameter) {
midiParameters.remove(midiParameter);
midiParameters.add(midiParameter);
midiParameter.deleteObserver(this);
midiParameter.addObserver(this);
}
 
public void removeMidiParameter(MidiParameter midiParameter) {
midiParameter.deleteObserver(this);
midiParameter.addObserver(this);
}
 
public int getGlobalChannel() {
return globalChannel;
}
 
public void setGlobalChannel(int globalChannel) {
this.globalChannel = globalChannel;
 
Iterator it = midiParameters.iterator();
 
while (it.hasNext()) {
MidiParameterControl midiParameter = (MidiParameterControl) it
.next();
if (midiParameter.isGlobal()) {
midiParameter.setMidiChannel(globalChannel);
}
}
 
setChanged();
notifyObservers();
clearChanged();
}
 
public void close() {
 
}
 
public void send(MidiMessage message, long timestamp) {
Object[] parametersArray = midiParameters.toArray();
 
for (int p = 0; p < parametersArray.length; p++) {
if (parametersArray[p] != null) {
((MidiParameter) parametersArray[p]).send(message, timestamp);
}
}
}
 
public void update(Observable observable, Object object) {
if (object == MidiParameterControl.GLOBAL) {
if (((MidiParameterControl) observable).isGlobal()) {
((MidiParameterControl) observable)
.setMidiChannel(globalChannel);
}
}
}
}
/trunk/java/org/midibox/midi/MidiMap.java
New file
0,0 → 1,35
/*
* @(#)MidiMap.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
 
public class MidiMap extends MidiParameterControlManager {
public MidiMap(Receiver receiver) {
super(receiver, 0);
}
 
// TODO: override
public void send(MidiMessage message, long timestamp) {
receiver.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiParameter.java
New file
0,0 → 1,480
/*
* @(#)MidiParameter.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
 
public class MidiParameter extends Observable implements Receiver {
 
public final static int NOTE_OFF = ShortMessage.NOTE_OFF;
 
public final static int NOTE_ON = ShortMessage.NOTE_ON;
 
public final static int AFTERTOUCH = ShortMessage.POLY_PRESSURE;
 
public final static int CONTROL_CHANGE = ShortMessage.CONTROL_CHANGE;
 
public final static int PROGRAM_CHANGE = ShortMessage.PROGRAM_CHANGE;
 
public final static int CHANNEL_PRESSURE = ShortMessage.CHANNEL_PRESSURE;
 
public final static int PITCH_BEND = ShortMessage.PITCH_BEND;
 
public final static Object STATUS = new Object();
 
public final static Object CHANNEL = new Object();
 
public final static Object NUMBER = new Object();
 
public final static Object VALUE = new Object();
 
public final static Object DEFAULT_VALUE = new Object();
 
public final static Object LEARN = new Object();
 
public final static Object HIGH_RESOLUTION = new Object();
 
protected Receiver receiver;
 
protected int channel;
 
protected int status;
 
protected int value;
 
protected int number;
 
protected int defaultValue;
 
protected int type;
 
protected boolean learn;
 
protected boolean highResolution;
 
public MidiParameter(Receiver receiver, int status, int channel,
int number, int value, int defaultValue) {
setReceiver(receiver);
setMidiStatus(status);
setMidiChannel(channel);
setMidiNumber(number);
setMidiValue(value, false);
setHighResolution(false);
setMidiDefaultValue(defaultValue);
}
 
public Receiver getReceiver() {
return receiver;
}
 
protected void setReceiver(Receiver receiver) {
this.receiver = receiver;
}
 
public int getMidiStatus() {
return status;
}
 
public void setMidiStatus(int status) {
 
this.status = status;
 
setChanged();
notifyObservers(STATUS);
clearChanged();
}
 
public int getMidiChannel() {
return channel;
}
 
public void setMidiChannel(int channel) {
 
this.channel = channel;
 
setChanged();
notifyObservers(CHANNEL);
clearChanged();
}
 
public int getMidiValue() {
return value & getMidiMaxValue();
}
 
public void setMidiValue(int value, boolean forward) {
 
this.value = value & getMidiMaxValue();
 
if (forward) {
createMessage();
}
 
setChanged();
notifyObservers(VALUE);
clearChanged();
}
 
public int getMidiMaxValue() {
 
int currentStatus = getMidiStatus();
 
if (currentStatus == PITCH_BEND
|| (currentStatus == CONTROL_CHANGE && highResolution)) {
return 16383;
} else {
return 127;
}
}
 
public String getMidiName() {
 
if (status == NOTE_ON || status == NOTE_OFF) {
return "Note " + MidiUtils.getKeyName(number);
} else if (status == AFTERTOUCH) {
return "Aftertouch " + MidiUtils.getKeyName(number);
} else if (status == CONTROL_CHANGE) {
if (highResolution) {
return MidiUtils.cc14BitNames[number];
} else {
return MidiUtils.ccNames[number];
}
} else if (status == PROGRAM_CHANGE) {
return "Program Change";
} else if (status == CHANNEL_PRESSURE) {
return "Channel Pressure";
} else if (status == PITCH_BEND) {
return "Pitch Bend";
} else {
return "undefined";
}
}
 
public int getMidiNumber() {
return number;
}
 
public void setMidiNumber(int number) {
this.number = number;
 
int currentStatus = getMidiStatus();
 
setChanged();
notifyObservers(NUMBER);
clearChanged();
}
 
public boolean isLearn() {
return learn;
}
 
public void setLearn(boolean learn) {
this.learn = learn;
 
setChanged();
notifyObservers(LEARN);
clearChanged();
}
 
public void createMessage() {
ShortMessage message = new ShortMessage();
if (receiver != null) {
try {
 
int data1 = 0;
int data2 = 0;
 
if (status == NOTE_ON || status == NOTE_OFF) {
data1 = number & 0x7F;
data2 = value & 0x7F;
} else if (status == AFTERTOUCH) {
data1 = number & 0x7F;
data2 = value & 0x7F;
} else if (status == CONTROL_CHANGE) {
 
if (highResolution
&& ((number < 64) || (number < 102 && number > 97))) {
 
int msbNumber;
int lsbNumber;
 
if (number < 64) {
if (number < 32) {
msbNumber = number;
lsbNumber = number + 32;
} else {
msbNumber = number - 32;
lsbNumber = number;
}
} else {
if (number % 2 == 0) {
msbNumber = number + 1;
lsbNumber = number;
} else {
msbNumber = number;
lsbNumber = number - 1;
}
}
 
int lsbValue = (value) & 0x7F;
int msbValue = (value >> 7) & 0x7F;
 
message
.setMessage(status, channel, msbNumber,
msbValue);
receiver.send(message, -1);
 
message = new ShortMessage();
 
message
.setMessage(status, channel, lsbNumber,
lsbValue);
receiver.send(message, -1);
 
return;
} else {
data1 = number & 0x7F;
data2 = value & 0x7F;
}
} else if (status == PROGRAM_CHANGE) {
data1 = value & 0x7F;
data2 = 0;
} else if (status == CHANNEL_PRESSURE) {
data1 = value & 0x7F;
data2 = 0;
} else if (status == PITCH_BEND) {
data1 = (value) & 0x7F;
data2 = (value >> 7) & 0x7F;
}
 
message.setMessage(status, channel, data1, data2);
receiver.send(message, -1);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
 
protected void midiLearn(MidiMessage message) {
if (message instanceof ShortMessage) {
 
setMidiChannel(((ShortMessage) message).getChannel());
 
int incomingStatus = ((ShortMessage) message).getCommand();
 
if (incomingStatus == NOTE_OFF || incomingStatus == NOTE_ON) {
 
setMidiStatus(NOTE_ON);
setMidiNumber(((ShortMessage) message).getData1());
setMidiDefaultValue(((ShortMessage) message).getData2());
 
} else if (incomingStatus == AFTERTOUCH) {
 
setMidiStatus(AFTERTOUCH);
setMidiNumber(((ShortMessage) message).getData1());
setMidiDefaultValue(((ShortMessage) message).getData2());
 
} else if (incomingStatus == CONTROL_CHANGE) {
setMidiStatus(CONTROL_CHANGE);
setMidiNumber(((ShortMessage) message).getData1());
if (highResolution
&& ((number < 64) || (number < 102 && number > 97))) {
if (number < 64) {
if (number < 32) {
setMidiValue(
((ShortMessage) message).getData2() << 7,
false);
} else {
setMidiValue(((ShortMessage) message).getData2(),
false);
}
} else {
if (number % 2 == 0) {
setMidiValue(((ShortMessage) message).getData2(),
false);
} else {
setMidiValue(
((ShortMessage) message).getData2() << 7,
false);
}
}
} else {
setMidiDefaultValue(((ShortMessage) message).getData2());
}
} else if (incomingStatus == PROGRAM_CHANGE) {
 
setMidiStatus(PROGRAM_CHANGE);
setMidiDefaultValue(((ShortMessage) message).getData1());
 
} else if (incomingStatus == CHANNEL_PRESSURE) {
 
setMidiStatus(CHANNEL_PRESSURE);
setMidiDefaultValue(((ShortMessage) message).getData1());
 
} else if (incomingStatus == PITCH_BEND) {
 
setMidiStatus(PITCH_BEND);
setMidiDefaultValue(((ShortMessage) message).getData1() & 0x7F
| (((ShortMessage) message).getData2() << 7));
 
}
}
}
 
public void send(MidiMessage message, long lTimeStamp) {
 
if (isLearn()) {
midiLearn(message);
setLearn(false);
} else {
if (message instanceof ShortMessage) {
 
if (channel == ((ShortMessage) message).getChannel()) {
 
int incomingStatus = ((ShortMessage) message).getCommand();
 
if ((incomingStatus == NOTE_OFF || incomingStatus == NOTE_ON)
&& (status == NOTE_OFF || status == NOTE_ON)) {
if (number == ((ShortMessage) message).getData1()) {
setMidiValue(incomingStatus == NOTE_OFF ? 0
: ((ShortMessage) message).getData2(),
false);
}
} else if ((incomingStatus == AFTERTOUCH)
&& (status == AFTERTOUCH)) {
if (number == ((ShortMessage) message).getData1()) {
setMidiValue(incomingStatus == NOTE_OFF ? 0
: ((ShortMessage) message).getData2(),
false);
}
} else if (incomingStatus == CONTROL_CHANGE
&& status == CONTROL_CHANGE) {
 
int incomingNumber = ((ShortMessage) message)
.getData1();
int incomingValue = ((ShortMessage) message).getData2();
 
if (highResolution
&& ((number < 64) || (number < 102 && number > 97))) {
 
if (number < 64) {
if (number < 32) {
if (incomingNumber == number) {
int newValue = value & 0x007F;
newValue = newValue
| incomingValue << 7;
setMidiValue(newValue, false);
} else if (incomingNumber == number + 32) {
int newValue = value & 0x3F80;
newValue = newValue | incomingValue;
setMidiValue(newValue, false);
}
} else {
if (incomingNumber == number) {
int newValue = value & 0x3F80;
newValue = newValue | incomingValue;
setMidiValue(newValue, false);
} else if (incomingNumber == number - 32) {
int newValue = value & 0x007F;
newValue = newValue
| incomingValue << 7;
setMidiValue(newValue, false);
}
}
} else {
if (number % 2 == 0) {
if (incomingNumber == number + 1) {
int newValue = value & 0x007F;
newValue = newValue
| incomingValue << 7;
setMidiValue(newValue, false);
} else if (incomingNumber == number) {
int newValue = value & 0x3F80;
newValue = newValue | incomingValue;
setMidiValue(newValue, false);
}
} else {
if (incomingNumber == number - 1) {
int newValue = value & 0x3F80;
newValue = newValue | incomingValue;
setMidiValue(newValue, false);
} else if (incomingNumber == number) {
int newValue = value & 0x007F;
newValue = newValue
| incomingValue << 7;
setMidiValue(newValue, false);
}
}
}
} else {
if (number == incomingNumber) {
setMidiValue(incomingValue, false);
}
}
} else if (incomingStatus == PROGRAM_CHANGE
&& status == PROGRAM_CHANGE) {
setMidiValue(((ShortMessage) message).getData1(), false);
} else if (incomingStatus == CHANNEL_PRESSURE
&& status == CHANNEL_PRESSURE) {
setMidiValue(((ShortMessage) message).getData1(), false);
} else if (incomingStatus == PITCH_BEND
&& status == PITCH_BEND) {
setMidiValue(((ShortMessage) message).getData1() & 0x7F
| (((ShortMessage) message).getData2() << 7),
false);
}
}
}
}
}
 
public int getMidiDefaultValue() {
return defaultValue & getMidiMaxValue();
}
 
public void setMidiDefaultValue(int value) {
 
this.defaultValue = value & getMidiMaxValue();
 
setChanged();
notifyObservers(DEFAULT_VALUE);
clearChanged();
}
 
public void close() {
 
}
 
public boolean isHighResolution() {
return highResolution;
}
 
public void setHighResolution(boolean highResolution) {
this.highResolution = highResolution;
 
setChanged();
notifyObservers(HIGH_RESOLUTION);
clearChanged();
}
}
/trunk/java/org/midibox/midi/MidiParameterControl.java
New file
0,0 → 1,136
/*
* @(#)MidiParameterControl.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
 
public class MidiParameterControl extends MidiParameter {
 
public final static Object RECEIVE = new Object();
 
public final static Object SEND = new Object();
 
public final static Object GLOBAL = new Object();
 
public final static int RANGE = 0;
 
public final static int BOOLEAN = 1;
 
protected boolean receive;
 
protected boolean send;
 
protected boolean global;
 
protected boolean highResolution;
 
public MidiParameterControl(int type, Receiver receiver, int status,
int channel, int number, int value, int defaultValue) {
super(receiver, status, channel, number, value, defaultValue);
setType(type);
setGlobal(true);
setReceive(true);
setSend(true);
}
 
public boolean isReceive() {
return receive;
}
 
public void setReceive(boolean respond) {
this.receive = respond;
 
setChanged();
notifyObservers(RECEIVE);
clearChanged();
}
 
public boolean isSend() {
return send;
}
 
public void setSend(boolean send) {
this.send = send;
 
setChanged();
notifyObservers(SEND);
clearChanged();
}
 
public boolean isGlobal() {
return global;
}
 
public void setGlobal(boolean global) {
 
this.global = global;
 
setChanged();
notifyObservers(GLOBAL);
clearChanged();
}
 
protected void midiLearn(MidiMessage message) {
if (message instanceof ShortMessage) {
setGlobal(false);
super.midiLearn(message);
}
}
 
public int getType() {
return type;
}
 
public void setType(int type) {
this.type = type;
}
 
public void setMidiValue(int value, boolean forward) {
 
if (type != RANGE) {
value = (value > 0) ? getMidiDefaultValue() : 0;
}
 
super.setMidiValue(value, forward);
}
 
public boolean isMidiValueOn() {
return getMidiValue() > 0;
}
 
public void setMidiValueOn(boolean on, boolean forward) {
setMidiValue(on ? 1 : 0, forward);
}
 
public void createMessage() {
if (send) {
super.createMessage();
}
}
 
public void send(MidiMessage message, long lTimeStamp) {
if (receive) {
super.send(message, lTimeStamp);
}
}
}
/trunk/java/org/midibox/midi/MidiKeyboardControllerDevice.java
New file
0,0 → 1,42
/*
* @(#)MidiKeyboardControllerDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiKeyboardControllerDevice extends VirtualMidiDevice {
 
protected MidiKeyboardController midiKeyboardController;
 
public MidiKeyboardControllerDevice(String name, int globalChannel) {
super(name, -1, -1);
this.midiKeyboardController = new MidiKeyboardController(midiOutPort,
globalChannel);
}
 
public MidiKeyboardController getMidiKeyboardController() {
return midiKeyboardController;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiKeyboardController.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiFilter.java
New file
0,0 → 1,225
/*
* @(#)MidiFilter.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;
 
public class MidiFilter implements Receiver {
 
protected Receiver receiver;
 
// voice messages
public boolean noteOff = true;
 
public boolean noteOn = true;
 
public boolean pollyPressure = true;
 
public boolean controlChange = true;
 
public boolean programChange = true;
 
public boolean channelPressure = true;
 
public boolean pitchBend = true;
 
// sysex messages
public boolean sysexMessage = true;
 
// system common
public boolean midiTimeCode = true;
 
public boolean songPositionPointer = true;
 
public boolean songSelect = true;
 
public boolean tuneRequest = true;
 
// system realtime
public boolean timingClock = true;
 
public boolean start = true;
 
public boolean continueMessage = true;
 
public boolean stop = true;
 
public boolean activeSensing = true;
 
public boolean systemReset = true;
 
// meta messages
public boolean metaMessage = true;
 
// control change
 
public boolean[] cc = new boolean[128];
 
// channels
public boolean[] channel = new boolean[16];
 
public MidiFilter(Receiver receiver) {
 
this.receiver = receiver;
 
for (int i = 0; i < cc.length; i++) {
cc[i] = true;
}
 
for (int i = 0; i < channel.length; i++) {
channel[i] = true;
}
}
 
public void close() {
 
}
 
public void send(MidiMessage message, long timestamp) {
 
// meta messages
if (message instanceof MetaMessage) {
if (!metaMessage)
return;
}
 
// sysex messages
else if (message instanceof SysexMessage) {
if (!sysexMessage)
return;
}
 
else {
 
int status = ((ShortMessage) message).getCommand();
 
switch (status) {
 
// voice messages
case ShortMessage.NOTE_OFF:
if (!noteOff)
return;
break;
 
case ShortMessage.NOTE_ON:
if (!noteOn)
return;
break;
 
case ShortMessage.POLY_PRESSURE:
if (!pollyPressure)
return;
break;
 
case ShortMessage.CONTROL_CHANGE:
if (controlChange) {
if (!cc[((ShortMessage) message).getData1()]) {
return;
}
} else {
return;
}
break;
 
case ShortMessage.PROGRAM_CHANGE:
if (!programChange)
return;
break;
 
case ShortMessage.CHANNEL_PRESSURE:
if (!channelPressure)
return;
break;
 
case ShortMessage.PITCH_BEND:
if (!pitchBend)
return;
break;
 
// system common
case ShortMessage.MIDI_TIME_CODE:
if (!midiTimeCode)
return;
break;
 
case ShortMessage.SONG_POSITION_POINTER:
if (!songPositionPointer)
return;
break;
 
case ShortMessage.SONG_SELECT:
if (!songSelect)
return;
break;
 
case ShortMessage.TUNE_REQUEST:
if (!tuneRequest)
return;
break;
 
// system realtime
case ShortMessage.TIMING_CLOCK:
if (!timingClock)
return;
break;
 
case ShortMessage.START:
if (!start)
return;
break;
 
case ShortMessage.CONTINUE:
if (!continueMessage)
return;
break;
 
case ShortMessage.STOP:
if (!stop)
return;
break;
 
case ShortMessage.ACTIVE_SENSING:
if (!activeSensing)
return;
break;
 
case ShortMessage.SYSTEM_RESET:
if (!systemReset)
return;
break;
 
}
 
// channels
if (!channel[((ShortMessage) message).getChannel()]) {
return;
}
}
 
if (receiver != null) {
receiver.send(message, timestamp);
}
}
}
/trunk/java/org/midibox/midi/SysexSendReceive.java
New file
0,0 → 1,116
/*
* @(#)SysexSendReceive.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.io.File;
import java.util.LinkedList;
import java.util.Observable;
 
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.SysexMessage;
 
public class SysexSendReceive extends Observable implements Receiver {
 
protected Receiver receiver;
 
protected File file;
 
protected long fileLastModified;
 
protected SysexFile sysexFile;
 
protected SysexSendReceiveWorkerTask sysexSendReceiveWorkerTask;
 
protected int sendBufferSize;
 
protected LinkedList receivedBytes;
 
public SysexSendReceive(Receiver receiver) {
super();
this.receiver = receiver;
sendBufferSize = 256;
receivedBytes = new LinkedList();
}
 
public File getFile() {
return file;
}
 
public boolean fileChanged() {
return file.lastModified() != fileLastModified;
}
 
public void setFile(File file) {
this.file = file;
fileLastModified = file.lastModified();
 
readSysexFile();
 
setChanged();
notifyObservers(file);
clearChanged();
}
 
public void readSysexFile() {
sysexFile = new SysexFile();
if (!sysexFile.read(file.getPath())) {
// TODO
}
}
 
public SysexFile getSysexFile() {
return sysexFile;
}
 
public int getSendBufferSize() {
return sendBufferSize;
}
 
public void setSendBufferSize(int sendBufferSize) {
this.sendBufferSize = sendBufferSize;
}
 
public LinkedList getReceivedBytes() {
return receivedBytes;
}
 
public void send(MidiMessage message, long timestamp) {
if (message instanceof SysexMessage) {
receivedBytes.add(((SysexMessage) message).getData());
 
setChanged();
notifyObservers(receivedBytes);
clearChanged();
}
}
 
public void close() {
 
}
 
public class SysexSendReceiveWorkerTask extends Thread {
 
public void run() {
 
}
}
}
/trunk/java/org/midibox/midi/MidiMonitorFilteredDevice.java
New file
0,0 → 1,48
/*
* @(#)MidiMonitorFilteredDevice.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiMonitorFilteredDevice extends VirtualMidiDevice {
 
protected MidiMonitorFiltered midiMonitorFiltered;
 
public MidiMonitorFilteredDevice(String name) {
 
this(name, new MidiMonitorFiltered());
 
}
 
public MidiMonitorFilteredDevice(String name,
MidiMonitorFiltered midiMonitorFiltered) {
super(name, 0, -1);
this.midiMonitorFiltered = midiMonitorFiltered;
}
 
public MidiMonitorFiltered getMidiMonitorFiltered() {
return midiMonitorFiltered;
}
 
protected void receiveFromReceivers(MidiMessage message, long timestamp) {
midiMonitorFiltered.send(message, timestamp);
}
}
/trunk/java/org/midibox/midi/MidiMonitor.java
New file
0,0 → 1,332
/*
* @(#)MidiMonitor.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
* Based on DumpReceiver.java. Original copyright below:
****************************************************************************
* DumpReceiver.java
*
* This file is part of jsresources.org
* Copyright (c) 1999 - 2001 by Matthias Pfisterer
* Copyright (c) 2003 by Florian Bomers
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
package org.midibox.midi;
 
import java.util.LinkedList;
import java.util.Observable;
 
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;
 
public class MidiMonitor extends Observable implements Receiver {
 
public static long seByteCount = 0;
 
public static long seCount = 0;
 
public static long smCount = 0;
 
private boolean _bPrintTimeStampAsTicks;
 
private LinkedList receivedMessages;
 
public MidiMonitor() {
super();
_bPrintTimeStampAsTicks = false;
receivedMessages = new LinkedList();
}
 
public void close() {
 
}
 
public LinkedList getReceivedMessages() {
return receivedMessages;
}
 
public void send(MidiMessage message, long lTimeStamp) {
receivedMessages.add(new MidiMessageReceived(message, lTimeStamp));
 
setChanged();
notifyObservers(receivedMessages);
clearChanged();
}
 
// TK: cheap version to create the timestamp string from a long (time base
// uS)
private String long2mS(long l) {
Long l_ms = new Long(l / 1000);
String l_str_ms = l_ms.toString();
return ("00000000000000" + l_str_ms).substring(l_str_ms.length());
}
 
public String decodeMessage(MidiMessage message, long lTimeStamp) {
String strMessage = null;
 
if (message instanceof ShortMessage) {
strMessage = decodeMessage((ShortMessage) message);
} else if (message instanceof SysexMessage) {
strMessage = decodeMessage((SysexMessage) message);
} else if (message instanceof MetaMessage) {
strMessage = decodeMessage((MetaMessage) message);
} else {
strMessage = "unknown message type";
}
String strTimeStamp = null;
if (_bPrintTimeStampAsTicks) {
strTimeStamp = "tick " + lTimeStamp + ": ";
} else {
if (lTimeStamp == -1L) {
strTimeStamp = "timestamp [unknown] | ";
} else {
strTimeStamp = long2mS(lTimeStamp) + " ms | ";
}
}
 
// return null if message is empty (required for filtered SysEx
// messages)
return (strMessage == null) ? null : strTimeStamp + strMessage;
}
 
public String decodeMessage(ShortMessage message) {
String strMessage = null;
switch (message.getCommand()) {
case 0x80:
strMessage = "Note Off " + MidiUtils.getKeyName(message.getData1())
+ " velocity: " + message.getData2();
break;
 
case 0x90:
strMessage = "Note On " + MidiUtils.getKeyName(message.getData1())
+ " velocity: " + message.getData2();
break;
 
case 0xa0:
strMessage = "Aftertouch "
+ MidiUtils.getKeyName(message.getData1()) + " pressure: "
+ message.getData2();
break;
 
case 0xb0:
strMessage = "CC " + MidiUtils.ccNames[message.getData1()]
+ " value: " + message.getData2();
break;
 
case 0xc0:
strMessage = "Program Change no: " + message.getData1();
break;
 
case 0xd0:
strMessage = "Channel Pressure value: " + message.getData1();
break;
 
case 0xe0:
strMessage = "Pitch Bend value: "
+ MidiUtils.get14bitValue(message.getData1(), message
.getData2());
break;
 
case 0xF0:
strMessage = MidiUtils.SYSTEM_MESSAGE_TEXT[message.getChannel()];
switch (message.getChannel()) {
case 0x1:
int nQType = (message.getData1() & 0x70) >> 4;
int nQData = message.getData1() & 0x0F;
if (nQType == 7) {
nQData = nQData & 0x1;
}
strMessage += MidiUtils.QUARTER_FRAME_MESSAGE_TEXT[nQType]
+ nQData;
if (nQType == 7) {
int nFrameType = (message.getData1() & 0x06) >> 1;
strMessage += ", frame type: "
+ MidiUtils.FRAME_TYPE_TEXT[nFrameType];
}
break;
 
case 0x2:
strMessage += MidiUtils.get14bitValue(message.getData1(),
message.getData2());
break;
 
case 0x3:
strMessage += message.getData1();
break;
}
break;
 
default:
strMessage = "unknown message: status = " + message.getStatus()
+ ", byte1 = " + message.getData1() + ", byte2 = "
+ message.getData2();
break;
}
if (message.getCommand() != 0xF0) {
int nChannel = message.getChannel() + 1;
String strChannel = "Channel " + nChannel + ": ";
strMessage = strChannel + strMessage;
}
smCount++;
return "[" + MidiUtils.getHexString(message) + "] " + strMessage;
}
 
public String decodeMessage(SysexMessage message) {
byte[] abData = message.getData();
String strMessage = null;
// System.out.println("sysex status: " + message.getStatus());
if (message.getStatus() == SysexMessage.SYSTEM_EXCLUSIVE) {
strMessage = "SysEx: F0 " + MidiUtils.getHexString(abData);
} else if (message.getStatus() == SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) {
strMessage = "Continued SysEx: F7 "
+ MidiUtils.getHexString(abData);
seByteCount--; // do not count the F7
}
seByteCount += abData.length + 1;
seCount++; // for the status byte
return strMessage;
}
 
public String decodeMessage(MetaMessage message) {
byte[] abData = message.getData();
String strMessage = null;
// System.out.println("data array length: " + abData.length);
switch (message.getType()) {
case 0:
int nSequenceNumber = ((abData[0] & 0xFF) << 8)
| (abData[1] & 0xFF);
strMessage = "Sequence Number: " + nSequenceNumber;
break;
 
case 1:
String strText = new String(abData);
strMessage = "Text Event: " + strText;
break;
 
case 2:
String strCopyrightText = new String(abData);
strMessage = "Copyright Notice: " + strCopyrightText;
break;
 
case 3:
String strTrackName = new String(abData);
strMessage = "Sequence/Track Name: " + strTrackName;
break;
 
case 4:
String strInstrumentName = new String(abData);
strMessage = "Instrument Name: " + strInstrumentName;
break;
 
case 5:
String strLyrics = new String(abData);
strMessage = "Lyric: " + strLyrics;
break;
 
case 6:
String strMarkerText = new String(abData);
strMessage = "Marker: " + strMarkerText;
break;
 
case 7:
String strCuePointText = new String(abData);
strMessage = "Cue Point: " + strCuePointText;
break;
 
case 0x20:
int nChannelPrefix = abData[0] & 0xFF;
strMessage = "MIDI Channel Prefix: " + nChannelPrefix;
break;
 
case 0x2F:
strMessage = "End of Track";
break;
 
case 0x51:
int nTempo = ((abData[0] & 0xFF) << 16) | ((abData[1] & 0xFF) << 8)
| (abData[2] & 0xFF); // tempo in microseconds per beat
float bpm = MidiUtils.convertTempo(nTempo);
// truncate it to 2 digits after dot
bpm = (float) (Math.round(bpm * 100.0f) / 100.0f);
strMessage = "Set Tempo: " + bpm + " bpm";
break;
 
case 0x54:
// System.out.println("data array length: " + abData.length);
strMessage = "SMTPE Offset: " + (abData[0] & 0xFF) + ":"
+ (abData[1] & 0xFF) + ":" + (abData[2] & 0xFF) + "."
+ (abData[3] & 0xFF) + "." + (abData[4] & 0xFF);
break;
 
case 0x58:
strMessage = "Time Signature: " + (abData[0] & 0xFF) + "/"
+ (1 << (abData[1] & 0xFF))
+ ", MIDI clocks per metronome tick: " + (abData[2] & 0xFF)
+ ", 1/32 per 24 MIDI clocks: " + (abData[3] & 0xFF);
break;
 
case 0x59:
String strGender = (abData[1] == 1) ? "minor" : "major";
strMessage = "Key Signature: "
+ MidiUtils.s_astrKeySignatures[abData[0] + 7] + " "
+ strGender;
break;
 
case 0x7F:
// TODO: decode vendor code, dump data in rows
String strDataDump = MidiUtils.getHexString(abData);
strMessage = "Sequencer-Specific Meta event: " + strDataDump;
break;
 
default:
String strUnknownDump = MidiUtils.getHexString(abData);
strMessage = "unknown Meta event: " + strUnknownDump;
break;
 
}
return strMessage;
}
}
/trunk/java/org/midibox/midi/MidiMapDeviceManager.java
New file
0,0 → 1,59
/*
* @(#)MidiMapDeviceManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
import java.util.Vector;
 
public class MidiMapDeviceManager extends Observable {
 
private Vector midiMapDevices;
 
private int midiMapDeviceNo;
 
public MidiMapDeviceManager() {
midiMapDevices = new Vector();
}
 
public MidiMapDevice addMidiMapDevice() {
MidiMapDevice midiMapDevice = new MidiMapDevice("Map "
+ ++midiMapDeviceNo);
midiMapDevices.add(midiMapDevice);
 
setChanged();
notifyObservers(midiMapDevice);
clearChanged();
 
return midiMapDevice;
}
 
public void removeMidiMapDevice(MidiMapDevice midiMapDevice) {
midiMapDevices.remove(midiMapDevice);
 
setChanged();
notifyObservers(midiMapDevice);
clearChanged();
}
 
public Vector getMidiMapDevices() {
return midiMapDevices;
}
}
/trunk/java/org/midibox/midi/MidiDeviceManager.java
New file
0,0 → 1,133
/*
* @(#)MidiDeviceManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
import java.util.Vector;
 
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequencer;
import javax.sound.midi.Synthesizer;
 
public class MidiDeviceManager extends Observable {
 
private Vector midiReadDevices;
 
private Vector midiWriteDevices;
 
private Vector selectedMidiReadDevices;
 
private Vector selectedMidiWriteDevices;
 
public MidiDeviceManager() {
midiReadDevices = new Vector();
midiWriteDevices = new Vector();
selectedMidiReadDevices = new Vector();
selectedMidiWriteDevices = new Vector();
rescanDevices();
}
 
public Vector getMidiReadDevices() {
return midiReadDevices;
}
 
public Vector getMidiWriteDevices() {
return midiWriteDevices;
}
 
public Vector getSelectedMidiReadDevices() {
return selectedMidiReadDevices;
}
 
public Vector getSelectedMidiWriteDevices() {
return selectedMidiWriteDevices;
}
 
public void selectMidiReadDevice(MidiDevice midiDevice) {
selectedMidiReadDevices.remove(midiDevice);
selectedMidiReadDevices.add(midiDevice);
 
setChanged();
notifyObservers(midiDevice);
clearChanged();
}
 
public void selectMidiWriteDevice(MidiDevice midiDevice) {
selectedMidiWriteDevices.remove(midiDevice);
selectedMidiWriteDevices.add(midiDevice);
 
setChanged();
notifyObservers(midiDevice);
clearChanged();
}
 
public void deselectMidiReadDevice(MidiDevice midiDevice) {
selectedMidiReadDevices.remove(midiDevice);
 
setChanged();
notifyObservers(midiDevice);
clearChanged();
}
 
public void deselectMidiWriteDevice(MidiDevice midiDevice) {
selectedMidiWriteDevices.remove(midiDevice);
 
setChanged();
notifyObservers(midiDevice);
clearChanged();
}
 
public void rescanDevices() {
 
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
 
for (int i = 0; i < infos.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
 
if (!(device instanceof Sequencer)
&& !(device instanceof Synthesizer)) {
 
int noReceivers = device.getMaxReceivers();
int noTransmitters = device.getMaxTransmitters();
 
if (noReceivers != 0) {
if (!midiWriteDevices.contains(device)) {
midiWriteDevices.add(device);
selectMidiWriteDevice(device);
}
}
 
if (noTransmitters != 0) {
if (!midiReadDevices.contains(device)) {
midiReadDevices.add(device);
selectMidiReadDevice(device);
}
}
}
} catch (MidiUnavailableException e) {
 
}
}
}
}
/trunk/java/org/midibox/midi/MidiMessageReceived.java
New file
0,0 → 1,35
/*
* @(#)MidiMessageReceived.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import javax.sound.midi.MidiMessage;
 
public class MidiMessageReceived {
 
public MidiMessage midiMessage;
 
public long timeStamp;
 
public MidiMessageReceived(MidiMessage midiMessage, long timeStamp) {
this.midiMessage = midiMessage;
this.timeStamp = timeStamp;
}
}
/trunk/java/org/midibox/midi/MidiRouterDeviceManager.java
New file
0,0 → 1,58
/*
* @(#)MidiRouterDeviceManager.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.midi;
 
import java.util.Observable;
import java.util.Vector;
 
public class MidiRouterDeviceManager extends Observable {
private Vector midiRouterDevices;
 
private int routerNo;
 
public MidiRouterDeviceManager() {
midiRouterDevices = new Vector();
}
 
public MidiRouterDevice addMidiRouterDevice() {
MidiRouterDevice midiRouterDevice = new MidiRouterDevice(
"Virtual Port " + ++routerNo);
midiRouterDevices.add(midiRouterDevice);
 
setChanged();
notifyObservers(midiRouterDevice);
clearChanged();
 
return midiRouterDevice;
}
 
public void removeMidiRouter(MidiRouterDevice midiRouterDevice) {
midiRouterDevices.remove(midiRouterDevice);
 
setChanged();
notifyObservers(midiRouterDevice);
clearChanged();
}
 
public Vector getMidiRouterDevices() {
return midiRouterDevices;
}
}
/trunk/java/org/midibox/apps/miosstudio/MIOSStudio.java
New file
0,0 → 1,457
/*
* @(#)MIOSStudio.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.apps.miosstudio;
 
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
 
import org.midibox.midi.MidiDeviceRouting;
import org.midibox.midi.MidiFilterDevice;
import org.midibox.midi.MidiKeyboardControllerDevice;
import org.midibox.midi.MidiMonitorFiltered;
import org.midibox.midi.MidiMonitorFilteredDevice;
import org.midibox.midi.MidiRouterDevice;
import org.midibox.mios.DebugFunctionDevice;
import org.midibox.mios.HexFileUploadDevice;
import org.midibox.mios.HexFileUploadDeviceManager;
import org.midibox.mios.LCDMessageDevice;
import org.midibox.mios.MIOSTerminal;
 
public class MIOSStudio implements Observer {
 
protected MidiDeviceRouting midiDeviceRouting;
 
protected MidiRouterDevice miosStudioInPort;
 
protected MidiFilterDevice midiThruFilterDevice;
 
// TODO: implement a map for MIDI thru
 
/*
* private MidiMapDevice midiThruMapDevice;
*/
 
protected MidiRouterDevice miosStudioOutPort;
 
private MidiMonitorFilteredDevice midiInPortMonitorDevice;
 
private MidiMonitorFilteredDevice midiOutPortMonitorDevice;
 
// Debuging for command line
 
/*
* private DumpReceiverDevice inDumpReceiverDevice;
*
* private DumpReceiverDevice outDumpReceiverDevice;
*/
 
private MidiKeyboardControllerDevice midiKeyboardControllerDevice;
 
// TODO: implement a manager for sysex sending and receing tasks
 
/*
* private SysexSendReceiveDeviceManager sysexSendReceiveDeviceManager;
*/
 
private HexFileUploadDeviceManager hexFileUploadDeviceManager;
 
// TODO: implement a device for reading and writing to MIOS
 
/*
* private MemoryReadWriteDevice memoryReadWriteDevice;
*/
 
private LCDMessageDevice lcdMessageDevice;
 
private DebugFunctionDevice debugFunctionDevice;
 
private MidiMonitorFilteredDevice miosTerminalDevice;
 
private boolean routeIndividualDevices;
 
private boolean midiThru;
 
public MIOSStudio() {
 
createDevices();
 
midiThru = false;
 
setRouteIndividualDevices(false);
 
connectDevices();
}
 
protected void createDevices() {
 
midiDeviceRouting = new MidiDeviceRouting();
 
miosStudioInPort = new MidiRouterDevice("MIOS Studio In Port");
 
miosStudioOutPort = new MidiRouterDevice("MIOS Studio Out Port");
 
midiThruFilterDevice = new MidiFilterDevice("MIOS Studio Thru Filter");
 
/*
* midiThruMapDevice = new MidiMapDevice("MIOS Studio Thru Map");
*/
 
midiInPortMonitorDevice = new MidiMonitorFilteredDevice(
"MIDI Monitor: IN");
 
midiOutPortMonitorDevice = new MidiMonitorFilteredDevice(
"MIDI Monitor: OUT");
 
/*
* inDumpReceiverDevice = new DumpReceiverDevice("Dump Receiver: IN");
*
* outDumpReceiverDevice = new DumpReceiverDevice("Dump Receiver: OUT");
*/
 
midiKeyboardControllerDevice = new MidiKeyboardControllerDevice(
"MIDI Keyboard Controller", 0);
 
/*
* sysexSendReceiveDeviceManager = new SysexSendReceiveDeviceManager();
* sysexSendReceiveDeviceManager.newSysexSendReceive();
* sysexSendReceiveDeviceManager.addObserver(this);
*/
 
hexFileUploadDeviceManager = new HexFileUploadDeviceManager();
hexFileUploadDeviceManager.newHexFileUploadDevice();
hexFileUploadDeviceManager.addObserver(this);
 
/*
* memoryReadWriteDevice = new MemoryReadWriteDevice( "MIOS Memory
* Read/Write");
*/
 
lcdMessageDevice = new LCDMessageDevice("MIOS LCD Message");
 
debugFunctionDevice = new DebugFunctionDevice("MIOS Debug Function");
 
MidiMonitorFiltered miosTerminalFiltered = new MidiMonitorFiltered(
new MIOSTerminal());
 
miosTerminalDevice = new MidiMonitorFilteredDevice("MIOS Terminal",
miosTerminalFiltered);
 
// special for MIOS Terminal:
// disable all messages by default, only allow pass SysEx
// user can enable other MIDI events again if required
miosTerminalFiltered.getMidiFilter().sysexMessage = true;
 
miosTerminalFiltered.getMidiFilter().metaMessage = false;
miosTerminalFiltered.getMidiFilter().activeSensing = false;
miosTerminalFiltered.getMidiFilter().channelPressure = false;
miosTerminalFiltered.getMidiFilter().continueMessage = false;
miosTerminalFiltered.getMidiFilter().controlChange = false;
miosTerminalFiltered.getMidiFilter().midiTimeCode = false;
miosTerminalFiltered.getMidiFilter().noteOff = false;
miosTerminalFiltered.getMidiFilter().noteOn = false;
miosTerminalFiltered.getMidiFilter().pitchBend = false;
miosTerminalFiltered.getMidiFilter().pollyPressure = false;
miosTerminalFiltered.getMidiFilter().programChange = false;
miosTerminalFiltered.getMidiFilter().songPositionPointer = false;
miosTerminalFiltered.getMidiFilter().songSelect = false;
miosTerminalFiltered.getMidiFilter().start = false;
miosTerminalFiltered.getMidiFilter().stop = false;
miosTerminalFiltered.getMidiFilter().systemReset = false;
miosTerminalFiltered.getMidiFilter().timingClock = false;
miosTerminalFiltered.getMidiFilter().tuneRequest = false;
}
 
public MidiDeviceRouting getMidiDeviceRouting() {
return midiDeviceRouting;
}
 
public MidiMonitorFilteredDevice getMidiOutPortMonitorDevice() {
return midiOutPortMonitorDevice;
}
 
public MidiMonitorFilteredDevice getMidiInPortMonitorDevice() {
return midiInPortMonitorDevice;
}
 
public MidiKeyboardControllerDevice getMidiKeyboardControllerDevice() {
return midiKeyboardControllerDevice;
}
 
/*
* public SysexSendReceiveDeviceManager getSysexSendReceiveDeviceManager() {
* return sysexSendReceiveDeviceManager; }
*/
 
public HexFileUploadDeviceManager getHexFileUploadDeviceManager() {
return hexFileUploadDeviceManager;
}
 
public DebugFunctionDevice getDebugFunctionDevice() {
return debugFunctionDevice;
}
 
/*
* public MemoryReadWriteDevice getMemoryReadWriteDevice() { return
* memoryReadWriteDevice; }
*/
 
public LCDMessageDevice getLcdMessageDevice() {
return lcdMessageDevice;
}
 
public MidiMonitorFilteredDevice getMIOSTerminalDevice() {
return miosTerminalDevice;
}
 
public boolean isMidiThru() {
return midiThru;
}
 
public void setMidiThru(boolean midiThru) {
this.midiThru = midiThru;
 
if (midiThru) {
midiDeviceRouting.connectDevices(miosStudioInPort,
midiThruFilterDevice);
/*
* midiDeviceRouting.connectDevices(midiThruFilterDevice,
* midiThruMapDevice);
*/
 
midiDeviceRouting.connectDevices(midiThruFilterDevice,
miosStudioOutPort);
} else {
midiDeviceRouting.disconnectDevices(miosStudioInPort,
midiThruFilterDevice);
/*
* midiDeviceRouting.disconnectDevices(midiThruFilterDevice,
* midiThruMapDevice);
*/
 
midiDeviceRouting.disconnectDevices(midiThruFilterDevice,
miosStudioOutPort);
}
}
 
public MidiRouterDevice getMiosStudioInPort() {
return miosStudioInPort;
}
 
public MidiRouterDevice getMiosStudioOutPort() {
return miosStudioOutPort;
}
 
public MidiFilterDevice getMidiThruFilterDevice() {
return midiThruFilterDevice;
}
 
/*
* public MidiMapDevice getMidiThruMapDevice() { return midiThruMapDevice; }
*/
 
public boolean isRouteIndividualDevices() {
return routeIndividualDevices;
}
 
public void setRouteIndividualDevices(boolean routeIndividualDevices) {
this.routeIndividualDevices = routeIndividualDevices;
 
// remove all devices
midiDeviceRouting.removeAllMidiReadDevices();
midiDeviceRouting.removeAllMidiWriteDevices();
 
// add internal MIOSStudio devices if selected
if (routeIndividualDevices) {
 
routeIndividualDevices();
 
} else {
midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
midiDeviceRouting.addMidiReadDevice(miosStudioOutPort);
}
 
// get midiDeviceRouting to add physical, virtual, filters and maps
midiDeviceRouting.reorder();
}
 
protected void routeIndividualDevices() {
 
midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
midiDeviceRouting.addMidiReadDevice(miosStudioInPort);
 
midiDeviceRouting.addMidiWriteDevice(midiThruFilterDevice);
midiDeviceRouting.addMidiReadDevice(midiThruFilterDevice);
 
/*
* midiDeviceRouting.addMidiWriteDevice(midiThruMapDevice);
* midiDeviceRouting.addMidiReadDevice(midiThruMapDevice);
*/
 
midiDeviceRouting.addMidiWriteDevice(miosStudioOutPort);
midiDeviceRouting.addMidiReadDevice(miosStudioOutPort);
 
midiDeviceRouting.addMidiWriteDevice(midiOutPortMonitorDevice);
 
midiDeviceRouting.addMidiWriteDevice(midiInPortMonitorDevice);
 
/*
* midiDeviceRouting.addMidiWriteDevice(inDumpReceiverDevice);
*
* midiDeviceRouting.addMidiWriteDevice(outDumpReceiverDevice);
*/
 
midiDeviceRouting.addMidiWriteDevice(midiKeyboardControllerDevice);
midiDeviceRouting.addMidiReadDevice(midiKeyboardControllerDevice);
 
/*
* midiDeviceRouting.addMidiReadDevices(sysexSendReceiveDeviceManager
* .getSysexSendReceiveDevices()); midiDeviceRouting.addMidiWriteDevices
* (sysexSendReceiveDeviceManager .getSysexSendReceiveDevices());
*/
 
midiDeviceRouting.addMidiReadDevices(hexFileUploadDeviceManager
.getHexFileUploadDevices());
midiDeviceRouting.addMidiWriteDevices(hexFileUploadDeviceManager
.getHexFileUploadDevices());
/*
* midiDeviceRouting.addMidiWriteDevice(memoryReadWriteDevice);
* midiDeviceRouting.addMidiReadDevice(memoryReadWriteDevice);
*/
 
midiDeviceRouting.addMidiReadDevice(lcdMessageDevice);
 
midiDeviceRouting.addMidiWriteDevice(debugFunctionDevice);
midiDeviceRouting.addMidiReadDevice(debugFunctionDevice);
 
midiDeviceRouting.addMidiWriteDevice(miosTerminalDevice);
}
 
public void connectDevices() {
 
midiDeviceRouting.connectDevices(miosStudioInPort,
midiInPortMonitorDevice);
 
midiDeviceRouting.connectDevices(miosStudioOutPort,
midiOutPortMonitorDevice);
 
/*
* midiDeviceRouting.connectDevices(inVirtualMidiPortDevice,
* inDumpReceiverDevice);
* midiDeviceRouting.connectDevices(outVirtualMidiPortDevice,
* outDumpReceiverDevice);
*/
 
setMidiThru(midiThru);
 
midiDeviceRouting.connectDevices(miosStudioInPort,
midiKeyboardControllerDevice);
midiDeviceRouting.connectDevices(midiKeyboardControllerDevice,
miosStudioOutPort);
/*
* Iterator it = sysexSendReceiveDeviceManager
* .getSysexSendReceiveDevices().iterator(); while (it.hasNext()) {
* SysexSendReceiveDevice ssrt = (SysexSendReceiveDevice) it.next();
* midiDeviceRouting.connectDevices(miosStudioInPort, ssrt);
* midiDeviceRouting.connectDevices(ssrt, miosStudioOutPort); }
*/
Iterator it = hexFileUploadDeviceManager.getHexFileUploadDevices()
.iterator();
while (it.hasNext()) {
HexFileUploadDevice hutd = (HexFileUploadDevice) it.next();
midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
}
/*
* midiDeviceRouting.connectDevices(miosStudioInPort,
* memoryReadWriteDevice);
* midiDeviceRouting.connectDevices(memoryReadWriteDevice,
* miosStudioOutPort);
*/
 
midiDeviceRouting.connectDevices(lcdMessageDevice, miosStudioOutPort);
midiDeviceRouting.connectDevices(miosStudioInPort, debugFunctionDevice);
midiDeviceRouting
.connectDevices(debugFunctionDevice, miosStudioOutPort);
 
midiDeviceRouting.connectDevices(miosStudioInPort, miosTerminalDevice);
}
 
public void update(Observable observable, Object object) {
/*
* if (observable == sysexSendReceiveDeviceManager) {
*
* SysexSendReceiveDevice ssrt = (SysexSendReceiveDevice) object;
*
* if (sysexSendReceiveDeviceManager.getSysexSendReceiveDevices()
* .contains(ssrt)) {
*
* midiDeviceRouting.connectDevices(miosStudioInPort, ssrt);
* midiDeviceRouting.connectDevices(ssrt, miosStudioOutPort);
*
* if (routeIndividualDevices) {
* midiDeviceRouting.addMidiReadDevice(ssrt);
* midiDeviceRouting.addMidiWriteDevice(ssrt);
* setRouteIndividualDevices(true); } } else {
* midiDeviceRouting.disconnectDevice(ssrt);
*
* if (routeIndividualDevices) {
* midiDeviceRouting.removeMidiReadDevice(ssrt);
* midiDeviceRouting.removeMidiWriteDevice(ssrt); } } }
*/
 
if (observable == hexFileUploadDeviceManager) {
 
HexFileUploadDevice hutd = (HexFileUploadDevice) object;
 
if (hexFileUploadDeviceManager.getHexFileUploadDevices().contains(
hutd)) {
 
midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
 
if (routeIndividualDevices) {
midiDeviceRouting.addMidiReadDevice(hutd);
midiDeviceRouting.addMidiWriteDevice(hutd);
setRouteIndividualDevices(true);
}
 
} else {
midiDeviceRouting.disconnectDevice(hutd);
 
if (routeIndividualDevices) {
midiDeviceRouting.removeMidiReadDevice(hutd);
midiDeviceRouting.removeMidiWriteDevice(hutd);
}
}
}
 
if (object == "Edit") {
 
boolean portsReleased = midiDeviceRouting.getPortsReleased();
 
if (!portsReleased) {
midiDeviceRouting.setPortsReleased(true);
midiDeviceRouting.setPortsReleased(false);
}
}
}
}
/trunk/java/org/midibox/apps/miosstudio/gui/MIOSStudioGUI.java
New file
0,0 → 1,1304
/*
* @(#)MIOSStudioGUI.java beta8 2006/04/23
*
* Copyright (C) 2008 Adam King (adamjking@optusnet.com.au)
*
* This application is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this application; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
package org.midibox.apps.miosstudio.gui;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.URL;
import java.util.Vector;
 
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
 
import org.midibox.apps.miosstudio.MIOSStudio;
import org.midibox.midi.MidiKeyboardControllerDevice;
import org.midibox.midi.SysexSendReceiveDevice;
import org.midibox.midi.gui.MidiDeviceRoutingGUI;
import org.midibox.midi.gui.MidiFilterGUI;
import org.midibox.midi.gui.MidiKeyboardControllerGUI;
import org.midibox.midi.gui.MidiMonitorFilteredGUI;
import org.midibox.mios.HexFileUploadDevice;
import org.midibox.mios.gui.DebugFunctionGUI;
import org.midibox.mios.gui.HexFileUploadDeviceManagerGUI;
import org.midibox.mios.gui.LCDMessageGUI;
import org.midibox.utils.ResourceLoader;
import org.midibox.utils.gui.FontLoader;
import org.midibox.utils.gui.HelpPane;
import org.midibox.utils.gui.ImageLoader;
 
public class MIOSStudioGUI extends JPanel implements ActionListener,
MouseListener, PropertyChangeListener, MenuListener {
 
protected MIOSStudio miosStudio;
 
private JDesktopPane desktop;
 
private HelpPane helpPane;
 
private MIOSStudioInternalFrame helpWindow;
 
protected MidiDeviceRoutingGUI midiDeviceRoutingGUI;
 
private MIOSStudioInternalFrame midiDeviceRoutingWindow;
 
private MidiMonitorFilteredGUI midiOutPortMonitorGUI;
 
private MIOSStudioInternalFrame midiOutPortMonitorWindow;
 
private MidiMonitorFilteredGUI midiInPortMonitorGUI;
 
private MIOSStudioInternalFrame midiInPortMonitorWindow;
 
private MidiKeyboardControllerGUI midiKeyboardControllerGUI;
 
private MIOSStudioInternalFrame midiKeyboardControllerWindow;
 
/*
* private SysexSendReceiveDeviceManagerGUI
* sysexSendReceiveDeviceManagerGUI;
*
* private MIOSStudioInternalFrame sysexSendReceiveDeviceManagerWindow;
*/
 
private HexFileUploadDeviceManagerGUI hexFileUploadDeviceManagerGUI;
 
private MIOSStudioInternalFrame hexFileUploadDeviceManagerWindow;
 
/*
* private MemoryReadWriteGUI memoryReadWriteGUI;
*/
 
private LCDMessageGUI lcdMessageGUI;
 
private MIOSStudioInternalFrame lcdMessageWindow;
 
private DebugFunctionGUI debugFunctionGUI;
 
private MIOSStudioInternalFrame debugFunctionWindow;
 
private MidiMonitorFilteredGUI miosTerminalGUI;
 
private MIOSStudioInternalFrame miosTerminalWindow;
 
private JDialog thruFilterProperties;
 
/*
* private JDialog thruMapProperties;
*/
protected JToolBar toolBar;
 
protected JPopupMenu toolBarMenu;
 
private ExternalButtonProperties externalButtonProperties;
 
private Vector externalCommands = new Vector();
 
protected JMenu fileMenu;
 
protected JMenu midiMenu;
 
protected JMenu miosMenu;
 
protected JMenu optionsMenu;
 
protected WindowMenu windowMenu;
 
protected JMenu helpMenu;
 
private JMenuItem midiThruMenuItem;
 
private JMenuItem showInternalMenuItem;
 
private JMenu lookAndFeelMenu;
 
private String lookAndFeel;
 
private boolean defaultDecoratedFrames;
 
private JLabel commentLabel;
 
public MIOSStudioGUI(MIOSStudio miosStudio) {
 
super(new BorderLayout());
 
this.miosStudio = miosStudio;
 
lookAndFeel = UIManager.getLookAndFeel().getClass().getName();
defaultDecoratedFrames = JFrame.isDefaultLookAndFeelDecorated();
 
add(createToolBar(), BorderLayout.NORTH);
add(createMainPanel(), BorderLayout.CENTER);
add(createCommentBar(), BorderLayout.SOUTH);
}
 
private JDesktopPane createMainPanel() {
desktop = new JDesktopPane() {
ImageIcon backgroundImage = ImageLoader
.getImageIcon("logo_watermark.png");
 
public void paintComponent(Graphics g) {
super.paintComponent(g);
backgroundImage
.paintIcon(this, g, (this.getWidth() - backgroundImage
.getIconWidth()) - 20,
(this.getHeight() - backgroundImage
.getIconHeight()) - 20);
}
}; // JDesktop pane with paint method overridden to display watermark
 
desktop.setBackground(Color.WHITE);
 
createInternalFrames();
 
// start In/Out/Terminal thread
miosStudio.getMidiInPortMonitorDevice().getMidiMonitorFiltered()
.getMidiMonitor().deleteObserver(midiInPortMonitorGUI);
 
miosStudio.getMidiOutPortMonitorDevice().getMidiMonitorFiltered()
.getMidiMonitor().deleteObserver(midiOutPortMonitorGUI);
 
miosStudio.getMIOSTerminalDevice().getMidiMonitorFiltered()
.getMidiMonitor().deleteObserver(miosTerminalGUI);
 
Thread t = new Thread() {
 
public void run() {
 
while (true) {
 
midiInPortMonitorGUI.check();
midiOutPortMonitorGUI.check();
miosTerminalGUI.check();
 
try {
Thread.sleep(50);
} catch (Exception e) {
 
}
}
}
 
};
 
t.start();
 
return desktop;
}
 
protected void createInternalFrames() {
 
// Help Window
 
helpPane = HelpPane.createSingleton(ResourceLoader
.getResource("help/index.html"));
helpPane.addPropertyChangeListener(this);
 
helpWindow = new MIOSStudioInternalFrame("MIOS Studio Help", true,
true, true, true, ImageLoader.getImageIcon("help.png"),
helpPane);
helpWindow.pack();
 
// MIDI Device Routing
 
Icon icon = ImageLoader.getImageIcon("midiDevices.png");
midiDeviceRoutingGUI = new MidiDeviceRoutingGUI(miosStudio
.getMidiDeviceRouting());
 
midiDeviceRoutingWindow = new MIOSStudioInternalFrame(
"MIDI Device Routing", true, // resizable
true, // closable
true, // maximizable
true, icon, midiDeviceRoutingGUI);
 
midiDeviceRoutingWindow.pack();
 
icon = ImageLoader.getImageIcon("ucIcon.png");
 
/*
* midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
* .getMiosStudioInPort(), icon);
*
* midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
* .getMiosStudioOutPort(), icon);
*/
 
// MIDI OUT Port
midiOutPortMonitorGUI = new MidiMonitorFilteredGUI(miosStudio
.getMidiOutPortMonitorDevice().getMidiMonitorFiltered());
 
icon = ImageLoader.getImageIcon("midiOut.png");
 
midiOutPortMonitorWindow = new MIOSStudioInternalFrame(
"MIDI Monitor: OUT", true, true, true, true, icon,
midiOutPortMonitorGUI);
 
midiOutPortMonitorWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
.getMidiOutPortMonitorDevice(), icon);
 
// MIDI IN Port
midiInPortMonitorGUI = new MidiMonitorFilteredGUI(miosStudio
.getMidiInPortMonitorDevice().getMidiMonitorFiltered());
 
icon = ImageLoader.getImageIcon("midiIn.png");
 
midiInPortMonitorWindow = new MIOSStudioInternalFrame(
"MIDI Monitor: IN", true, true, true, true, icon,
midiInPortMonitorGUI);
 
midiInPortMonitorWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
.getMidiInPortMonitorDevice(), icon);
 
// MIDI Keyboard Controller
 
icon = ImageLoader.getImageIcon("piano.png");
 
midiKeyboardControllerGUI = new MidiKeyboardControllerGUI(miosStudio
.getMidiKeyboardControllerDevice().getMidiKeyboardController());
 
midiKeyboardControllerWindow = new MIOSStudioInternalFrame(
"MIDI Keyboard Controller", false, // resizable
true, // closable
false, // maximizable
true, icon, midiKeyboardControllerGUI);
 
midiKeyboardControllerWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(
MidiKeyboardControllerDevice.class, icon);
 
// Sysex Send/Receive
/*
* sysexSendReceiveDeviceManagerGUI = new
* SysexSendReceiveDeviceManagerGUI(
* miosStudio.getSysexSendReceiveDeviceManager());
*
* icon = ImageLoader.getImageIcon("sysex.png");
*
* sysexSendReceiveDeviceManagerWindow = new MIOSStudioInternalFrame(
* "Sysex Send/Receive", true, true, true, true, icon,
* sysexSendReceiveDeviceManagerGUI);
*
* sysexSendReceiveDeviceManagerWindow.pack();
*/
 
midiDeviceRoutingGUI.addMidiDeviceIcon(SysexSendReceiveDevice.class,
icon);
 
// Hex Upload
 
hexFileUploadDeviceManagerGUI = new HexFileUploadDeviceManagerGUI(
miosStudio.getHexFileUploadDeviceManager());
 
icon = ImageLoader.getImageIcon("hex.png");
 
hexFileUploadDeviceManagerWindow = new MIOSStudioInternalFrame(
"MIOS Hex File Upload", true, true, true, true, icon,
hexFileUploadDeviceManagerGUI);
 
hexFileUploadDeviceManagerWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(HexFileUploadDevice.class, icon);
 
// Read/Write
/*
* icon = ImageLoader.getImageIcon("readWrite.png");
*
* memoryReadWriteGUI = new MemoryReadWriteGUI(miosStudio
* .getMemoryReadWriteDevice().getMemoryReadWrite());
*
* tabbedPane.addTab("MIOS Memory Read/Write", icon,
* memoryReadWriteGUI);
* midiDeviceRoutingGUI.addMidiDeviceIcon(MemoryReadWriteDevice.class,
* icon);
*/
 
// LCD Message
icon = ImageLoader.getImageIcon("lcd.png");
 
lcdMessageGUI = new LCDMessageGUI(miosStudio.getLcdMessageDevice()
.getLCDMessage());
 
lcdMessageWindow = new MIOSStudioInternalFrame("MIOS LCD Message",
true, true, true, true, icon, lcdMessageGUI);
 
lcdMessageWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(
miosStudio.getLcdMessageDevice(), icon);
 
// MIOS Debug
 
icon = ImageLoader.getImageIcon("debug.png");
 
debugFunctionGUI = new DebugFunctionGUI(miosStudio
.getDebugFunctionDevice().getDebugFunction());
 
debugFunctionWindow = new MIOSStudioInternalFrame(
"MIOS Debug Functions", true, true, true, true, icon,
debugFunctionGUI);
 
debugFunctionWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
.getDebugFunctionDevice(), icon);
 
// MIOS Terminal
miosTerminalGUI = new MidiMonitorFilteredGUI(miosStudio
.getMIOSTerminalDevice().getMidiMonitorFiltered());
 
icon = ImageLoader.getImageIcon("miosTerminal.png");
 
miosTerminalWindow = new MIOSStudioInternalFrame("MIOS Terminal", true,
true, true, true, icon, miosTerminalGUI);
 
miosTerminalWindow.pack();
 
midiDeviceRoutingGUI.addMidiDeviceIcon(miosStudio
.getMIOSTerminalDevice(), icon);
}
 
public JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
 
createFileMenu();
createMIDIMenu();
createMIOSMenu();
createOptionsMenu();
createWindowMenu();
createHelpMenu();
 
menuBar.add(fileMenu);
menuBar.add(midiMenu);
menuBar.add(miosMenu);
menuBar.add(optionsMenu);
menuBar.add(windowMenu);
menuBar.add(helpMenu);
 
return menuBar;
}
 
protected void createFileMenu() {
 
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
}
 
protected void createMIDIMenu() {
midiMenu = new JMenu("MIDI");
midiMenu.setMnemonic(KeyEvent.VK_M);
 
JMenuItem menuItem = new JMenuItem("MIDI Device Routing");
menuItem.setMnemonic(KeyEvent.VK_R);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("midi_devices");
menuItem.addActionListener(this);
midiMenu.add(menuItem);
 
menuItem = new JMenuItem("MIDI Monitor: OUT");
menuItem.setMnemonic(KeyEvent.VK_O);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("midi_out_port_monitor");
menuItem.addActionListener(this);
midiMenu.add(menuItem);
 
menuItem = new JMenuItem("MIDI Monitor: IN");
menuItem.setMnemonic(KeyEvent.VK_I);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("midi_in_port_monitor");
menuItem.addActionListener(this);
midiMenu.add(menuItem);
 
menuItem = new JMenuItem("MIDI Keyboard Controller");
menuItem.setMnemonic(KeyEvent.VK_P);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("piano_controller");
menuItem.addActionListener(this);
midiMenu.add(menuItem);
 
/*
* menuItem = new JMenuItem("Sysex Send/Recieve");
* menuItem.setMnemonic(KeyEvent.VK_S);
* menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
* ActionEvent.CTRL_MASK)); menuItem.setActionCommand("sysex");
* menuItem.addActionListener(this); menu.add(menuItem);
*/
 
}
 
protected void createMIOSMenu() {
 
miosMenu = new JMenu("MIOS");
miosMenu.setMnemonic(KeyEvent.VK_O);
 
JMenuItem menuItem = new JMenuItem("MIOS Hex File Upload");
menuItem.setMnemonic(KeyEvent.VK_U);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("open_hex_file");
menuItem.addActionListener(this);
miosMenu.add(menuItem);
 
menuItem = new JMenuItem("MIOS LCD Message");
menuItem.setMnemonic(KeyEvent.VK_L);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("lcd_message");
menuItem.addActionListener(this);
miosMenu.add(menuItem);
 
menuItem = new JMenuItem("MIOS Debug Functions");
menuItem.setMnemonic(KeyEvent.VK_D);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("debug_functions");
menuItem.addActionListener(this);
miosMenu.add(menuItem);
 
menuItem = new JMenuItem("MIOS Terminal");
menuItem.setMnemonic(KeyEvent.VK_T);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
ActionEvent.CTRL_MASK));
menuItem.setActionCommand("mios_terminal");
menuItem.addActionListener(this);
miosMenu.add(menuItem);
}
 
protected void createOptionsMenu() {
 
optionsMenu = new JMenu("Options");
optionsMenu.setMnemonic(KeyEvent.VK_P);
 
showInternalMenuItem = new JCheckBoxMenuItem("Show Internal Routing",
miosStudio.isRouteIndividualDevices());
showInternalMenuItem.setActionCommand("route_internal");
showInternalMenuItem.addActionListener(this);
optionsMenu.add(showInternalMenuItem);
 
JMenuItem menuItem = new JMenuItem("Restore Default Internal Routing");
menuItem.setActionCommand("restore_default");
menuItem.addActionListener(this);
optionsMenu.add(menuItem);
 
optionsMenu.addSeparator();
JMenu thruMenu = new JMenu("MIDI Thru");
 
midiThruMenuItem = new JCheckBoxMenuItem("Enable MIDI Thru");
midiThruMenuItem.setActionCommand("midi_thru");
midiThruMenuItem.addActionListener(this);
thruMenu.add(midiThruMenuItem);
 
menuItem = new JMenuItem("Show MIDI Thru Filter");
menuItem.setActionCommand("midi_thru_filter");
menuItem.addActionListener(this);
thruMenu.add(menuItem);
 
/*
* menuItem = new JMenuItem("Show MIDI Thru Map");
* menuItem.setActionCommand("midi_thru_map");
* menuItem.addActionListener(this); thruMenu.add(menuItem);
*/
 
optionsMenu.add(thruMenu);
optionsMenu.addSeparator();
lookAndFeelMenu = new JMenu("Look & Feel");
lookAndFeelMenu.addMenuListener(this);
optionsMenu.add(lookAndFeelMenu);
}
 
protected void createWindowMenu() {
 
windowMenu = new WindowMenu(this);
windowMenu.setMnemonic(KeyEvent.VK_W);
}
 
protected void createHelpMenu() {
 
helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
 
JMenuItem menuItem = new JMenuItem("MIOS Studio Help");
menuItem.setMnemonic(KeyEvent.VK_I);
 
menuItem.setActionCommand("help_index");
menuItem.addActionListener(this);
helpMenu.add(menuItem);
 
menuItem = new JMenuItem("MIOS Function Reference");
menuItem.setMnemonic(KeyEvent.VK_F);
 
menuItem.setActionCommand("mios_fun");
menuItem.addActionListener(this);
helpMenu.add(menuItem);
}
 
public void addExternalCommandButton(String commandName, String command) {
ExternalCommandButton button = new ExternalCommandButton();
button.setCommandName(commandName);
button.setExternalCommand(command);
externalCommands.add(button);
toolBar.add(button);
assignExternalButtonMnemonics();
toolBar.setVisible(false);
toolBar.setVisible(true);
}
 
protected void removeExternalCommandButton(ExternalCommandButton button) {
externalCommands.remove(button);
toolBar.remove(button);
assignExternalButtonMnemonics();
toolBar.setVisible(false);
toolBar.setVisible(true);
}
 
protected void assignExternalButtonMnemonics() {
for (int i = 0; i < externalCommands.size() && i < 9; i++) {
((ExternalCommandButton) externalCommands.elementAt(i))
.setMnemonic(0x31 + i);
}
}
 
protected JToolBar createToolBar() {
 
toolBar = new JToolBar("Tool Bar", JToolBar.HORIZONTAL);
toolBar.setFloatable(true);
toolBar.setRollover(true);
 
createMIDIButtons();
 
toolBar.addSeparator();
 
createMIOSButtons();
 
toolBar.addSeparator();
 
createHelpButtons();
 
toolBar.addSeparator();
 
toolBarMenu = new JPopupMenu();
JMenuItem addButton = new JMenuItem("Add External Command Button");
addButton.setActionCommand("add_command_button");
addButton.addActionListener(this);
toolBarMenu.add(addButton);
 
toolBar.addMouseListener(this);
toolBar.setVisible(true);
return toolBar;
}
 
protected void createMIDIButtons() {
 
Insets insets = new Insets(2, 2, 2, 2);
 
JButton button = new JButton(ImageLoader
.getImageIcon("midiDevices.png"));
button.setToolTipText("MIDI Device Routing");
button.setActionCommand("midi_devices");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("midiOut.png"));
button.setToolTipText("MIDI Monitor: OUT");
button.setActionCommand("midi_out_port_monitor");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("midiIn.png"));
button.setToolTipText("MIDI Monitor: IN");
button.setActionCommand("midi_in_port_monitor");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("piano.png"));
button.setToolTipText("MIDI Keyboard Controller");
button.setActionCommand("piano_controller");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
/*
* button = new JButton(ImageLoader.getImageIcon("sysex.png"));
* button.setToolTipText("Sysex Send/Receive");
* button.setActionCommand("sysex"); button.addActionListener(this);
* button.setMargin(insets); toolBar.add(button);
*/
 
}
 
protected void createMIOSButtons() {
 
Insets insets = new Insets(2, 2, 2, 2);
 
JButton button = new JButton(ImageLoader.getImageIcon("hex.png"));
button.setToolTipText("MIOS Hex File Upload");
button.setActionCommand("open_hex_file");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("lcd.png"));
button.setToolTipText("MIOS LCD Message");
button.setActionCommand("lcd_message");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("debug.png"));
button.setToolTipText("MIOS Debug Functions");
button.setActionCommand("debug_functions");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
button = new JButton(ImageLoader.getImageIcon("miosTerminal.png"));
button.setToolTipText("MIOS Terminal");
button.setActionCommand("mios_terminal");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
}
 
protected void createHelpButtons() {
 
Insets insets = new Insets(2, 2, 2, 2);
 
JButton button = new JButton(ImageLoader.getImageIcon("help.png"));
button.setToolTipText("MIOS Studio Help");
button.setActionCommand("help_window");
button.addActionListener(this);
button.setMargin(insets);
toolBar.add(button);
 
}
 
private void runExternalCommand(String command) {
try {
Runtime rt = Runtime.getRuntime();
rt.exec(command);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Cannot run command: "
+ command + "\nReceived error: " + e.getLocalizedMessage(),
"Cannot run command", JOptionPane.ERROR_MESSAGE);
}
}
 
private JPanel createCommentBar() {
JPanel commentBar = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.gridwidth = 1;
 
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
commentBar.add(Box.createGlue(), gbc);
gbc.gridx++;
 
gbc.weightx = 0.0;
gbc.insets = new Insets(2, 2, 2, 2);
 
commentBar.add(new JSeparator(JSeparator.VERTICAL), gbc);
gbc.gridx++;
 
gbc.insets = new Insets(2, 10, 2, 20);
 
commentLabel = new JLabel();
commentBar.add(commentLabel, gbc);
return commentBar;
}
 
public void setCommentLabel(String text) {
 
commentLabel.setText(text);
}
 
private void showMidiThruFilter() {
if (thruFilterProperties == null) {
final MidiFilterGUI midiFilterGUI = new MidiFilterGUI(miosStudio
.getMidiThruFilterDevice().getMidiFilter());
 
thruFilterProperties = new JDialog();
thruFilterProperties.setContentPane(midiFilterGUI);
thruFilterProperties.setModal(false);
thruFilterProperties.setTitle("MIDI Thru Filter");
thruFilterProperties.pack();
thruFilterProperties.setLocationRelativeTo(this);
thruFilterProperties.setVisible(true);
 
thruFilterProperties.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
miosStudio.getMidiThruFilterDevice().deleteObserver(
midiFilterGUI);
thruFilterProperties = null;
}
});
}
thruFilterProperties.requestFocus();
}
 
/*
* private void showMidiThruMap() { if (thruMapProperties == null) { final
* MidiMapGUI midiMapGUI = new MidiMapGUI(miosStudio
* .getMidiThruMapDevice().getMidiMap());
*
* thruMapProperties = new JDialog();
* thruMapProperties.setContentPane(midiMapGUI);
* thruMapProperties.setModal(false); thruMapProperties.setTitle("MIDI Thru
* Map"); thruMapProperties.pack();
* thruMapProperties.setLocationRelativeTo(this);
* thruMapProperties.setVisible(true);
*
* thruMapProperties.addWindowListener(new WindowAdapter() { public void
* windowClosing(WindowEvent we) { miosStudio.getMidiThruMapDevice()
* .deleteObserver(midiMapGUI); thruMapProperties = null; } }); }
* thruMapProperties.requestFocus(); }
*/
 
protected void onHelpIndex() {
URL currentURL = helpPane.getCurrentURL();
if (currentURL != null) {
if (!currentURL.equals(ResourceLoader
.getResource("help/index.html"))) {
helpPane.goToURL(ResourceLoader.getResource("help/index.html"));
} else {
showFrame(helpWindow);
}
} else {
helpPane.goToURL(ResourceLoader.getResource("help/index.html"));
}
}
 
protected void onMiosFun() {
helpPane.goToURL(ResourceLoader.getResource("help/mios_fun.html"));
}
 
public void showFrame(JInternalFrame frame) {
try {
if (!frame.isVisible()) {
frame.setVisible(true);
desktop.add(frame);
frame.moveToFront();
frame.setSelected(true);
} else if (frame.isIcon()) {
frame.setIcon(false);
frame.moveToFront();
frame.setSelected(true);
} else {
frame.moveToFront();
frame.setSelected(true);
}
} catch (java.beans.PropertyVetoException e) {
System.out.println(e.toString());
}
}
 
private void buildLookAndFeel() {
 
JCheckBoxMenuItem item;
 
for (int i = 0; i < UIManager.getInstalledLookAndFeels().length; i++) {
final int l = i;
item = new JCheckBoxMenuItem(
UIManager.getInstalledLookAndFeels()[i].getName());
lookAndFeelMenu.add(item);
if (UIManager.getInstalledLookAndFeels()[i].getClassName().equals(
lookAndFeel)) {
item.setSelected(true);
}
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
lookAndFeel = UIManager.getInstalledLookAndFeels()[l]
.getClassName();
JOptionPane
.showMessageDialog(
MIOSStudioGUI.this,
"The selected Look & Feel will be applied the next time you restart MIOS Studio",
"ALERT", JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
System.out.println(e.toString());
}
}
});
}
 
item = new JCheckBoxMenuItem("Include Frames/Dialogs",
defaultDecoratedFrames);
item.setActionCommand("dialogs");
item.addActionListener(this);
 
lookAndFeelMenu.addSeparator();
lookAndFeelMenu.add(item);
}
 
public JMenu getFileMenu() {
return fileMenu;
}
 
public boolean isDefaultDecoratedFrames() {
return defaultDecoratedFrames;
}
 
public MIOSStudio getMiosStudio() {
return miosStudio;
}
 
public Vector getExternalCommands() {
return externalCommands;
}
 
public String getLookAndFeel() {
return lookAndFeel;
}
 
public JDesktopPane getDesktop() {
return desktop;
}
 
public MIOSStudioInternalFrame getMidiDeviceRoutingWindow() {
return midiDeviceRoutingWindow;
}
 
public MIOSStudioInternalFrame getMidiOutPortMonitorWindow() {
return midiOutPortMonitorWindow;
}
 
public MIOSStudioInternalFrame getMidiInPortMonitorWindow() {
return midiInPortMonitorWindow;
}
 
public MIOSStudioInternalFrame getMidiKeyboardControllerWindow() {
return midiKeyboardControllerWindow;
}
 
public MIOSStudioInternalFrame getHexFileUploadDeviceManagerWindow() {
return hexFileUploadDeviceManagerWindow;
}
 
public MIOSStudioInternalFrame getLcdMessageWindow() {
return lcdMessageWindow;
}
 
public MIOSStudioInternalFrame getDebugFunctionWindow() {
return debugFunctionWindow;
}
 
public MIOSStudioInternalFrame getMIOSTerminalWindow() {
return miosTerminalWindow;
}
 
public MIOSStudioInternalFrame getHelpWindow() {
return helpWindow;
}
 
/*
* public MIOSStudioInternalFrame getSysexSendReceiveDeviceManagerWindow() {
* return sysexSendReceiveDeviceManagerWindow; }
*/
public void mousePressed(MouseEvent me) {
Object source = me.getSource();
 
if (source == toolBar) {
if (me.getButton() == MouseEvent.BUTTON3) {
toolBarMenu.show(toolBar, me.getX(), me.getY());
}
} else if (source instanceof ExternalCommandButton) {
if (me.getButton() == MouseEvent.BUTTON3) {
((ExternalCommandButton) source).popMenu.show(
((ExternalCommandButton) source), me.getX(), me.getY());
}
}
}
 
public void mouseReleased(MouseEvent me) {
 
}
 
public void mouseClicked(MouseEvent me) {
 
}
 
public void mouseEntered(MouseEvent me) {
 
}
 
public void mouseExited(MouseEvent me) {
 
}
 
public void propertyChange(PropertyChangeEvent pce) {
showFrame(helpWindow);
}
 
public void menuCanceled(MenuEvent e) {
}
 
public void menuDeselected(MenuEvent e) {
Object source = e.getSource();
 
if (source == windowMenu) {
windowMenu.removeAll();
} else if (source == lookAndFeelMenu) {
lookAndFeelMenu.removeAll();
}
}
 
public void menuSelected(MenuEvent e) {
Object source = e.getSource();
 
if (source == windowMenu) {
windowMenu.buildChildMenus();
} else if (source == lookAndFeelMenu) {
buildLookAndFeel();
}
}
 
public void actionPerformed(ActionEvent ae) {
 
if (ae.getActionCommand().equals("midi_devices")) {
showFrame(midiDeviceRoutingWindow);
 
} else if (ae.getActionCommand().equals("midi_out_port_monitor")) {
showFrame(midiOutPortMonitorWindow);
 
} else if (ae.getActionCommand().equals("midi_in_port_monitor")) {
showFrame(midiInPortMonitorWindow);
 
} else if (ae.getActionCommand().equals("piano_controller")) {
showFrame(midiKeyboardControllerWindow);
 
} else if (ae.getActionCommand().equals("open_hex_file")) {
showFrame(hexFileUploadDeviceManagerWindow);
 
} else if (ae.getActionCommand().equals("lcd_message")) {
showFrame(lcdMessageWindow);
 
} else if (ae.getActionCommand().equals("debug_functions")) {
showFrame(debugFunctionWindow);
 
} else if (ae.getActionCommand().equals("mios_terminal")) {
showFrame(miosTerminalWindow);
 
} else if (ae.getActionCommand().equals("route_internal")) {
miosStudio.setRouteIndividualDevices(showInternalMenuItem
.isSelected());
 
} else if (ae.getActionCommand().equals("restore_default")) {
miosStudio.connectDevices();
 
} else if (ae.getActionCommand().equals("midi_thru_filter")) {
showMidiThruFilter();
 
} else if (ae.getActionCommand().equals("midi_thru")) {
miosStudio.setMidiThru(midiThruMenuItem.isSelected());
 
} else if (ae.getActionCommand().equals("help_window")) {
showFrame(helpWindow);
 
} else if (ae.getActionCommand().equals("help_index")) {
onHelpIndex();
 
} else if (ae.getActionCommand().equals("mios_fun")) {
onMiosFun();
 
} else if (ae.getActionCommand().equals("externalCommand")) {
runExternalCommand(((ExternalCommandButton) ae.getSource()).externalCommand);
 
} else if (ae.getActionCommand().equals("add_command_button")) {
addExternalCommandButton("[empty]", "");
 
} else if (ae.getActionCommand().equals("dialogs")) {
defaultDecoratedFrames = ((JCheckBoxMenuItem) ae.getSource())
.isSelected();
}
}
 
public class MIOSStudioInternalFrame extends JInternalFrame {
public MIOSStudioInternalFrame(String name, boolean resizeable,
boolean closeable, boolean maximizeable, boolean iconifiable,
Icon icon, JComponent contentPane) {
super(name, resizeable, closeable, maximizeable, iconifiable);
setFrameIcon(icon);
setContentPane(contentPane);
}
 
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
 
public class ExternalCommandButton extends JButton implements
ActionListener {
 
public String externalCommand = "";
 
public String commandName = "";
 
public JPopupMenu popMenu;
 
public ExternalCommandButton() {
super(ImageLoader.getImageIcon("external.png"));
 
Insets insets = new Insets(2, 2, 2, 2);
 
setMargin(insets);
setActionCommand("externalCommand");
addActionListener(MIOSStudioGUI.this);
setToolTipText(commandName);
 
popMenu = new JPopupMenu();
 
JMenuItem item = new JMenuItem("Properties");
item.setActionCommand("show_properties");
item.addActionListener(this);
popMenu.add(item);
 
item = new JMenuItem("Remove Button");
item.setActionCommand("remove_command_button");
item.addActionListener(this);
popMenu.add(item);
 
addMouseListener(MIOSStudioGUI.this);
}
 
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals("remove_command_button")) {
removeExternalCommandButton(this);
} else {
externalButtonProperties = new ExternalButtonProperties(this);
externalButtonProperties.setSize(500, 150);
externalButtonProperties
.setLocationRelativeTo(MIOSStudioGUI.this);
externalButtonProperties.setVisible(true);
}
}
 
public void setExternalCommand(String externalCommand) {
this.externalCommand = externalCommand;
}
 
public void setCommandName(String commandName) {
this.commandName = commandName;
setToolTipText(commandName);
}
 
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g.setFont(FontLoader.getFont("uni05_53.ttf", 8f));
String number = "" + (externalCommands.indexOf(this) + 1);
FontMetrics fm = g2d.getFontMetrics();
int offsetX = fm.stringWidth(number);
g.drawString(number, getWidth() - offsetX - 4, getHeight() - 4);
}
}
 
public class ExternalButtonProperties extends JDialog implements
ActionListener {
public ExternalCommandButton externalCommandButton;
 
public JTextField commandName;
 
public JTextField commandString;
 
public JButton okButton;
 
public ExternalButtonProperties(
ExternalCommandButton externalCommandButton) {
super();
this.externalCommandButton = externalCommandButton;
 
setTitle("External Command Button "
+ (externalCommands.indexOf(externalCommandButton) + 1));
 
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
 
gbc.insets = new Insets(4, 4, 4, 4);
 
gbc.anchor = GridBagConstraints.WEST;
JLabel label = new JLabel("Command Name: ");
add(label, gbc);
gbc.gridx++;
 
gbc.anchor = GridBagConstraints.EAST;
commandName = new JTextField(externalCommandButton.commandName, 30);
add(commandName, gbc);
gbc.gridx--;
gbc.gridy++;
 
gbc.anchor = GridBagConstraints.WEST;
label = new JLabel("Command String: ");
add(label, gbc);
gbc.gridx++;
 
gbc.anchor = GridBagConstraints.EAST;
commandString = new JTextField(
externalCommandButton.externalCommand, 30);
add(commandString, gbc);
gbc.gridx--;
gbc.gridy++;
 
okButton = new JButton("OK");
okButton.addActionListener(this);
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.CENTER;
add(okButton, gbc);
}
 
public void actionPerformed(ActionEvent ae) {
externalCommandButton.setCommandName(commandName.getText());
externalCommandButton.setExternalCommand(commandString.getText());
this.dispose();
}
}
 
public class WindowMenu extends JMenu {
 
private MIOSStudioGUI miosStudio;
 
private JDesktopPane desktop;
 
private JMenuItem cascadeMenuItem;
 
public WindowMenu(MIOSStudioGUI miosStudio) {
this.miosStudio = miosStudio;
this.desktop = miosStudio.desktop;
setText("Window");
addMenuListener(MIOSStudioGUI.this);
}
 
private JInternalFrame[] getFrames() {
return desktop.getAllFrames();
}
 
private void buildChildMenus() {
int i;
ChildMenuItem menuItem;
JInternalFrame[] frames = getFrames();
 
cascadeMenuItem = new JMenuItem("Cascade Windows");
 
cascadeMenuItem.addActionListener(new ActionListener() {
 
public void actionPerformed(ActionEvent ae) {
 
JInternalFrame[] frames = getFrames();
 
for (int x = 0; x < frames.length; x++) {
frames[frames.length - 1 - x].setLocation(x * 20,
x * 20);
}
}
});
 
cascadeMenuItem.setEnabled(frames.length > 0);
 
add(cascadeMenuItem);
 
addSeparator();
 
for (i = 0; i < frames.length; i++) {
menuItem = new ChildMenuItem(frames[i]);
menuItem.setState(i == 0);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JInternalFrame frame = ((ChildMenuItem) ae.getSource())
.getFrame();
miosStudio.showFrame(frame);
}
});
menuItem.setIcon(frames[i].getFrameIcon());
add(menuItem);
}
}
 
public class ChildMenuItem extends JCheckBoxMenuItem {
private JInternalFrame frame;
 
public ChildMenuItem(JInternalFrame frame) {
super(frame.getTitle());
this.frame = frame;
}
 
public JInternalFrame getFrame() {
return frame;
}
}
}
}
/trunk/java/org/midibox/apps/miosstudiosid/MIOSStudioSID.java
New file
0,0 → 1,42
package org.midibox.apps.miosstudiosid;
 
import org.midibox.apps.SIDV2librarian.SIDV2librarian;
 
public class MIOSStudioSID extends org.midibox.apps.miosstudio.MIOSStudio {
 
private SIDV2librarian sidv2librarian;
 
public SIDV2librarian getSidv2librarian() {
 
return sidv2librarian;
}
 
protected void createDevices() {
 
super.createDevices();
 
sidv2librarian = new SIDV2librarian(null);
 
sidv2librarian.getSIDLibController().addObserver(this);