Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: MidiEvent Issues.

  1. #1
    iamdeaneyelid is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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. 
    
    
    } 
    
    }

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,297
    Rep Power
    5

    Default Re: MidiEvent Issues.

    What is it returning? Is it null?

  3. #3
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    248
    Rep Power
    2

    Default Re: MidiEvent Issues.

    my makeEvent method doesn't return a midiEvent
    Why are you so sure?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,918
    Rep Power
    16

    Default Re: MidiEvent Issues.

    }catch(Exception e) { }
    Never do that. At the very least, print or log the stack trace.

    db
    quad64bit likes this.
    Why do they call it rush hour when nothing moves? - Robin Williams

  5. #5
    iamdeaneyelid is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default 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 replies
    Last edited by iamdeaneyelid; 01-05-2012 at 05:19 AM.

Similar Threads

  1. GUI Issues
    By larry_d1990 in forum Advanced Java
    Replies: 2
    Last Post: 03-17-2011, 02:35 PM
  2. MidiEvent status not recognised by Java
    By JellevM in forum Advanced Java
    Replies: 0
    Last Post: 02-19-2011, 11:01 AM
  3. Int to String Issues
    By xael in forum New To Java
    Replies: 6
    Last Post: 09-21-2010, 08:08 PM
  4. jdk issues
    By artemff in forum New To Java
    Replies: 3
    Last Post: 01-02-2010, 03:18 AM
  5. Issues with Jva I.O
    By Annatar01 in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •