Exemplo n.º 1
0
        /** This reads event TimeSlice chunks from parentInput's input stream until the next
         * measure start time slice or no more bytesRemaining in the parentInput,
         * adding the TimeSlice objects to the measureStart's time slice list.
         * When this reads the TimeSlice, it also adds the subsequent music
         * symbols to it.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @param measureStart  the MeasureStartTimeSlice to which TimeSlice
         *      objects are added.
         * @see TimeSlice
         */
        public static void addTimeSlices(Riff parentInput, MeasureStartTimeSlice measureStart)
        {
            if (parentInput.getBytesRemaining() <= 0)
            // This is a measure start time slice with nothing after it in the staff
            return;

              if (parentInput.peekFOURCC().Equals(RIFF_ID) &&
              parentInput.peekFirstChunkBYTE() == MEASURE_START)
            // The next chunk is already the start of a new measure
            return;

              TimeSlice timeSlice = RiffTimeSlice.maybeNew(parentInput);
              if (timeSlice == null)
            // For some reason, the first chunk after the measure start
            //   time slice is not an event time slice.  Create a fake one with
            //   start time of 0/1.
            // DEBUG: should mock up an input file and test this.
            timeSlice = new TimeSlice(new Rational(0, 1), null);

              while (true) {
            if (measureStart.getTimeSliceCount() > 0 &&
            measureStart.getTimeSlice
              (measureStart.getTimeSliceCount() - 1).getStartTime().Equals
            (timeSlice.getStartTime()))
              // This new time slice start time is the same as the last one,
              // so just continue using the last one.
              // DEBUG: this still doesn't ensure increasing order
              // DEBUG: This discards the tags in the newly read time slice
              timeSlice =
            measureStart.getTimeSlice(measureStart.getTimeSliceCount() - 1);
            else
              measureStart.addTimeSlice(timeSlice);

            // Read music symbols until the next time slice or
            //    end of the staff.
            RiffTimeSlice.addMusicSymbols(parentInput, timeSlice);
            if (parentInput.getBytesRemaining() <= 0)
              // reached the end of the staff
              break;
            // We know the next chunk is a time slice.  Check whether it is
            //    a measure start.
            if (parentInput.peekFirstChunkBYTE() == MEASURE_START)
              // The next chunk is the start of a new measure
              break;

            // We have now ensured that the next chunk is an event time slice.
            timeSlice = RiffTimeSlice.newInstance(parentInput);
              }
        }
Exemplo n.º 2
0
        /** This reads event TimeSlice chunks from parentInput's input stream until the next
         * measure start time slice or no more bytesRemaining in the parentInput,
         * adding the TimeSlice objects to the measureStart's time slice list.
         * When this reads the TimeSlice, it also adds the subsequent music
         * symbols to it.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @param measureStart  the MeasureStartTimeSlice to which TimeSlice
         *      objects are added.
         * @see TimeSlice
         */
        static public void addTimeSlices
            (Riff parentInput, MeasureStartTimeSlice measureStart)
        {
            if (parentInput.getBytesRemaining() <= 0)
            {
                // This is a measure start time slice with nothing after it in the staff
                return;
            }

            if (parentInput.peekFOURCC().Equals(RIFF_ID) &&
                parentInput.peekFirstChunkBYTE() == MEASURE_START)
            {
                // The next chunk is already the start of a new measure
                return;
            }

            TimeSlice timeSlice = RiffTimeSlice.maybeNew(parentInput);

            if (timeSlice == null)
            {
                // For some reason, the first chunk after the measure start
                //   time slice is not an event time slice.  Create a fake one with
                //   start time of 0/1.
                // DEBUG: should mock up an input file and test this.
                timeSlice = new TimeSlice(new Rational(0, 1), null);
            }

            while (true)
            {
                if (measureStart.getTimeSliceCount() > 0 &&
                    measureStart.getTimeSlice
                        (measureStart.getTimeSliceCount() - 1).getStartTime().Equals
                        (timeSlice.getStartTime()))
                {
                    // This new time slice start time is the same as the last one,
                    // so just continue using the last one.
                    // DEBUG: this still doesn't ensure increasing order
                    // DEBUG: This discards the tags in the newly read time slice
                    timeSlice =
                        measureStart.getTimeSlice(measureStart.getTimeSliceCount() - 1);
                }
                else
                {
                    measureStart.addTimeSlice(timeSlice);
                }

                // Read music symbols until the next time slice or
                //    end of the staff.
                RiffTimeSlice.addMusicSymbols(parentInput, timeSlice);
                if (parentInput.getBytesRemaining() <= 0)
                {
                    // reached the end of the staff
                    break;
                }
                // We know the next chunk is a time slice.  Check whether it is
                //    a measure start.
                if (parentInput.peekFirstChunkBYTE() == MEASURE_START)
                {
                    // The next chunk is the start of a new measure
                    break;
                }

                // We have now ensured that the next chunk is an event time slice.
                timeSlice = RiffTimeSlice.newInstance(parentInput);
            }
        }