Package javax.sound.midi

Examples of javax.sound.midi.MidiEvent


    public void addEvent(int command, int data1)
    {
        try {
            ShortMessage message = new ShortMessage();
            message.setMessage(command, currentTrack, data1);
            MidiEvent event = new MidiEvent(message, getTrackTimer());
            track[currentTrack].add(event);
        } catch (InvalidMidiDataException e)
        {
            // We've kept a good eye on the data.  This exception won't happen.
            e.printStackTrace();
View Full Code Here


    public void addEvent(int command, int data1, int data2)
    {
        try {
            ShortMessage message = new ShortMessage();
            message.setMessage(command, currentTrack, data1, data2);
            MidiEvent event = new MidiEvent(message, getTrackTimer());
            track[currentTrack].add(event);
        } catch (InvalidMidiDataException e)
        {
            // We've kept a good eye on the data.  This exception won't happen.
            e.printStackTrace();
View Full Code Here

    {
        try {
            if (addNoteOn) {
                ShortMessage message = new ShortMessage();
                message.setMessage(ShortMessage.NOTE_ON, currentTrack, data1, data2);
                MidiEvent event = new MidiEvent(message, getTrackTimer());
                track[currentTrack].add(event);
            }

            advanceTrackTimer(duration);

            if (addNoteOff) {
                ShortMessage message2 = new ShortMessage();
                message2.setMessage(ShortMessage.NOTE_OFF, currentTrack, data1, data3);
                MidiEvent event2 = new MidiEvent(message2, getTrackTimer());
                track[currentTrack].add(event2);
            }
        } catch (InvalidMidiDataException e)
        {
            // We've kept a good eye on the data.  This exception won't happen.
View Full Code Here

        for (int i=0; i < tracks.length; i++)
        {
            for (int e=0; e < tracks[i].size(); e++)
            {
                // Get MIDI message and time data from event
                MidiEvent event = tracks[i].get(e);
                long timestamp = event.getTick();

                // Put the MIDI message into the time map
                List<MidiEvent> list = null;
                if ((list = (ArrayList<MidiEvent>)timeMap.get(timestamp)) == null)
                {
View Full Code Here

                for (int ev = 0; ev < trackSize; ev++)
                {
                    counter++;
                    fireProgressReported("Parsing MIDI...", counter, totalCount);
                   
                    MidiEvent event = tracks[t].get(ev);
                    MidiMessage message = event.getMessage();

                    trace("Message received: ",message);
                    parse(message, event.getTick());
                }
            }
        }
    }
View Full Code Here

public class MidiEventTest extends TestCase {
    public void test_getMessage() {
        byte[] bt = new byte[] {1, 2, 3, 4};
        MidiMessage1 message = new MidiMessage1(bt);
        MidiEvent event = new MidiEvent(message, 10L);
        MidiMessage mm = event.getMessage();
        assertEquals(1, mm.getMessage()[0]);
        assertEquals(2, mm.getMessage()[1]);
        assertEquals(3, mm.getMessage()[2]);
        assertEquals(4, mm.getMessage()[3]);
        bt[0] = 10;
        bt[1] = 20;
        bt[2] = 30;
        bt[3] = 40;
        /*
         * values change
         */
        assertEquals(10, mm.getMessage()[0]);
        assertEquals(20, mm.getMessage()[1]);
        assertEquals(30, mm.getMessage()[2]);
        assertEquals(40, mm.getMessage()[3]);
        byte[] nb = mm.getMessage();
        nb[0] = 45;
        nb[1] = -12;
        nb[2] = 90;
        nb[3] = 14;
        /*
         * values don't change
         */
        assertEquals(10, mm.getMessage()[0]);
        assertEquals(20, mm.getMessage()[1]);
        assertEquals(30, mm.getMessage()[2]);
        assertEquals(40, mm.getMessage()[3]);
       
        MidiEvent event1 = new MidiEvent(null, 10L);
        assertNull(event1.getMessage());
    }
View Full Code Here

        assertEquals(1, tr.size());
        assertEquals(0, tr.ticks());
       
        byte[] bt = new byte[] {1, 2, 3};
        MidiMessage1 message = new MidiMessage1(bt);
        MidiEvent event = new MidiEvent(message, 10L);
       
        assertTrue(tr.add(event));
        assertFalse(tr.add(event));
        bt[0] = 10;
        bt[1] = 20;
        assertFalse(tr.add(event));
        /*
         * values change
         */
        assertEquals(10, tr.get(0).getMessage().getMessage()[0]);
        assertEquals(20, tr.get(0).getMessage().getMessage()[1]);
        assertEquals(3, tr.get(0).getMessage().getMessage()[2]);
       
        /*
         * if event is equals null, so it doesn't add to Track, i.e.
         * method add(MidiEvent) return 'false'
         */
        assertFalse(tr.add(null));
       
        /*
         * In the first place, the MidiMessage with the array MidiMessage.data contains
         * -1, 47 and 0 is the meta-event End of Track, and so it
         * accrue to Track always, even it contains meta-event already, i.e. method
         * add(MidiEvent) always return 'true' in this case, but size of
         * Track doesn't increase.
         *
         * In the second place, other events accrue to Track taking
         * into account value of tick of MidiEvent, i.e. the MidiEvent
         * with the smallest value of tick will be the first in the Track
         * and so on and the MidiEvent with the biggest value of tick
         * will be the last but one; the last is the meta-event End of Track
         *
         * If values of ticks of two or more events are equals, they add
         * to Track on the basis of addition, i.e. if any event adds to Track,
         * it will be after events with the same value of tick
         */
        assertTrue(tr.add(new MidiEvent(new MidiMessage1(new byte[] {-1, 47, 0}), -20)));
        assertTrue(tr.add(new MidiEvent(new MidiMessage1(new byte[] {-1, 47, 0}), 0)));
       
        assertTrue(tr.add(new MidiEvent(new MidiMessage1(new byte[] {-23, 92, 89}), 8)));
        assertTrue(tr.add(new MidiEvent(new MidiMessage1(new byte[] {23, 2, -9}), 8)));
       
        assertEquals(-23, tr.get(0).getMessage().getMessage()[0]);
        assertEquals(23, tr.get(1).getMessage().getMessage()[0]);
        assertEquals(10, tr.get(2).getMessage().getMessage()[0]);
        assertEquals(-1, tr.get(3).getMessage().getMessage()[0]);
View Full Code Here

        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
       
        byte[] bt = new byte[] {1, 2, 3};
        MidiMessage1 message = new MidiMessage1(bt);
        MidiEvent event1 = new MidiEvent(message, 10L);
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 0);
        MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
        tr.add(event1);
        tr.add(event2);
        tr.add(event3);
        assertEquals(4, tr.size());
       
        assertTrue(tr.remove(event3));
        assertFalse(tr.remove(event3));
        assertEquals(3, tr.size());
       
        assertFalse(tr.remove(new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 0)));
        assertTrue(tr.remove(event2));
       
        assertFalse(tr.remove(null));
       
        /*
         * I can remove meta-event End of Track
         */
        MidiEvent event4 = tr.get(1);
        assertTrue(tr.remove(event4));
       
        assertTrue(tr.add(event4));
        assertTrue(tr.remove(event4));
       
View Full Code Here

         * create an empty Track
         */
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
        assertEquals(1, tr.size());
        MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), 10L);
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 0);
        MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
        tr.add(event1);
        tr.add(event2);
        tr.add(event3);
        assertEquals(4, tr.size());
        tr.add(event1); //false; it contains already
        assertEquals(4, tr.size());
        tr.remove(event1);
        tr.remove(event2);
        assertEquals(2, tr.size());
        tr.remove(event3);
        tr.remove(tr.get(0));
        assertEquals(0, tr.size());
        tr.add(new MidiEvent(new MidiMessage1(new byte[] {-1, 47, 0}), 6L));
        assertEquals(1, tr.size());
        tr.remove(tr.get(0));
        assertEquals(0, tr.size());
        try {
            tr.add(event1);
View Full Code Here

         * create an empty Track
         */
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
        assertEquals(0, tr.ticks());
        MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), -10L);
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 2L);
        MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
        /*
         * values of Track.ticks() only positive;
         * value of Track.ticks() is the biggest value of ticks of events that
         * contain in the Track;
         * if I remove event with the biggest value of
View Full Code Here

TOP

Related Classes of javax.sound.midi.MidiEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.