예제 #1
0
        /** Creates new StaffSystem from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public StaffSystem newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            StaffSystem staffSystem = new StaffSystem
                                          (RiffStaffSystemHeader.newInstance(riffInput));

            // debug: check for NIFFStaffGrouping

            while (riffInput.getBytesRemaining() > 0)
            {
                Staff staff;
                if ((staff = RiffStaff.maybeNew(riffInput)) != null)
                {
                    // Call addChild() which will set the child's parent to this.
                    staffSystem.addStaff(staff);
                }
                // debug: must check for NIFFFontSymbol, etc.
                else
                {
                    // Did not recognize the chunk type, so skip
                    riffInput.skipChunk();
                }
            }

            return(staffSystem);
        }
예제 #2
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF String Table, then decode it and store it in the
         * root RIFFForNIFF object.
         * If the next item is not a NIFF String Table, do nothing
         * and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream.
         *        If parentInput.getParent() is not of type RIFFForNIFF, then this
         *        moves the input past the String Table but does not store it.
         * @return true if the String Table was processed, false if this is
         *         not a String Table.
         */
        static public bool maybeDecode(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            {
                return(false);
            }

            Riff riffInput = new Riff(parentInput, RIFF_ID);

            if (!(parentInput.getParent() is RiffForNiff))
            {
                // There is no place to store the data
                riffInput.skipRemaining();
                return(true);
            }
            RiffForNiff riffForNiff = (RiffForNiff)parentInput.getParent();

            // Read the entire string table into a byte array
            byte[] stringTable = new byte[riffInput.getBytesRemaining()];
            for (int i = 0; i < stringTable.Length; ++i)
            {
                stringTable[i] = (byte)riffInput.readBYTE();
            }
            riffForNiff.setStringTable(stringTable);

            // This skips possible pad byte
            riffInput.skipRemaining();

            return(true);
        }
예제 #3
0
파일: RiffPage.cs 프로젝트: svejdo1/niffty
        /** Creates new Page from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public Page newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            Page page = new Page(RiffPageHeader.newInstance(riffInput));

            while (riffInput.getBytesRemaining() > 0)
            {
                StaffSystem staffSystem;
                if ((staffSystem = RiffStaffSystem.maybeNew(riffInput)) != null)
                {
                    page.addSystem(staffSystem);
                }
                // debug: must check for NIFFFontSymbol, etc.
                else
                {
                    // Did not recognize the chunk type, so skip
                    riffInput.skipChunk();
                }
            }

            return(page);
        }
예제 #4
0
        /** Creates new ScoreSetup from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public ScoreSetup newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            NiffInfo         niffInfo         = null;
            ChunkLengthTable chunkLengthTable = null;
            PartsList        partsList        = null;

            while (riffInput.getBytesRemaining() > 0)
            {
                Object obj;
                if ((obj = RiffChunkLengthTable.maybeNew(riffInput)) != null)
                {
                    chunkLengthTable = (ChunkLengthTable)obj;
                }
                else if ((obj = RiffNiffInfo.maybeNew(riffInput)) != null)
                {
                    niffInfo = (NiffInfo)obj;
                }
                else if ((obj = RiffPartsList.maybeNew(riffInput)) != null)
                {
                    partsList = (PartsList)obj;
                }
                else if (RiffStringTable.maybeDecode(riffInput))
                {
                    // Do nothing.  The String Table was stored for later use.
                }
                // debug: check for other optional chunks
                else
                {
                    // Did not recognize the chunk type, so skip
                    riffInput.skipChunk();
                }
            }

            // Make sure required chunks are present.
            if (niffInfo == null)
            {
                throw new RiffFormatException("Can't find NIFF info chunk in Setup section.");
            }
            if (chunkLengthTable == null)
            {
                throw new RiffFormatException("Can't find chunk length table in Setup section.");
            }
            if (partsList == null)
            {
                throw new RiffFormatException("Can't find parts list chunk in Setup section.");
            }

            return(new ScoreSetup(niffInfo, chunkLengthTable, partsList));
        }
예제 #5
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);
              }
        }
예제 #6
0
파일: RiffStaff.cs 프로젝트: svejdo1/niffty
        /** Creates new Staff from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         * This also reads all the enclosed MeasureStartTimeSlice objects
         * which themselves contain the event TimeSlice and MusicSymbol objects.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static Staff newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              Staff staff = new Staff(RiffStaffHeader.newInstance(riffInput));

              if (riffInput.getBytesRemaining() <= 0)
            // the staff is empty
            return staff;

              MeasureStartTimeSlice measureStart =
             RiffMeasureStartTimeSlice.maybeNew(riffInput);
              if (measureStart == null) {
            // For some reason, the first chunk in this staff is not a
            //   measure start time slice.  Create a fake one based
            //   on the previous staff system's end time
            // DEBUG: must implement this!  For now use start time of 0/1
            measureStart = new MeasureStartTimeSlice(new Rational(0, 1), null);
              }

              while (true) {
            if (staff.getMeasureStartCount() > 0 &&
            staff.getMeasureStart
              (staff.getMeasureStartCount() - 1).getStartTime().Equals
            (measureStart.getStartTime()))
              // This new measure 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 measure start
              measureStart =
            staff.getMeasureStart(staff.getMeasureStartCount() - 1);
            else
              staff.addMeasureStart(measureStart);

            // Read event time slices until the next measure start time slice or
            //    end of the staff
            RiffMeasureStartTimeSlice.addTimeSlices(riffInput, measureStart);
            if (riffInput.getBytesRemaining() <= 0)
              // reached the end of the staff
              break;

            // The previous call to readTimeSlices has already
            //   ensured that the next chunk is a measure start time slice.
            measureStart = RiffMeasureStartTimeSlice.newInstance(riffInput);
              }

              return staff;
        }
예제 #7
0
        /** Creates new ScoreData from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static ScoreData newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              ScoreData scoreData = new ScoreData();

              while (riffInput.getBytesRemaining() > 0) {
            // Create the child and call addChild() which will set the child's parent
            //   to this.
            scoreData.addPage(RiffPage.newInstance(riffInput));
              }

              return scoreData;
        }
예제 #8
0
        /** This reads chunks from parentInput's input stream until the next
         * NIFF time slice or no more bytesRemaining in the input,
         * adding the chunks to the timeSlice's music symbol list.  If a music
         * symbol is not recognized, this skips it.
         * This stops at either a measure start or an event time slice.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @param timeSlice  the TimeSlice to which MusicSymbol objects are added.
         * @see MusicSymbol
         */
        public static void addMusicSymbols(Riff parentInput, TimeSlice timeSlice)
        {
            while (parentInput.getBytesRemaining() > 0) {
            if (parentInput.peekFOURCC().Equals(RIFF_ID))
              // encoutered the next time slice, so quit
              // Note that this stops at either a measure start or an event time slice.
              return;

            MusicSymbol musicSymbol = maybeNewAnyMusicSymbol(parentInput);
            if (musicSymbol != null)
              timeSlice.addMusicSymbol(musicSymbol);
            else
              // Did not recognize the music symbol, so skip
              parentInput.skipChunk();
              }
        }
예제 #9
0
        /** Creates new ScoreData from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public ScoreData newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            ScoreData scoreData = new ScoreData();

            while (riffInput.getBytesRemaining() > 0)
            {
                // Create the child and call addChild() which will set the child's parent
                //   to this.
                scoreData.addPage(RiffPage.newInstance(riffInput));
            }

            return(scoreData);
        }
예제 #10
0
파일: RiffPage.cs 프로젝트: svejdo1/niffty
        /** Creates new Page from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static Page newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              Page page = new Page(RiffPageHeader.newInstance(riffInput));

              while (riffInput.getBytesRemaining() > 0) {
            StaffSystem staffSystem;
            if ((staffSystem = RiffStaffSystem.maybeNew(riffInput)) != null)
              page.addSystem(staffSystem);
            // debug: must check for NIFFFontSymbol, etc.
            else
              // Did not recognize the chunk type, so skip
              riffInput.skipChunk();
              }

              return page;
        }
예제 #11
0
        /** Creates new StaffSystem from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static StaffSystem newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              StaffSystem staffSystem = new StaffSystem
             (RiffStaffSystemHeader.newInstance(riffInput));
              // debug: check for NIFFStaffGrouping

              while (riffInput.getBytesRemaining() > 0) {
            Staff staff;
            if ((staff = RiffStaff.maybeNew(riffInput)) != null)
              // Call addChild() which will set the child's parent to this.
              staffSystem.addStaff(staff);
            // debug: must check for NIFFFontSymbol, etc.
            else
              // Did not recognize the chunk type, so skip
              riffInput.skipChunk();
              }

              return staffSystem;
        }
예제 #12
0
        /** This reads chunks from parentInput's input stream until the next
         * NIFF time slice or no more bytesRemaining in the input,
         * adding the chunks to the timeSlice's music symbol list.  If a music
         * symbol is not recognized, this skips it.
         * This stops at either a measure start or an event time slice.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @param timeSlice  the TimeSlice to which MusicSymbol objects are added.
         * @see MusicSymbol
         */
        static public void addMusicSymbols(Riff parentInput, TimeSlice timeSlice)
        {
            while (parentInput.getBytesRemaining() > 0)
            {
                if (parentInput.peekFOURCC().Equals(RIFF_ID))
                {
                    // encoutered the next time slice, so quit
                    // Note that this stops at either a measure start or an event time slice.
                    return;
                }

                MusicSymbol musicSymbol = maybeNewAnyMusicSymbol(parentInput);
                if (musicSymbol != null)
                {
                    timeSlice.addMusicSymbol(musicSymbol);
                }
                else
                {
                    // Did not recognize the music symbol, so skip
                    parentInput.skipChunk();
                }
            }
        }
예제 #13
0
        /** Creates new ScoreSetup from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static ScoreSetup newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              NiffInfo niffInfo = null;
              ChunkLengthTable chunkLengthTable = null;
              PartsList partsList = null;

              while (riffInput.getBytesRemaining() > 0) {
            Object obj;
            if ((obj = RiffChunkLengthTable.maybeNew(riffInput)) != null)
              chunkLengthTable = (ChunkLengthTable)obj;
            else if ((obj = RiffNiffInfo.maybeNew(riffInput)) != null)
              niffInfo = (NiffInfo)obj;
            else if ((obj = RiffPartsList.maybeNew(riffInput)) != null)
              partsList = (PartsList)obj;
            else if (RiffStringTable.maybeDecode(riffInput)) {
              // Do nothing.  The String Table was stored for later use.
            }
              // debug: check for other optional chunks
            else
              // Did not recognize the chunk type, so skip
              riffInput.skipChunk();
              }

              // Make sure required chunks are present.
              if (niffInfo == null)
            throw new RiffFormatException("Can't find NIFF info chunk in Setup section.");
              if (chunkLengthTable == null)
            throw new RiffFormatException("Can't find chunk length table in Setup section.");
              if (partsList == null)
            throw new RiffFormatException("Can't find parts list chunk in Setup section.");

              return new ScoreSetup(niffInfo, chunkLengthTable, partsList);
        }
예제 #14
0
파일: RiffStaff.cs 프로젝트: svejdo1/niffty
        /** Creates new Staff from the parentInput's input stream.
         * The next object in the input stream must be of this type.
         * This also reads all the enclosed MeasureStartTimeSlice objects
         * which themselves contain the event TimeSlice and MusicSymbol objects.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public Staff newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            Staff staff = new Staff(RiffStaffHeader.newInstance(riffInput));

            if (riffInput.getBytesRemaining() <= 0)
            {
                // the staff is empty
                return(staff);
            }

            MeasureStartTimeSlice measureStart =
                RiffMeasureStartTimeSlice.maybeNew(riffInput);

            if (measureStart == null)
            {
                // For some reason, the first chunk in this staff is not a
                //   measure start time slice.  Create a fake one based
                //   on the previous staff system's end time
                // DEBUG: must implement this!  For now use start time of 0/1
                measureStart = new MeasureStartTimeSlice(new Rational(0, 1), null);
            }

            while (true)
            {
                if (staff.getMeasureStartCount() > 0 &&
                    staff.getMeasureStart
                        (staff.getMeasureStartCount() - 1).getStartTime().Equals
                        (measureStart.getStartTime()))
                {
                    // This new measure 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 measure start
                    measureStart =
                        staff.getMeasureStart(staff.getMeasureStartCount() - 1);
                }
                else
                {
                    staff.addMeasureStart(measureStart);
                }

                // Read event time slices until the next measure start time slice or
                //    end of the staff
                RiffMeasureStartTimeSlice.addTimeSlices(riffInput, measureStart);
                if (riffInput.getBytesRemaining() <= 0)
                {
                    // reached the end of the staff
                    break;
                }

                // The previous call to readTimeSlices has already
                //   ensured that the next chunk is a measure start time slice.
                measureStart = RiffMeasureStartTimeSlice.newInstance(riffInput);
            }

            return(staff);
        }
예제 #15
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);
            }
        }
예제 #16
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF String Table, then decode it and store it in the
         * root RIFFForNIFF object.
         * If the next item is not a NIFF String Table, do nothing
         * and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream.
         *        If parentInput.getParent() is not of type RIFFForNIFF, then this
         *        moves the input past the String Table but does not store it.
         * @return true if the String Table was processed, false if this is
         *         not a String Table.
         */
        public static bool maybeDecode(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            return false;

              Riff riffInput = new Riff(parentInput, RIFF_ID);

              if (!(parentInput.getParent() is RiffForNiff)) {
            // There is no place to store the data
            riffInput.skipRemaining();
            return true;
              }
              RiffForNiff riffForNiff = (RiffForNiff)parentInput.getParent();

              // Read the entire string table into a byte array
              byte[] stringTable = new byte[riffInput.getBytesRemaining()];
              for (int i = 0; i < stringTable.Length; ++i)
            stringTable[i] = (byte)riffInput.readBYTE();
              riffForNiff.setStringTable(stringTable);

              // This skips possible pad byte
              riffInput.skipRemaining();

              return true;
        }