Skip to content

Commit

Permalink
Minor formatting tweaks. GuiMiniHost does not work in Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhroth committed Oct 21, 2008
1 parent 967a2a9 commit 38d4e38
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 72 deletions.
Binary file modified JVstHost.jar
Binary file not shown.
4 changes: 1 addition & 3 deletions src/com/synthbot/minihost/GuiMiniHost.java
Expand Up @@ -37,14 +37,12 @@ public class GuiMiniHost implements PluginStringGuiListener {
private GuiMiniHostListener stringGui; private GuiMiniHostListener stringGui;


private int channel = 0; private int channel = 0;
private int velocity = 127;


public GuiMiniHost(File vstFile) { public GuiMiniHost(File vstFile) {
vst = null; vst = null;


stringGui = new PluginStringGui(this); stringGui = new PluginStringGui(this);
try { try {
System.out.println("GuiMiniHost... about ot load ! "+vstFile.toString());
vst = new JVstHost(vstFile, sampleRate, blockSize); vst = new JVstHost(vstFile, sampleRate, blockSize);
} catch (JVstLoadException jvle) { } catch (JVstLoadException jvle) {
jvle.printStackTrace(System.err); jvle.printStackTrace(System.err);
Expand Down Expand Up @@ -82,7 +80,7 @@ public String getProgramName(){
public synchronized void playNote(int note, int velocity){ public synchronized void playNote(int note, int velocity){
try { try {
ShortMessage midiMessage = new ShortMessage(); ShortMessage midiMessage = new ShortMessage();
midiMessage.setMessage(ShortMessage.NOTE_ON, 0, note, velocity); midiMessage.setMessage(ShortMessage.NOTE_ON, channel, note, velocity);
audioThread.addMidiMessages(midiMessage); audioThread.addMidiMessages(midiMessage);
} catch (InvalidMidiDataException imde) { } catch (InvalidMidiDataException imde) {
imde.printStackTrace(System.err); imde.printStackTrace(System.err);
Expand Down
112 changes: 49 additions & 63 deletions src/com/synthbot/minihost/PluginStringGui.java
Expand Up @@ -21,7 +21,6 @@


package com.synthbot.minihost; package com.synthbot.minihost;



import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Container; import java.awt.Container;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
Expand All @@ -43,7 +42,7 @@
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JComboBox; import javax.swing.JComboBox;


public class PluginStringGui extends JFrame implements GuiMiniHostListener { public class PluginStringGui extends JFrame implements GuiMiniHostListener {


private final PluginStringGuiListener host; private final PluginStringGuiListener host;


Expand All @@ -52,19 +51,19 @@ public class PluginStringGui extends JFrame implements GuiMiniHostListener {
private JSlider[] sliders; private JSlider[] sliders;
private JButton setEvolutionMaskButton; private JButton setEvolutionMaskButton;


// private static final String EVOLUTION_MASK = "Set Evoution Mask"; // private static final String EVOLUTION_MASK = "Set Evoution Mask";
private static final String SYNTHBOT_STRING_GUI = "SynthBot String GUI"; private static final String SYNTHBOT_STRING_GUI = "SynthBot String GUI";
//private static final String NO_EVOLVE = "Don't Evolve"; // private static final String NO_EVOLVE = "Don't Evolve";
private static final String PARAMETER_VALUE = "Parameter Value"; private static final String PARAMETER_VALUE = "Parameter Value";
private static final String PARAMETER_DISPLAY = "Parameter Display"; private static final String PARAMETER_DISPLAY = "Parameter Display";
private static final String PARAMETER_NAME = "Parameter Name"; private static final String PARAMETER_NAME = "Parameter Name";


public PluginStringGui(PluginStringGuiListener pluginHost){ public PluginStringGui(PluginStringGuiListener pluginHost) {
super(SYNTHBOT_STRING_GUI); super(SYNTHBOT_STRING_GUI);
this.host = pluginHost; this.host = pluginHost;
} }


public void generateGui(){ public void generateGui() {
// configure the gui based on this host // configure the gui based on this host
int colWidth = 240; int colWidth = 240;
int colHeight = 25; int colHeight = 25;
Expand All @@ -84,10 +83,7 @@ public void generateGui(){
displays[i] = host.getParameterDisplay(i); displays[i] = host.getParameterDisplay(i);
names[i] = host.getParameterName(i); names[i] = host.getParameterName(i);
labels[i] = host.getParameterLabel(i); labels[i] = host.getParameterLabel(i);
System.out.println("GuiMiniHost: label is "+labels[i]);
} }




// this is the top level container with the 3 cols plus the keyboard // this is the top level container with the 3 cols plus the keyboard
Container globalContainer = new Container(); Container globalContainer = new Container();
Expand Down Expand Up @@ -117,12 +113,8 @@ public void generateGui(){
sliders = new JSlider[numParameters]; sliders = new JSlider[numParameters];


for (int i = 0; i < numParameters; i++) { for (int i = 0; i < numParameters; i++) {
//System.out.println("PluginStringGUI... adding para "+names[i]);
JLabel nameLabel = new JLabel(i + ": " + names[i] + " (" + labels[i] + ") ", JLabel.RIGHT); JLabel nameLabel = new JLabel(i + ": " + names[i] + " (" + labels[i] + ") ", JLabel.RIGHT);

final JSlider slider = new JSlider(0, 127, (int) (values[i] * 127f)); // set initial value
final JSlider slider = new JSlider(0, 127, (int) (values[i] * 127f)); // set
// initial
// value?
slider.setValue((int) (values[i] * 127f)); slider.setValue((int) (values[i] * 127f));
slider.setFocusable(false); slider.setFocusable(false);
sliders[i] = slider; sliders[i] = slider;
Expand All @@ -140,12 +132,11 @@ public void generateGui(){


final int index = i; final int index = i;
slider.addChangeListener(new ChangeListener() { slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent event) { public void stateChanged(ChangeEvent event) {
String displayString = host.setParameter(index, String displayString = host.setParameter(index, ((float) slider.getValue()) / 127f);
((float) slider.getValue()) / 127f); valueLabel.setText(displayString);
valueLabel.setText(displayString); }
} });
});
// tell it not to fuck about with the sizes // tell it not to fuck about with the sizes
widgets.setMinimumSize(new Dimension(colWidth, colHeight)); widgets.setMinimumSize(new Dimension(colWidth, colHeight));
widgets.setPreferredSize(new Dimension(colWidth, colHeight)); widgets.setPreferredSize(new Dimension(colWidth, colHeight));
Expand Down Expand Up @@ -196,11 +187,11 @@ public void stateChanged(ChangeEvent event) {
} }


key.addActionListener(new ActionListener() { key.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
//host.playNote(48 + note, 96, synthbot.onGetCurrentParameters()); // host.playNote(48 + note, 96, synthbot.onGetCurrentParameters());
host.playNote(48 + note, 96); host.playNote(48 + note, 96);
} }
}); });
keyboard.add(key); keyboard.add(key);
} }


Expand All @@ -220,53 +211,48 @@ public void actionPerformed(ActionEvent event) {
JComboBox progList = new JComboBox(progNames); JComboBox progList = new JComboBox(progNames);
progList.setSelectedIndex(0); progList.setSelectedIndex(0);
progList.addActionListener(new ActionListener() { progList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
int index = cb.getSelectedIndex(); int index = cb.getSelectedIndex();
String progName = (String) cb.getSelectedItem(); String progName = (String) cb.getSelectedItem();
float[] program; float[] program;
// System.out.println("PluginStringGUI: you selected program host.setProgram(index);
// "+progName+" index "+index); // now update the sliders...
host.setProgram(index); // program = host.getCurrentParameters();
// now update the sliders...
//program = host.getCurrentParameters(); for (int i = 0; i < numParameters; i++) {

sliders[i].setValue((int) (host.getParameter(i) * 127f));
for (int i = 0; i < numParameters; i++) { }
// System.out.println("PluginStringGUI: updating param "+i+" to }
// "+program[i]); });
sliders[i].setValue((int) (host.getParameter(i) * 127f));
}
}
});


globalContainer.add(scrollPane); globalContainer.add(scrollPane);
globalContainer.add(keyboard); globalContainer.add(keyboard);
globalContainer.add(progList); globalContainer.add(progList);
this.add(globalContainer); this.add(globalContainer);



// container.add(playSound); // container.add(playSound);


this.addKeyListener(new KeyListener() { this.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) { public void keyPressed(KeyEvent event) {
} }


public void keyReleased(KeyEvent event) { public void keyReleased(KeyEvent event) {
} }


public void keyTyped(KeyEvent event) { public void keyTyped(KeyEvent event) {
switch (event.getKeyChar()) { switch (event.getKeyChar()) {
case ' ': case ' ':
// TODO play a sound here // TODO play a sound here
break; break;
case 'w': case 'w':
// TODO close the frame // TODO close the frame
break; break;
default: default:
break; break;
} }
} }
}); });


this.setFocusable(true); this.setFocusable(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Expand Down
7 changes: 1 addition & 6 deletions src/com/synthbot/minihost/PluginStringGuiListener.java
Expand Up @@ -30,18 +30,13 @@
* @version 1.0 * @version 1.0
*/ */
public interface PluginStringGuiListener{ public interface PluginStringGuiListener{

public String setParameter(int index, float value); public String setParameter(int index, float value);
public float getParameter(int index); public float getParameter(int index);
public int getNumParameters(); public int getNumParameters();
public String getParameterDisplay(int index); public String getParameterDisplay(int index);
public String getParameterName(int index); public String getParameterName(int index);
public String getParameterLabel(int index); public String getParameterLabel(int index);

public void setProgram(int index); public void setProgram(int index);
public String getProgramName(); public String getProgramName();

public void playNote(int noteNumber, int velocity); public void playNote(int noteNumber, int velocity);


} }
3 changes: 3 additions & 0 deletions src/com/synthbot/minihost/RandomMiniHost.java
Expand Up @@ -27,6 +27,9 @@
import javax.sound.midi.ShortMessage; import javax.sound.midi.ShortMessage;
import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.InvalidMidiDataException;


/**
* Plays a random note every 1 second.
*/
public class RandomMiniHost { public class RandomMiniHost {


private static final float sampleRate = 44100f; private static final float sampleRate = 44100f;
Expand Down

0 comments on commit 38d4e38

Please sign in to comment.