K-Gater, Part 5

Yeah, I know that the code layout looks messy.  You can lay things out any way you prefer.  For right now, I’m still focusing mostly on having something I can use to play the K-Pro with.  I’ll worry about code layout later.  If this offends you, sorry.

I’ll finish off the class definitions here and do all of the variable definitions.

class timerExec extends TimerTask – The main timer.
I mentioned before that I’d tried creating two separate timer objects, one for the metronome and one for the gate arp, and that they kept clobbering each other.  My workaround is shown below.  I just made one timer that fires every 1 ms, and then increment a metronome counter, and a gate arp counter.  When either counter hits the top limit, I execute the associated code.  For the metronome, I just display the numbers 1-4 in the Metronome button (I know, I should allow the user to select 1-3, 1-4, 1-5 etc.  I’m also still learning music, so I’m keeping it simple as I start out.)  For the gate arp, I load the arpOn or arpOff times (in milliseconds) into the arp.arpTmr member, and pass the calculated arpeggiated note to the playArp() method.

public kproUI() – The constructor for this entire Java app.
I use the app constructor to initialize the rest of my program.  I don’t know if this is standard Java practice or not, but this is the only way I know of to run init code.

initComponents() – The Netbeans-created init method for setting up all the components, etc.
 initJButtonList() – Load most of the GUI component jButtons into an Array list.
 initMidiDevices() – See if the K-Pro and Roland keyboard are plugged in; create MidiDevices for them if they are.
readSoundBank() – Create the software synth and read its soundbank (instrument voices) into a jComboBox.
initSliders() – A catchall for setting up the GUI components and starting the master timer.

I won’t go into the details of the usages of the variables here.  The comments below are sufficient at the moment.  I will say the following, though:

keyboardBottomNote – Used for changing the octave of the keyboard.
When I buy the Roland keyboard, I’ll replace this variable with something
like “keyboardOctave”.  I’ll probably also create a new keyboard class.

keyboardSpacing – Spacing between keys of the keyboard.
Right now, “1” means that keys go sequentially from 0 to 1, 2, 3, etc.
If I want the keyboard to cover more than one octave, I can do that with
this variable.  This will be moved to the keyboard class later.

keyboardVolume – Holder for MIDI messages.
The default software synth uses standard MIDI short messages, which contain the
channel number, note number, NOTE_ON or NOTE_OFF and velocity.  (The K-Pro doesn’t have
velocity control, it just has “program volume” for the entire instrument.)
So, I’m defaulting velocity to 50 here.  Later, I’ll replace this with the
velocity data coming from the Roland keyboard.

keyboardKey – Number of the desired key to be pressed.
I’ll replace this with the actual key pressed from the Roland data.

selectedArpFile – Arpeggiator pattern file name.
Bad things happen if you don’t have pattern data loaded when you try to
start the Gate Arp (null pointer exceptions).  Also, I want to include this
file name when the user stores the patches to file.

lastSavedPatchFile – Name of the patch file for use with Patch Save.
I tried getting fancy. If the User selects File->Save, then I’ll automatically
save to the name stored in this variable without bringing up the File Dialog.
If the patches haven’t been saved yet, or if the user selects File->SaveAs,
I’ll open the dialog box.

jBList – List of most of the jButtons
I want to change the button background color, and text, to show which preset is
currently being played for either the K-Pro or the software synth, and the
instrument voice assigned to each.  Rather than use if-statements or switch-case
(which I started doing), I’m loading the jButtons into a jButton ArrayList.
Much easier this way.  If I were doing this in raw Java, I’d use a for-loop.
Instead, because of the Netbeans limitation, I’m adding each jButton one
line at a time.

kProInstruments[] – Array of K-Pro instrument names.
Because Korg didn’t implement the K-Pro software driver as part of the synthesizer
class (I’m guessing this is why), I can’t make a synthesizer object for querying
the K-Pro for the soundbank.  Instead, I had to handtype the instrument names here
and hardcode them into this array.

————————– Raw code

Formatted text file.
// Create the timer that handles both executing the metronome and the gate arp.

class timerExec extends TimerTask {                        // The heart of the timer
public void run() {
if(met.tmr > -1) {                                    // Code for metronome
if(met.tmr >= met.bpmTotal) {
met.tmr = 0;                                   // Need to restart the metronome timer each time
met.cntr = (met.cntr < 4) ? met.cntr + 1: 1;
if(arp.arpTmr > -1) {
if(arp.arpTmr >= arp.arpTime) {
playArp(arp.calcNote);                        // arpeggiator timer reset automatically in playArp()

/** Creates new form kproUI */
public kproUI() {

boolean debug = false;

timerExec       ttd                = new timerExec();
Timer           masterTimer        = new Timer();
MidiDevice      kProDevice         = null;    // Pointer to the kPro if it is plugged in and turned on.
int             channelNo          = 0;       // Currently selected channel number via the preset buttons.
boolean         kSaveTo            = false;   // Flag for when user wants to save to a K-Pro voice preset
boolean         dSaveTo            = false;   // Flag for saving to the software synth voice preset.
boolean         suppressUpdate     = true;    // Used to prevent “Add Patch” from inputting patch twice.
int             lastButtonSelected = 1;       // Number for the voice preset jButtons last selected by the user.
int             lastPatternSel     = 0;       // Number of the gate arp pattern last selected by the user.
Soundbank       soundbank          = null;    // Contains the software synth instrument list, bank and patch numbers.
Synthesizer        synth              = null;    // Pointer to the Java software synth.
MidiChannel []  channels           = null;    // Software synth MIDI channel voice assignments.
Instrument[]    aInstruments       = null;    // Software synth instrument voice assignments.
int             keyboardBottomNote = 0;       // Default the starting note of the keyboard.
int             keyboardSpacing    = 1;       // Increment each key by one on the keyboard
int             keyboardVolume     = 50;      // Default value for the MIDI velocity variable.
int             keyboardKey        = 5;       // Default to keyboard key 5 always pressed.
String          selectedArpFile    = “”;      // Init the arpeggiator patterns file name.
String          lastSavedPatchFile = “”;      // Name of current patch file, for use with Save Patch.

int []   kProVoices      = {0, 0, 0, 0, 0, 0, 0, 0};                   // For storing 8 instrument voices from the K-Pro.
int []   defaultVoices   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};       // For storing 12 instrument voices from the default synth

ArrayList<JButton> jBList = new ArrayList<JButton>();

// The K-Pro driver isn’t implemented as an instance of the synthesizer class, so there’s no way to query it directly to
// get the instrument list.  The only alternative is to hand-load it here.

String kProInstruments[] = {“L.000 Synth Lead”,
“L.001 Sync”,
“L.002 Sine Portamt”,
“L.003 LFO Squ Lead”,
“L.004 PWM Lead”,
“L.005 Micro Lead”,
“L.006 Mini Lead”,
“L.007 Crazy Lead”,
“L.008 Syn Decay”,
“L.009 5th Lead”,
“L.010 Basic Arp”,
“L.011 Unison Lead”,
“L.012 XMod Decay”,
“L.013 Soft Lead”,
“L.014 Deci X Lead”,
“L.015 Talk”,
“L.016 Syn Brass”,
“L.017 5th Decay”,
“L.018 MS20 Lead”,
“L.019 Saw Lead”,
“L.020 Fe-Voice”,
“L.021 Ring Detune”,
“L.022 Orange Lead”,
“L.023 Dist Lead”,
“L.024 5th Brass”,
“L.025 Belec”,
“L.026 Ambient”,
“L.027 LR 5th Lead”,
“L.028 Tell Min”,
“L.029 FeedbackLead”,
“L.030 Sync Lead”,
“L.031 Square Bell”,
“L.032 Square Lead”,
“L.033 Unison Sweep”,
“L.034 3octave Lead”,
“L.035 XY Scale”,
“L.036 Digital Talk”,
“L.037 LFO Lead”,
“L.038 XMod SawLead”,
“L.039 Pitch Mod”,
“A.040 Vibraphone”,
“A.041 Trumpet”,
“A.042 Piano”,
“A.043 Tape Flute”,
“A.044 Dist Guitar”,
“A.045 E.Piano”,
“A.046 Glass Bell”,
“A.047 Phase Clav”,
“A.048 Digerido”,
“A.049 Elec Sitar”,
“A.050 Duo Strings”,
“A.051 Jazz Guitar”,
“A.052 Tenor Sax”,
“A.053 Harmonica”,
“A.054 Flute”,
“B.055 House Bass”,
“B.056 Slap Bass”,
“B.057 Bad Bass”,
“B.058 Disco Bass”,
“B.059 Attack Bass”,
“B.060 Hoover Bass”,
“B.061 Talk Bass”,
“B.062 AcousticBass”,
“B.063 Simple Bass”,
“B.064 Fat Bass”,
“B.065 Elec Bass”,
“B.066 Big Bass”,
“B.067 Synth Bass”,
“B.068 Sexy Bass”,
“B.069 Kick Bass”,
“B.070 Reso Bass”,
“B.071 Acid Bass”,
“B.072 Unison Bass”,
“B.073 Boost Bass”,
“B.074 XMod Bass”,
“B.075 Fall Bass”,
“B.076 Zap Bass”,
“B.077 Ring Bass”,
“B.078 Square Bass”,
“B.079 DistSawBass”,
“B.080 MG Bass”,
“B.081 Bit Bass”,
“B.082 Stereo Bass”,
“B.083 Valve Bass”,
“B.084 Organ Bass”,
“C.085 Filter Chord”,
“C.086 Side Chain”,
“C.087 ArpeggioSine”,
“C.088 Wurly Chord”,
“C.089 Guitar Chord”,
“C.090 E.Guitar Hit”,
“C.091 Pad Chord 1”,
“C.092 UM Sequence”,
“C.093 2039”,
“C.094 Filter Mod”,
“C.095 Decay Chord”,
“C.096 ArpeggioDown”,
“C.097 Electro Stab”,
“C.098 Synth Chord”,
“C.099 Motion Chord”,
“C.100 ArpeggioPuls”,
“C.101 Phaser Chord”,
“C.102 EL Chord”,
“C.103 Chord Seq”,
“C.104 FilterMod5th”,
“C.105 Pad Chord 2”,
“C.106 DecaySynChod”,
“C.107 Trance Chord”,
“C.108 Sine Chord”,
“C.109 Organ Chord”,
“C.110 Sweep Chord”,
“C.111 Power Chord”,
“C.112 BPF Chord”,
“C.113 E.Piano Chod”,
“C.114 Chord Hit”,
“S.115 Resonate”,
“S.116 Helicopter”,
“S.117 Orch Hit”,
“S.118 Rise/Fall”,
“S.119 IndustrySFX”,
“S.120 Infinity”,
“S.121 XY Cat”,
“S.122 8bit Noise”,
“S.123 HPF Square”,
“S.124 Kaoss Drone”,
“S.125 Quiz Show”,
“S.126 Game SFX”,
“S.127 Sync Random”,
“S.128 Noise Filter”,
“S.129 8bit Game”,
“S.130 Metal”,
“S.131 Siren”,
“S.132 Missile”,
“S.133 Random”,
“S.134 Beam Saber”,
“S.135 Synth Looper”,
“S.136 Ring Mod”,
“S.137 Voice Looper”,
“S.138 Sweep”,
“S.139 Drop”,
“D.140 Conga”,
“D.141 Rock Kit”,
“D.142 Tom”,
“D.143 House Kit 1”,
“D.144 House Kit 2”,
“D.145 Techno Kit”,
“D.146 Disco Kit”,
“D.147 Hip Hop Kit”,
“D.148 Standard Kit”,
“D.149 80’s Kit”,
“D.150 Cymbal-Revb”,
“D.151 Cymbal-Filt”,
“D.152 Clap”,
“D.153 Percussion”,
“D.154 Zap/Hit”,
“D.155 Phone/Clap”,
“D.156 BD/SD”,
“D.157 Filter Snare”,
“D.158 Timpani”,
“D.159 XMod Perc”,
“P.160 Hip Hop 1”,
“P.161 House 1”,
“P.162 Jam Guitar”,
“P.163 House 2”,
“P.164 Conga Loop”,
“P.165 Techno”,
“P.166 House 3”,
“P.167 Electro”,
“P.168 Dubstep”,
“P.169 Reggaeton”,
“P.170 Hip Hop 2”,
“P.171 Disco”,
“P.172 Rock”,
“P.173 Breakbeats”,
“P.174 Drum’n’Bass”,
“P.175 Bossa Nova”,
“P.176 Lo-Fi Breaks”,
“P.177 Zap Beat”,
“P.178 XY Drum”,
“P.179 Deci Beat”,
“P.180 Beat Box”,
“P.181 Grain Beat”,
“P.182 Call Me”,
“P.183 Taiko”,
“P.184 Robo”,
“V.185 Vocod-Unison”,
“V.186 Vocod-Pulse”,
“V.187 Vocod-Chord1”,
“V.188 Vocod-Detune”,
“V.189 Vocod-Deci”,
“V.190 Vocod-5th”,
“V.191 Vocod-Chord2”,
“V.192 Vocod-Saw”,
“V.193 Vocod-Echo”,
“V.194 Vocod-Formnt”,
“V.195 Audio-Pitch”,
“V.196 Audio-Grain”,
“V.197 Audio-Delay”,
“V.198 Audio-Filter”,
“V.199 Audio-Looper”};

Previous Post
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: