Results 1 to 5 of 5
Thread: MidiEvent Issues.
- 01-03-2012, 06:23 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
MidiEvent Issues.
Hey everyone,
I'm currently working through a tutorial on how to draw graphics in time with music and the first step in this tutorial
is to simply learn how to build a static utility method that makes a message and returns a midi event. The problem I'm having is that
my makeEvent method doesn't return a midiEvent but from what I can tell I've done it the right way. I'm still learning a lot about Java and really can't tell where I have gone wrong.
Below is my code.
Thanks in advance if anyone can offer any help
Dan
Java Code:package gui; import javax.sound.midi.*; public class MiniMusicPlayer1 { public static void main(String[]args){ try{ Sequencer sequencer = MidiSystem.getSequencer(); //This creates a new instance of the sequencer sequencer.open(); // This opens the sequencer up, ready for use Sequence seq = new Sequence(Sequence.PPQ,4); // This create a new sequence Track track = seq.createTrack(); // This creates a new track for (int i = 5; i< 61; i+= 4){ //This for loop makes a bunch of events that keeps the notes going up in a scale from 5 to 61. track.add(makeEvent(144,1,i,100,i)); track.add(makeEvent(128,1,i,100,i+2)); } sequencer.setSequence(seq); sequencer.setTempoInBPM(220); sequencer.start(); } catch(Exception ex) { ex.printStackTrace(); } } public static MidiEvent makeEvent(int comd, int chan, int one, int two, int tick) { MidiEvent event = null; try{ ShortMessage a = new ShortMessage(); // Making a new instance of a message a.setMessage(comd, chan, one, two); // Calling set message with instructions event = new MidiEvent(a, tick); // Making a MidiEvent instance for the message }catch(Exception e) { } return event; //returns a MidiEvent all loaded with the message. } }
- 01-03-2012, 05:43 PM #2
Re: MidiEvent Issues.
What is it returning? Is it null?
- 01-03-2012, 05:56 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Re: MidiEvent Issues.
Why are you so sure?my makeEvent method doesn't return a midiEvent
- 01-04-2012, 09:38 AM #4
Re: MidiEvent Issues.
Never do that. At the very least, print or log the stack trace.}catch(Exception e) { }
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-05-2012, 05:16 AM #5
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: MidiEvent Issues.
Hey man,
Thanks for the response!
I managed to get it working, turns out I already had a class called "makeEvent "in the same package. I think
eclipse might of auto created it really not sure. I acknowledge your advice on exceptions I need to get use to that wwhole system.
Thanks again for your repliesLast edited by iamdeaneyelid; 01-05-2012 at 05:19 AM.
Similar Threads
-
GUI Issues
By larry_d1990 in forum Advanced JavaReplies: 2Last Post: 03-17-2011, 02:35 PM -
MidiEvent status not recognised by Java
By JellevM in forum Advanced JavaReplies: 0Last Post: 02-19-2011, 11:01 AM -
Int to String Issues
By xael in forum New To JavaReplies: 6Last Post: 09-21-2010, 08:08 PM -
jdk issues
By artemff in forum New To JavaReplies: 3Last Post: 01-02-2010, 03:18 AM -
Issues with Jva I.O
By Annatar01 in forum New To JavaReplies: 0Last Post: 02-08-2008, 01:16 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks