Package javax.sound.midi

Examples of javax.sound.midi.Track


     * test method get(int)
     * @throws Exception
     */
    public void test_get() throws Exception {
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
       
        /*
         * numeration of events begin with 0, and so the first
         * event gets with index 0, the second - with index 1
         * and so on
         */
        try {
            tr.get(-1);
            fail("ArrayIndexOutOfBoundsException expected");
        } catch (ArrayIndexOutOfBoundsException e) {}
       
        try {
            tr.get(1);
            fail("ArrayIndexOutOfBoundsException expected");
        } catch (ArrayIndexOutOfBoundsException e) {}
    }
View Full Code Here


    public void test_remove() throws Exception {
        /*
         * create an empty Track
         */
        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));
       
        assertTrue(tr.remove(event1));
       
        /*
         * If I remove meta-event End of Track and I have some
         * events in Track still, and I try to add new event, it's
         * all right, it adds, and so meta-event End of Track adds too;
         * if Track doesn't contain any events, i.e. method size()
         * return 0, if I try to add meta-event End of Track, it's
         * all right, but if I try to add not meta-event, I have some problem.
         * In the first place, meta-event adds to the Track, but event
         * I want to add doesn't add, i.e. size() return 1. But after it
         * I use method add(MidiEvent), and
         * method add(<the_same_event_I_want_to_add>) return 'false'!!!
         * And method remove(<the_same_event_I_want_to_add>) return
         * 'false' too! And only now method add(<the_same_event_I_want_to_add>)
         * return 'true', and this event adds to Track;
         * Other events accrue to Track correctly.
         */
        assertEquals(0, tr.size());
       
        assertTrue(tr.add(event4)); //add meta-event to empty track; it's OK
       
        assertTrue(tr.add(event1)); //add some event
        assertEquals(2, tr.size());
        assertTrue(tr.remove(event4)); //remove meta-event End of Track
        assertTrue(tr.add(event2)); //add some event...
        assertEquals(3, tr.size()); //...and size of Track is 3; meta-event
                                    //was added
        assertTrue(tr.remove(tr.get(2)));
        assertTrue(tr.remove(event2));
        assertTrue(tr.remove(event1)); //now Track is empty
        try {
            tr.add(event2); //add some event; I catch exception
            fail("ArrayIndexOutOfBoundsException expected");
        } catch (ArrayIndexOutOfBoundsException e) {}
        assertEquals(1, tr.size()); //size of Track is 1; it contain meta-event
        assertTrue(tr.add(event1)); //I can add event1,...
        assertFalse(tr.add(event2)); //...but I can't add event2...
        assertFalse(tr.remove(event2)); //...and remove it too!
        assertTrue(tr.add(event2)); //but now it's all right!
        assertEquals(3, tr.size()); //Track contain two my events and meta-event
    }
View Full Code Here

    public void test_size() throws Exception {
        /*
         * 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);
            fail("ArrayIndexOutOfBoundsException expected");
        } catch (ArrayIndexOutOfBoundsException e) {}
        assertEquals(1, tr.size());
    }
View Full Code Here

    public void test_ticks() throws Exception {
        /*
         * 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
         * tick, value that return method Track.ticks() will be the same
         */
        tr.add(event1);
        assertEquals(0, tr.ticks());
        tr.add(event2);
        assertEquals(2, tr.ticks());
        tr.add(event3);
        assertEquals(6, tr.ticks());
        tr.remove(event3); //I remove event with the biggest tick,...
        assertEquals(6, tr.ticks()); //...but value that return method Track.ticks() the same
        tr.remove(event2);
        tr.remove(event1);
        assertEquals(6, tr.ticks()); //and even now...
        tr.add(event2);
        assertEquals(6, tr.ticks()); //and now...
        tr.remove(tr.get(1));
        tr.remove(event2);
        assertEquals(0, tr.size()); //Track is empty
        assertEquals(0, tr.ticks()); //Track is empty, value that return Track.ticks() equals 0
    }
View Full Code Here

     */
    public void test_createTrack() throws Exception {
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        assertEquals(9, seq.getTracks().length);

        Track tr = seq.createTrack();
        Track tr1 = seq.createTrack();
        /*
         * returned Track is the same that create with constructor,
         * but size of vector increase
         */
        assertEquals(1, tr.size());
        assertEquals(3, tr.get(0).getMessage().getMessage().length);
        assertEquals(-1, tr.get(0).getMessage().getMessage()[0]);
        assertEquals(47, tr.get(0).getMessage().getMessage()[1]);
        assertEquals(0, tr.get(0).getMessage().getMessage()[2]);
       
        assertEquals(1, tr1.size());
        assertEquals(3, tr1.get(0).getMessage().getMessage().length);
        assertEquals(-1, tr1.get(0).getMessage().getMessage()[0]);
        assertEquals(47, tr1.get(0).getMessage().getMessage()[1]);
        assertEquals(0, tr1.get(0).getMessage().getMessage()[2]);
       
        assertEquals(11, seq.getTracks().length);
       
        /*
         * new Tracks accrue to the end of vector
         */
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 3L);
        tr1.add(event2);
        assertEquals(23, seq.getTracks()[10].get(0).getMessage().getMessage()[0]);
    }
View Full Code Here

     * test method deleteTrack(Track)
     * @throws Exception
     */
    public void test_deleteTrack() throws Exception {
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
        Track tr1 = seq.createTrack();
        assertEquals(11, seq.getTracks().length);
       
        tr.add(new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), 10));
        assertTrue(seq.deleteTrack(tr));
        assertFalse(seq.deleteTrack(tr));
View Full Code Here

     * test method getMicrosecondLength()
     *
     */
    public void test_getMicrosecondLength() throws Exception {
        Sequence seq = new Sequence(Sequence.PPQ, 15, 2);
        Track tr = seq.createTrack();
        MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), -10L);
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 3L);
        MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
       
        /*------- Sequence.PPQ -------*/
        tr.add(event2);    
        assertEquals(100000, seq.getMicrosecondLength());
        Track tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(200000, seq.getMicrosecondLength());
        seq.deleteTrack(tr1);
        assertEquals(100000, seq.getMicrosecondLength());
        seq.deleteTrack(tr);
        assertEquals(0, seq.getMicrosecondLength());
       
        /*------- Sequence.SMPTE_24 -------*/
        event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 0L);
        seq = new Sequence(Sequence.SMPTE_24, 17, 2);
        tr = seq.createTrack();
        tr.add(event2);    
        assertEquals(0, seq.getMicrosecondLength());
        tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(14705, seq.getMicrosecondLength());
        seq.deleteTrack(tr1);
        assertEquals(0, seq.getMicrosecondLength());
       
        /*------- Sequence.SMPTE_25 -------*/
        event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 3L);
        event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 97913L);
        seq = new Sequence(Sequence.SMPTE_25, -5, 2);
        tr = seq.createTrack();
        tr.add(event2);    
        assertEquals(-24000, seq.getMicrosecondLength());
        tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(-783304000, seq.getMicrosecondLength());
        seq.deleteTrack(tr1);
        assertEquals(-24000, seq.getMicrosecondLength());

        /*------- Sequence.SMPTE_30 -------*/
        seq = new Sequence(Sequence.SMPTE_30, 0, 2);
        tr = seq.createTrack();
        tr.add(event2);    
        assertEquals(9223372036854775807L, seq.getMicrosecondLength());
        tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(9223372036854775807L, seq.getMicrosecondLength());
        seq.deleteTrack(tr1);
        assertEquals(9223372036854775807L, seq.getMicrosecondLength());
       
        /*------- Sequence.SMPTE_30DROP -------*/
        seq = new Sequence(Sequence.SMPTE_30DROP, 17, 2);
        tr = seq.createTrack();
        tr.add(event2);    
        assertEquals(5888L, seq.getMicrosecondLength());
        tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(192178456L, seq.getMicrosecondLength());
        seq.deleteTrack(tr1);
        assertEquals(5888L, seq.getMicrosecondLength());
    }
View Full Code Here

        //TODO
        /*
         * I don't understand how this method works
         */
        Sequence seq = new Sequence(Sequence.PPQ, 987, 2);
        Track tr = seq.createTrack();
        MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3, 34, -98, -27}), -10L);
        MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4, 78, -12, 5}), 3L);
        MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1, 87, 9, 8, -2}), 6L);
        tr.add(event1);
        tr.add(event3);
        Track tr1 = seq.createTrack();
        tr1.add(event2);
        assertEquals(0, seq.getPatchList().length);
    }
View Full Code Here

     * test method getTickLength()
     *
     */
    public void test_getTickLength() throws Exception {
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        Track tr = seq.createTrack();
        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);
        tr.add(event1);
        tr.add(event2);
       
        assertEquals(2, seq.getTickLength());
        Track tr1 = seq.createTrack();
        tr1.add(event1);
        tr1.add(event2);
        tr1.add(event3);
        assertEquals(6, seq.getTickLength());
        seq.deleteTrack(tr1);
        assertEquals(2, seq.getTickLength());
        seq.deleteTrack(tr);
        assertEquals(0, seq.getTickLength());
View Full Code Here

     *
     */
    public void test_getTracks() throws Exception {
        Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
        seq.createTrack();
        Track tr1 = seq.createTrack();
       
        Track[] tracks = seq.getTracks();
        assertEquals(11, tracks.length);
       
        /*
 
View Full Code Here

TOP

Related Classes of javax.sound.midi.Track

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.