Skip to content

Commit 795ea0c

Browse files
authored
Merge pull request #11 from haschdl/fix-sysexmessage
Fix Sysexmessages
2 parents 2696c60 + e2a9b53 commit 795ea0c

File tree

9 files changed

+197
-193
lines changed

9 files changed

+197
-193
lines changed

.idea/artifacts/processingLibrariesLocal.xml

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 28 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/LaunchControlDemo/LaunchControlDemo.pde

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,87 @@ import pLaunchControl.*;
99

1010
LaunchControl controller;
1111

12-
void setup() {
13-
size(1000, 500);
14-
15-
try {
16-
controller = new LaunchControl(this, true);
17-
}
18-
catch(Exception e) {
19-
println("Unfortunately we could not detect that Launch Control is connected to this computer :(");
20-
}
21-
textAlign(CENTER);
22-
}
23-
24-
25-
void draw() {
26-
background(0);
27-
translate(20, 20);
28-
stroke(255);
29-
strokeWeight(3);
30-
float s = width/16;
31-
translate(s/2, s);
32-
33-
drawKnobs(s);
34-
drawPads(s);
35-
36-
}
12+
void setup() {
13+
size(1000, 500);
14+
15+
try {
16+
controller = new LaunchControl(this, true);
17+
// If you have renamed your Launch Control in the system
18+
// preferences, use this version of the constructor:
19+
// controller = new LaunchControl(this, true, "THE NAME YOU GAVE TO THE CONTROLLER");
20+
}
21+
catch(Exception e) {
22+
println("Unfortunately we could not detect that Launch Control is connected to this computer :(");
23+
println(e);
24+
noLoop();
25+
}
26+
textAlign(CENTER);
27+
}
28+
29+
30+
void draw() {
31+
background(0);
32+
translate(20, 20);
33+
stroke(255);
34+
strokeWeight(3);
35+
float s = width/16;
36+
translate(s/2, s);
37+
if (controller !=null) {
38+
drawKnobs(s);
39+
drawPads(s);
40+
}
41+
}
3742

3843
/**
3944
* Draws the knobs of the controller as simple arcs.
4045
*/
41-
void drawKnobs(float s) {
42-
43-
//drawing positions
44-
float start = HALF_PI * 1.3;
45-
float end = TWO_PI + HALF_PI * .7;
46-
47-
pushMatrix();
48-
for (int i = 0; i < 16; i++) {
49-
//draw knob background, simple arc
50-
fill(255);
51-
arc(2*s*(i%8), 0, s, s, start, end);
52-
53-
//draw knob position
54-
fill(80);
55-
Knob knob = controller.getKnob(i);
56-
float normal = knob.valueNormal();
57-
float realValue = knob.value();
58-
59-
arc(2*s*(i%8), 0, s, s, start, start + normal*(end-start));
60-
fill(255);
61-
text(round(realValue), 2*s*(i%8), s );
62-
63-
if (i == 7)
64-
translate(0, height * .3);
65-
}
66-
popMatrix();
67-
}
46+
void drawKnobs(float s) {
47+
48+
//drawing positions
49+
float start = HALF_PI * 1.3;
50+
float end = TWO_PI + HALF_PI * .7;
51+
52+
pushMatrix();
53+
for (int i = 0; i < 16; i++) {
54+
//draw knob background, simple arc
55+
fill(255);
56+
arc(2*s*(i%8), 0, s, s, start, end);
57+
58+
//draw knob position
59+
fill(80);
60+
Knob knob = controller.getKnob(i);
61+
float normal = knob.valueNormal();
62+
float realValue = knob.value();
63+
64+
arc(2*s*(i%8), 0, s, s, start, start + normal*(end-start));
65+
fill(255);
66+
text(round(realValue), 2*s*(i%8), s );
67+
68+
if (i == 7)
69+
translate(0, height * .3);
70+
}
71+
popMatrix();
72+
}
6873

6974
/**
7075
* Draws the pads of the controller as simple arcs.
7176
*/
72-
void drawPads(float s) {
73-
translate(0,height * .6);
74-
rectMode(CENTER);
75-
76-
for (int i = 0; i < 8; i++) {
77-
//draw pad background, simple arc
78-
fill(255);
79-
rect(2*s*i,0,s,s);
80-
81-
//draw pad state position
82-
fill(80);
83-
boolean padState = controller.getPad(i).value();
84-
if(padState)
85-
rect(2*s*i,0,s,s);
86-
87-
fill(255);
88-
text(round(i), 2*s*(i%8), s );
89-
90-
}
91-
}
77+
void drawPads(float s) {
78+
translate(0, height * .6);
79+
rectMode(CENTER);
80+
81+
for (int i = 0; i < 8; i++) {
82+
//draw pad background, simple arc
83+
fill(255);
84+
rect(2*s*i, 0, s, s);
85+
86+
//draw pad state position
87+
fill(80);
88+
boolean padState = controller.getPad(i).value();
89+
if (padState)
90+
rect(2*s*i, 0, s, s);
91+
92+
fill(255);
93+
text(round(i), 2*s*(i%8), s );
94+
}
95+
}

library.properties

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# UTF-8 supported.
22

33
# The name of your library as you want it formatted.
4-
name = Novation Launch Controller client
4+
name = Novation Launch Control client
55

66
# List of authors. Links can be provided using the syntax [author name](url).
7-
authors = [Half Scheidl](https://github.com/haschdl)
7+
authors = [Half Scheidl](https://github.com/haschdl), [Jonathan Newman](https://github.com/poetoflight)
88

99
# A web page for your library, NOT a direct link to where to download it.
1010
url = https://github.com/haschdl/pLaunchController
@@ -24,15 +24,14 @@ categories = I/O
2424
# repeating the name of your library here. Also, avoid saying anything redundant
2525
# like mentioning that it's a library. This should start with a capitalized
2626
# letter, and end with a period.
27-
sentence = Control your sketches using the knobs and pads from Novation &reg; Launch Control&reg;.
27+
sentence = Control your sketches using the knobs, pads and slider from MIDI controllers such as Novation &reg; Launch Control&reg;.
2828

2929
# Additional information suitable for the Processing website. The value of
3030
# 'sentence' always will be prepended, so you should start by writing the
3131
# second sentence here. If your library only works on certain operating systems,
3232
# mention it here.
33-
paragraph = Once connected to your computer, use the MIDI controller to control your sketch by\
34-
adjusting the values of variables. This is library is not created by or supported by Novation, \
35-
the manufacturer of the device. It uses standard MIDI protocols, thus does not require any additional drivers.
33+
paragraph = Once connected to your computer, use the MIDI controller to control your sketch by \
34+
adjusting the values of variables. This is library is not created by or supported by Novation.
3635

3736
# Links in the 'sentence' and 'paragraph' attributes can be inserted using the
3837
# same syntax as for authors.
@@ -42,11 +41,11 @@ paragraph = Once connected to your computer, use the MIDI controller to control
4241
# compare different versions of the same library, and check if an update is
4342
# available. You should think of it as a counter, counting the total number of
4443
# releases you've had.
45-
version = 4 # This must be parsable as an int
44+
version = 5 # This must be parsable as an int
4645

4746
# The version as the user will see it. If blank, the version attribute will be
4847
# used here. This should be a single word, with no spaces.
49-
prettyVersion = 1.2 # This is treated as a String
48+
prettyVersion = 2.0.0-alpha # This is treated as a String
5049

5150
# The min and max revision of Processing compatible with your library.
5251
# Note that these fields use the revision and not the version of Processing,

pLaunchController.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
67
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
78
</content>
89
<orderEntry type="inheritedJdk" />
910
<orderEntry type="sourceFolder" forTests="false" />
1011
<orderEntry type="library" name="processing4" level="project" />
12+
<orderEntry type="library" name="uk.co.xfactory.librarians.coremidi4j" level="project" />
1113
</component>
1214
</module>

pLaunchController.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
<zipfileset dir="${basedir}/src" prefix="pLaunchController/src"/>
218218
<zipfileset file="${basedir}/export.txt" prefix="pLaunchController/library"/>
219219
<zipfileset file="${temp.jar.path.pLaunchController.jar2}" prefix="pLaunchController/library"/>
220-
<zipfileset dir="${basedir}/examples" prefix="pLaunchController/examples"/>
220+
<zipfileset dir="/resources/examples" prefix="pLaunchController/examples"/>
221221
<zipfileset file="${basedir}/library.properties" prefix="pLaunchController"/>
222222
</zip>
223223
<mkdir dir="${artifact.output.processinglib}/pLaunchController"/>
@@ -226,7 +226,7 @@
226226
<copy file="${temp.jar.path.pLaunchController.jar}" tofile="${artifact.output.processinglib}/pLaunchController/library/pLaunchController.jar"/>
227227
<mkdir dir="${artifact.output.processinglib}/pLaunchController/examples"/>
228228
<copy todir="${artifact.output.processinglib}/pLaunchController/examples">
229-
<fileset dir="${basedir}/examples"/>
229+
<fileset dir="/resources/examples"/>
230230
</copy>
231231
<mkdir dir="${artifact.output.processinglib}/pLaunchController/src"/>
232232
<copy todir="${artifact.output.processinglib}/pLaunchController/src">

src/pLaunchControl/LaunchControl.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import javax.sound.midi.MidiUnavailableException;
88
import java.lang.reflect.Method;
99

10+
import uk.co.xfactorylibrarians.coremidi4j.CoreMidiDeviceProvider;
11+
import uk.co.xfactorylibrarians.coremidi4j.CoreMidiNotification;
12+
import uk.co.xfactorylibrarians.coremidi4j.CoreMidiException;
13+
14+
1015
import static processing.core.PApplet.println;
1116

1217
/***
@@ -37,6 +42,7 @@
3742
*
3843
*/
3944
public class LaunchControl implements MidiDevice {
45+
public static final String DEVICE_NAME_SUFFIX = "Launch Control";
4046
Method controllerChangedEventMethod, knobChangedEventMethod, padChangedEventMethod;
4147
private static final String controlChangedEventName = "LaunchControlChanged";
4248
private static final String knobChangedEventName = "LaunchControlKnobChanged";
@@ -76,7 +82,7 @@ public Knob getKnob(KNOBS knob) {
7682
public Knob getKnob(int knobIndex) {
7783
//TODO validate knobIndex
7884
KNOBS knobAtPosition = KNOBS.values()[knobIndex];
79-
return knobValues[knobAtPosition.code()];
85+
return knobValues[knobAtPosition.code()];
8086
}
8187

8288

@@ -118,34 +124,46 @@ public void setSliderValueRange(float slider_min, float slider_max) {
118124
throw new UnsupportedOperationException("Method not available. This device does not have sliders.");
119125
}
120126

127+
128+
public LaunchControl(PApplet parent, boolean debug) throws MidiUnavailableException {
129+
this(parent, debug, null);
130+
}
131+
121132
public LaunchControl(PApplet parent) throws MidiUnavailableException {
122-
this(parent, false);
133+
this(parent, false, null);
123134
}
124-
public LaunchControl(PApplet parent, boolean debug) throws MidiUnavailableException {
135+
136+
137+
public LaunchControl(PApplet parent, boolean debug, String deviceName) throws MidiUnavailableException {
125138
this.parent = parent;
126-
this.debug=debug;
139+
this.debug = debug;
127140
for (int i = 0, l = KNOB_COUNT; i < l; i++) {
128141
knobValues[i] = new Knob(i, parent);
129142
}
130143
for (int i = 0, l = PAD_COUNT; i < l; i++) {
131-
padValues[i] = new Pad(i,parent);
144+
padValues[i] = new Pad(i, parent);
132145
}
133-
infos = MidiSystem.getMidiDeviceInfo();
146+
infos = CoreMidiDeviceProvider.getMidiDeviceInfo();
134147
for (javax.sound.midi.MidiDevice.Info info : infos) {
135-
if (info.getName().equals("Launch Control")) {
136-
javax.sound.midi.MidiDevice device = MidiSystem.getMidiDevice(info);
137-
if (info.getClass().getName().equals("com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo")) {
148+
javax.sound.midi.MidiDevice device = MidiSystem.getMidiDevice(info);
149+
if (this.debug)
150+
System.out.println(String.format("Device: %s \t Receivers: %d \t Transmitters: %d", info, device.getMaxReceivers(), device.getMaxTransmitters()));
151+
if ((deviceName != null && info.getName().endsWith(deviceName)) || info.getName().endsWith(DEVICE_NAME_SUFFIX)) {
152+
if (device.getMaxReceivers() == 0) {
138153
deviceIn = device;
139-
println("Connected to Launch Control MIDI Input.");
140-
} else {
141-
println("Connected to Launch Control MIDI Output.");
154+
println("Connected to MIDI Input.");
155+
} else if (device.getMaxTransmitters() == 0) {
156+
println("Connected to MIDI Output.");
142157
deviceOut = device;
143158
}
144159
}
145160
}
146161

147162
if (deviceIn == null) {
148-
println("Launch Control not connected!");
163+
if (deviceName == null)
164+
System.out.printf("A device with name ending with %s was not detected.\n", DEVICE_NAME_SUFFIX);
165+
else
166+
System.out.printf("A device with name you provided was not detected.\nCheck the device name: %s \n", deviceName);
149167
return;
150168
}
151169

@@ -216,7 +234,7 @@ public Pad[] getPads() {
216234
public Pad getPad(int padIndex) {
217235
//TODO validate padIndex
218236
PADS padAtPosition = PADS.values()[padIndex];
219-
return padValues[padAtPosition.code()];
237+
return padValues[padAtPosition.code()];
220238
}
221239

222240

@@ -239,7 +257,7 @@ public void setPad(PADS pad, boolean value, boolean disableEvents) {
239257
if (padValues[pad.code()].value() != value) {
240258
padValues[pad.code()].value(value);
241259
receiver.sendLedOnOff(value, pad);
242-
if(!disableEvents) {
260+
if (!disableEvents) {
243261
midiLaunchControlChanged();
244262
padChanged(pad);
245263
}

src/pLaunchControl/LaunchControlDeviceReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import javax.naming.OperationNotSupportedException;
44
import javax.sound.midi.MidiMessage;
5+
import uk.co.xfactorylibrarians.coremidi4j.CoreMidiReceiver;
6+
57
import javax.sound.midi.Receiver;
68
import javax.sound.midi.SysexMessage;
79

0 commit comments

Comments
 (0)