Fun with MIDI

Post Reply
Doc Joe
Posts: 43
Joined: Thu Oct 29, 2020 7:53 pm

Fun with MIDI

Post by Doc Joe »

Hi folks,

I am only just getting into writing a MIDI interface. I am creating a control panel for the NDLR. In short, the control will be a bunch of buttons that send individual MIDI CC messages to a MIDI channel via a MIDIOutputJack.

I've read the oracle code, added the appropriate library and have been testing code, but keep getting an error on the message creation. Here is an example of the code:

javax.sound.midi.ShortMessage myMsg = new ShortMessage(); // the constructor
myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93); // which will eventually be set as midi_msg.setMessage( midi_cc, midi_channel, midi_range, midi_range );

Note, this code is from the Oracle Java page: https://docs.oracle.com/javase/tutorial ... sages.html

During build, I get this error.

Mymodule.java:555: error: unreported exception InalidMidiDataException; must be caught or declaired to be thrown;
myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93)
^
The ^ symbol is positioned under the open (

Any clues as to what I may be doing wrong, or perhaps it my configuration?
User avatar
honki-bobo
Posts: 310
Joined: Sat Nov 09, 2019 1:18 pm

Re: Fun with MIDI

Post by honki-bobo »

Hi Doc Joe,

according to the API documentation, setMessage throws an InalidMidiDataException if the status byte or all data bytes belonging to the message, do not specify a valid MIDI message. You need to surround it with a try-catch-block to handle the exception, if it occurs:

Code: Select all

try {
    myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
} catch (InvalidMidiDataException e) {
    // do something
}
For more information on catching and handling exceptions see this Java tutorial.

Hope this helps.

Best regards,
Martin
Image
Monkey Business Audio
Modules - Music - Twitter - YouTube
jgillmanjr
Posts: 15
Joined: Wed Mar 31, 2021 12:14 am

Re: Fun with MIDI

Post by jgillmanjr »

I got bit with that exact same thing when I first started writing my module (hooray for using module development as a project to learn Java lol).
A data engineer and pilot that occasionally makes sounds suitable for public consumption.

I've started making modules too!
Doc Joe
Posts: 43
Joined: Thu Oct 29, 2020 7:53 pm

Re: Fun with MIDI

Post by Doc Joe »

Woohoo. After some messing about and the above advice, I got the proof of concept for an NDLR controller module in Voltage working.

Now to create all the various controls, knobs and options! I planning to have the all NDRL controls available as buttons/sliders with CV input and attenverters, so we can use Voltage not only as an interface to the NDRL, but also to be controlled by generative modules, such as those of Bernard and Weevil (awesomeness squared).

So... a generative hardware sequencer being controlled by virtual generative modules and sequencers, feedbacking back to more virtual modules and/or hardware synths.

A design consideration: I am thinking of creating 5 separate modules to control the NDLR. One for the overall unit (the master controls) and one module each for the four NDLR players - Pad, Drone, Motif 1 and Motif 2. That way, we won't end up with a massively wide control. It also means we can position each module next to any modules that are being controlled by the NRDL. What do folks think about that as an idea? Is breaking up the controller into five modules the right way to go, or would you prefer one big module with everything?

Any other ideas for this module would be welcome. The NDLR is a lovely bit of kit, and perfect when used with Voltage.

Best regards,
Joe
Doc Joe
Posts: 43
Joined: Thu Oct 29, 2020 7:53 pm

Re: Fun with MIDI

Post by Doc Joe »

For those also on a similar journey, here is the ProcessSample code for this:

// midi_channel is the numbe rof the midi channal (duh). Not that it is a range of 0 to 15 (not 1 to 16)
// buttons, etc can change the midi_cc value (data 1 of the midi event)
// midi_data2 represents the value being sent to the specific midi control_code
// in my proof of concept, I set midi_cc to 26 and midi_data2 to 7, which corresponds to setting the NDRL chords to 7ths.

if (midi_cc != 0 )
{

try {
myMsg.setMessage( ShortMessage.CONTROL_CHANGE, midi_channel, midi_cc, midi_data2);
midiOutputJack.ClearMessages();
midiOutputJack.AddMessage( myMsg);
}
catch (InvalidMidiDataException e)
{
// report the error to a textLabel on the control
textLabel1.SetText( e.toString() );
}
// reset the midi_cc and midi_data2 values to 0, so the processing will not repeat
midi_cc = 0;
midi_data2 = 0;
}
sdv
Posts: 73
Joined: Fri Mar 27, 2020 7:21 pm

Re: Fun with MIDI

Post by sdv »

So, how is your NDLR interface module coming along? I have one and it would be fun to breathe some new life into it.
User avatar
Waverley Instruments
Posts: 147
Joined: Thu May 05, 2022 2:10 pm

Re: Fun with MIDI

Post by Waverley Instruments »

Doc Joe wrote: Thu Apr 29, 2021 11:50 pm // report the error to a textLabel on the control
textLabel1.SetText( e.toString() );
Personally, I wouldn't do UI updates in ProcessSample(). I'd set an error flag which you could check in your GUI update timer handler and set the status message there.

Sorry just realised this was quite an old post! :oops:

Cheers, -Rob @ WI
Post Reply

Return to “Module Designer”