The Artima Developer Community
Sponsored Link

Java Answers Forum
Help Cleaning Code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tim W

Posts: 12
Nickname: daniel1980
Registered: Oct, 2005

Help Cleaning Code Posted: Dec 5, 2005 7:59 AM
Reply to this message Reply
Advertisement
Hi everyone,

I would appreciate if someone could help me out cleaning up the code below for a basic program i am doing. Im still very much a begginer but ive added comments to most things to make it easier. The code near the end of class is probably wrong so anyhelp on that would be apprecaited.

Heres the code, thanks for your time:



//
// BasicMonitor.java
// BasicMonitor
//
//
import java.util.*;
import javax.sound.midi*;
import javax.swing.*;
import static javax.sound.Midi.ShortMessage.*;

public class BasicMonitor {

public static void main (String args[]) {

// Poll system for midi devices

MidiDevice.info[]devicelist = MidiSystem.getMidiDeviceInfo();

// Ask user to select the input device

MidiDevice.Info deviceInfo =
(MidiDevice.Info)
JOptionPane.showInputDialog (
null,
"Select MIDI Device",
"Program name",
JOptionPane.QUESTION_MESSAGE,
null,
deviceList,
null);

System.out.println ("Selected device = " + deviceInfo);

// See if the user pressed cancel

if (deviceInfo != null) {
try {
MidiDevice device = MidiSystem.getMidiDevice (deviceInfo);
device.open();

// Create the display window

MidiMonitorWindow win = new MidiMonitorWindow ("Tims Midi Monitor Window")

// Create the message buffer

MessageByteBuffer buffer = new MessageByteBuffer ();

// Create a reciever which puts message into buffer

MonitoringReciever r = new (buffer);

// Connect the reciever to the devices transmitter

transmitter t = device.getTransmitter ()
t.SetReceiver (r);


// Setup infinite loop
while (true) {
MidiMessage message = bufferObject.get ();

// Check if message exists
if (byteData != null) {
byte [] byteData = message.getMessage ();
for (byte b : byteData) {
int i = b & 0xFF;
System.out.print (i + " ");
}
System.out.println ();
}

// Get status byte and extract command and channel bits
int status = byteData [0] &0xFF;
int command = status & 0xF0;
int channel = status & 0xF0;

// Process message according to the command bits
switch (command) {
case NOTE_ON;

// Check if note on or alternative note off
if (byteData [2]!=0) {
win.ShowNoteon (channel, byteData [1], byteData [2] }

else
win.showNoteoff (channel, byteData [1], byteData [2] }
break

case Note_0ff;
win.ShowNoteoff (channel, byteData [1], byteData [2] }

case Pitch_Bend;
Win.show PitchBend (channel byteData [1], byteData [2] }

case Poly;
Win.show PolykeyPressure (channel byteData [1], byteData [2])

case Control_Change;
Win.show ControlChange (channel byteData [1], byteData [2])

case Program_Change;
Win.show ProgramChanage (channel byteData [1], byteData [2])

After Case;
Default:

// System message, is it one were interested in?
if (status == Active_sensing)(
win.showActiveSensing();
{
else if
Timing == Clock
win.timingClock();

else
System == Exclusive
win.systemExlusive();

thread yeild ();

catch (MidiUnavailableException e) {
System.out.println ("Exception thrown " + e);
}
}


Thanks

Topic: JSP/Servlets newbie question Previous Topic   Next Topic Topic: Barcode terminals ppc

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use