Esempio n. 1
0
        /** Creates new KeySignature 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 KeySignature newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new KeySignature
            (riffInput.readSIGNEDBYTE(), RiffTags.newInstance(riffInput));
        }
Esempio n. 2
0
        /** Creates new StaffHeader 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 StaffHeader newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              // empty required part
              return new StaffHeader(RiffTags.newInstance(riffInput));
        }
Esempio n. 3
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF stem, return a new Stem.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static Stem maybeNew(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            return null;

              return newInstance(parentInput);
        }
Esempio n. 4
0
        /** Creates new PageHeader 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 PageHeader newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            // empty required part
            return(new PageHeader(RiffTags.newInstance(riffInput)));
        }
Esempio n. 5
0
        /** Creates new KeySignature 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 KeySignature newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new KeySignature
                       (riffInput.readSIGNEDBYTE(), RiffTags.newInstance(riffInput)));
        }
Esempio n. 6
0
        /** 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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /** Begin reading a new RIFF chunk or list which is part of a parent chunk or list.
         * Upon return, the input file is ready to read the content.  The chunk ID can
         * be checked with getChunkID().  If this is a list, you can read
         * the list ID with readFOURCC().
         * This will update the bytesRemaining for this and parent RIFF objects.
         *
         * @param parent     the parent RIFF object
         * @see #getChunkID
         * @see #readFOURCC
         * @exception IOException   if an I/O error occurs
         */
        public Riff(Riff parent)
        {
            _parent = parent;
              _input = _parent._input;

              beginChunk();
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        /** Creates new Stem 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 Stem newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            // empty required part
            return(new Stem(RiffTags.newInstance(riffInput)));
        }
Esempio n. 11
0
        /** Begin reading a new RIFF chunk or list which is part of a parent chunk or list.
         * Upon return, the input file is ready to read the content.  The chunk ID can
         * be checked with getChunkID().  If this is a list, you can read
         * the list ID with readFOURCC().
         * This will update the bytesRemaining for this and parent RIFF objects.
         *
         * @param parent     the parent RIFF object
         * @see #getChunkID
         * @see #readFOURCC
         * @exception IOException   if an I/O error occurs
         */
        public Riff(Riff parent)
        {
            _parent = parent;
            _input  = _parent._input;

            beginChunk();
        }
Esempio n. 12
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF staff, return a new Staff.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static Staff maybeNew(Riff parentInput)
        {
            if (!parentInput.peekListID().Equals(RIFF_ID))
            return null;

              return newInstance(parentInput);
        }
Esempio n. 13
0
        /** Creates new Beam 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 Beam newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Beam
                       (riffInput.readBYTE(), riffInput.readBYTE(),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 14
0
        /** Creates new Accidental 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 Accidental newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Accidental
            (convertShape(riffInput.readBYTE()),
             RiffTags.newInstance(riffInput));
        }
Esempio n. 15
0
        /** Creates new Accidental 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 Accidental newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Accidental
                       (convertShape(riffInput.readBYTE()),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 16
0
        /** Creates new Beam 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 Beam newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Beam
            (riffInput.readBYTE(), riffInput.readBYTE(),
             RiffTags.newInstance(riffInput));
        }
Esempio n. 17
0
        /** Creates new ChunkLengthTable 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 ChunkLengthTable newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            // Debug. Just skip remaining for now.
            riffInput.skipRemaining();

            return(new ChunkLengthTable());
        }
Esempio n. 18
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF system, return a new StaffSystem.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public StaffSystem maybeNew(Riff parentInput)
        {
            if (!parentInput.peekListID().Equals(RIFF_ID))
            {
                return(null);
            }

            return(newInstance(parentInput));
        }
Esempio n. 19
0
        /** Creates new PartsList 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 PartsList newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");
              riffInput.requireFOURCC(RIFF_ID);

              // Debug. Just skip remaining for now.
              riffInput.skipRemaining();
              return new PartsList();
        }
Esempio n. 20
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF rest, return a new Rest.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public Rest maybeNew(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            {
                return(null);
            }

            return(newInstance(parentInput));
        }
Esempio n. 21
0
        /** Creates new ChunkLengthTable 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 ChunkLengthTable newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              // Debug. Just skip remaining for now.
              riffInput.skipRemaining();

              return new ChunkLengthTable();
        }
Esempio n. 22
0
        /** Creates a new Lyric 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 Lyric newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              String text = RiffStringTable.decodeString
            (RiffForNiff.getStringTable(parentInput), riffInput.readLONG());
              return new Lyric
            (text, riffInput.readBYTE(), RiffTags.newInstance(riffInput));
        }
Esempio n. 23
0
        /** Peek into the parentInput's input stream and if the next item
         * is one of the recognized NIFF music symbols which subclass
         * MusicSymbol, then return a new object of that subclass.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public MusicSymbol maybeNewAnyMusicSymbol(Riff parentInput)
        {
            MusicSymbol musicSymbol;

            if ((musicSymbol = RiffAccidental.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffAugmentationDot.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffBarline.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffBeam.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffClef.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffKeySignature.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffLyric.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffNotehead.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffStem.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffRest.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffTie.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else if ((musicSymbol = RiffTimeSignature.maybeNew(parentInput)) != null)
            {
                return(musicSymbol);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 24
0
        /** Creates new Clef 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 Clef newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Clef
             (convertShape(riffInput.readBYTE()),
              riffInput.readSIGNEDBYTE(),
              convertOctaveNumber(riffInput.readBYTE()),
              RiffTags.newInstance(riffInput));
        }
Esempio n. 25
0
        /** Creates new PartsList 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 PartsList newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, "LIST");

            riffInput.requireFOURCC(RIFF_ID);

            // Debug. Just skip remaining for now.
            riffInput.skipRemaining();
            return(new PartsList());
        }
Esempio n. 26
0
        /** Creates new Notehead 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 Notehead newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Notehead
            (convertShape(riffInput.readBYTE()),
             riffInput.readSIGNEDBYTE(),
             new Rational(riffInput.readSHORT(), riffInput.readSHORT()),
             RiffTags.newInstance(riffInput));
        }
Esempio n. 27
0
        /** Creates new Clef 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 Clef newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Clef
                       (convertShape(riffInput.readBYTE()),
                       riffInput.readSIGNEDBYTE(),
                       convertOctaveNumber(riffInput.readBYTE()),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 28
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF time slice with any type other than MEASURE_START (presumably
         * type EVENT), return a new  TimeSlice.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static TimeSlice maybeNew(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            return null;
              // We must also ensure that this is not a MEASURE_START time slice
              if (parentInput.peekFirstChunkBYTE() == MEASURE_START)
            return null;

              return newInstance(parentInput);
        }
Esempio n. 29
0
        /** Creates a new Barline 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 Barline newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Barline
                       (convertType(riffInput.readBYTE()),
                       convertExtendsTo(riffInput.readBYTE()),
                       riffInput.readSHORT(),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 30
0
        /** Creates a new Lyric 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 Lyric newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            String text = RiffStringTable.decodeString
                              (RiffForNiff.getStringTable(parentInput), riffInput.readLONG());

            return(new Lyric
                       (text, riffInput.readBYTE(), RiffTags.newInstance(riffInput)));
        }
Esempio n. 31
0
        /** Creates new Rest 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 Rest newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Rest
                       (convertShape(riffInput.readBYTE()),
                       riffInput.readSIGNEDBYTE(),
                       new Rational(riffInput.readSHORT(), riffInput.readSHORT()),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 32
0
        /** Decrease _bytesRemaining for this and all parent RIFF objects.
         * This does not read anything from _input.
         *
         * @param bytes     the amount to decrease _bytesRemaining
         */
        private void advanceBytesRemaining(int bytes)
        {
            Riff riff = this;

            while (riff != null)
            {
                riff._bytesRemaining -= bytes;
                riff = riff._parent;
            }
        }
Esempio n. 33
0
        /** This is a static method to find the parent of riff which is
         * a RIFFForNIFF and return its getStringTable().
         *
         * @param riff   this, or one of its parents going up the chain
         *      should be an is RIFFForNIFF
         * @return the getStringTable() from the first parent or riff
         *      which is a RIFFForNIFF, or return a zero length byte array
         *      if there is no such parent.
         */
        public static byte[] getStringTable(Riff riff)
        {
            while (riff != null) {
            if (riff is RiffForNiff)
              return ((RiffForNiff)riff).getStringTable();
            riff = riff.getParent();
              }

              return new byte[0];
        }
Esempio n. 34
0
        /** Creates a new Barline 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 Barline newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Barline
            (convertType(riffInput.readBYTE()),
             convertExtendsTo(riffInput.readBYTE()),
             riffInput.readSHORT(),
             RiffTags.newInstance(riffInput));
        }
Esempio n. 35
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));
        }
Esempio n. 36
0
        /** Begin reading a new RIFF chunk or list which is part of a parent chunk or list,
         * requiring the chunkID to be chunkID. To begin a list, use "LIST" for chunkID.
         * Upon return, the input file is ready to read the content.  To check
         * the list ID, call requireFOURCC.
         * This will update the bytesRemaining for this and parent RIFF objects.
         *
         * @param parent     the parent RIFF object
         * @param chunkID   the required chunk ID
         * @see #requireFOURCC
         * @exception IOException   if an I/O error occurs
         * @exception RIFFFormatException   if the chunk ID read is not chunkID
         */
        public Riff(Riff parent, String chunkID)
        {
            _parent = parent;
            _input  = _parent._input;

            beginChunk();
            if (!_chunkID.Equals(chunkID))
            {
                throw new RiffFormatException
                          ("Expected chunk ID " + chunkID + ". Got " + _chunkID + ".");
            }
        }
Esempio n. 37
0
        /** This is a static method to find the parent of riff which is
         * a RIFFForNIFF and return its getStringTable().
         *
         * @param riff   this, or one of its parents going up the chain
         *      should be an is RIFFForNIFF
         * @return the getStringTable() from the first parent or riff
         *      which is a RIFFForNIFF, or return a zero length byte array
         *      if there is no such parent.
         */
        static public byte[] getStringTable(Riff riff)
        {
            while (riff != null)
            {
                if (riff is RiffForNiff)
                {
                    return(((RiffForNiff)riff).getStringTable());
                }
                riff = riff.getParent();
            }

            return(new byte[0]);
        }
Esempio n. 38
0
        /** Peek into the parentInput's input stream and if the next item
         * is a NIFF time slice with type MEASURE_START, return a new
         * MeasureStartTimeSlice.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        static public MeasureStartTimeSlice maybeNew(Riff parentInput)
        {
            if (!parentInput.peekFOURCC().Equals(RIFF_ID))
            {
                return(null);
            }
            // We must also ensure that this is a MEASURE_START time slice
            if (parentInput.peekFirstChunkBYTE() != MEASURE_START)
            {
                return(null);
            }

            return(newInstance(parentInput));
        }
Esempio n. 39
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);
              }
        }
Esempio n. 40
0
        /** 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;
        }
Esempio n. 41
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;
        }
Esempio n. 42
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();
              }
        }
Esempio n. 43
0
        /** Creates new MeasureStartTimeSlice from the parentInput's input stream.
         * The next object in the input stream must be a time slice with type MEASURE_START.
         * After creating the MeasureStartTimeSlice, you can call addTimeSlices()
         * to store the event time slices for this measure start time slice.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @see #addTimeSlices
         */
        static public MeasureStartTimeSlice newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            int type = riffInput.readBYTE();

            if (type != MEASURE_START)
            {
                throw new RiffFormatException
                          ("Expected MEASURE_START for time slice type. Got " + type + ".");
            }

            return(new MeasureStartTimeSlice
                       (new Rational(riffInput.readSHORT(), riffInput.readSHORT()),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 44
0
        /** Start reading a new RIFF stream as a RIFF form, requiring the
         * chunkID to be "RIFX" and the form ID to be formID.
         * Upon return, the input file is ready to read the content.
         *
         * @param input     the RIFF input stream
         * @param formID    the expected form ID
         * @see #requireFOURCC
         * @exception IOException   if an I/O error occurs
         * @exception RIFFFormatException   if the chunk ID is not "RIFX"
         */
        public Riff(Stream input, String formID)
        {
            _input = input;
              _parent = null;

              beginChunk();
              if (!_chunkID.Equals("RIFX")) {
            throw new RiffFormatException
            ("Expected RIFX at start of RIFF stream. Got " + _chunkID + ".");
              }

              String formIDRead = readFOURCC();
              if (!formIDRead.Equals(formID)) {
            throw new RiffFormatException
            ("Expected form ID " + formID + ". Got " + formIDRead + ".");
              }
        }
Esempio n. 45
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);
        }
Esempio n. 46
0
        /** 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;
        }
Esempio n. 47
0
        /** Creates new TimeSlice from the parentInput's input stream.
         * The next object in the input stream must be a time slice with
         * a type any other than MEASURE_START (which means the type should
         * be EVENT).
         * After creating the TimeSlice, you can call addMusicSymbols()
         * to store the music symbols for this time slice.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @see #addMusicSymbols
         */
        static public TimeSlice newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            int type = riffInput.readBYTE();

            if (type == MEASURE_START)
            {
                throw new RiffFormatException
                          ("Did not expect a time slice with type MEASURE_START.");
            }
            else if (type != EVENT)
            {
                throw new RiffFormatException
                          ("Expected EVENT for time slice type. Got " + type + ".");
            }

            return(new TimeSlice
                       (new Rational(riffInput.readSHORT(), riffInput.readSHORT()),
                       RiffTags.newInstance(riffInput)));
        }
Esempio n. 48
0
        /** Creates new NIFFInfo 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 NiffInfo newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            // Read 8 bytes and convert to string
            byte[] buffer = new byte[8];
            buffer[0] = (byte)riffInput.readBYTE();
            buffer[1] = (byte)riffInput.readBYTE();
            buffer[2] = (byte)riffInput.readBYTE();
            buffer[3] = (byte)riffInput.readBYTE();
            buffer[4] = (byte)riffInput.readBYTE();
            buffer[5] = (byte)riffInput.readBYTE();
            buffer[6] = (byte)riffInput.readBYTE();
            buffer[7] = (byte)riffInput.readBYTE();

            return(new NiffInfo
                       (Encoding.UTF8.GetString(buffer, 0, buffer.Length),
                       riffInput.readSIGNEDBYTE(),
                       riffInput.readSIGNEDBYTE(),
                       riffInput.readSHORT(),
                       riffInput.readSHORT()));
        }
Esempio n. 49
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;
        }
Esempio n. 50
0
        /** Creates new NIFFInfo 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 NiffInfo newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff (parentInput, RIFF_ID);

            // Read 8 bytes and convert to string
            byte[] buffer = new byte[8];
            buffer[0] = (byte)riffInput.readBYTE();
            buffer[1] = (byte)riffInput.readBYTE();
            buffer[2] = (byte)riffInput.readBYTE();
            buffer[3] = (byte)riffInput.readBYTE();
            buffer[4] = (byte)riffInput.readBYTE();
            buffer[5] = (byte)riffInput.readBYTE();
            buffer[6] = (byte)riffInput.readBYTE();
            buffer[7] = (byte)riffInput.readBYTE();

            return new NiffInfo
              (Encoding.UTF8.GetString(buffer, 0, buffer.Length),
               riffInput.readSIGNEDBYTE(),
               riffInput.readSIGNEDBYTE(),
               riffInput.readSHORT(),
               riffInput.readSHORT());
        }
Esempio n. 51
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();
                }
            }
        }
Esempio n. 52
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);
        }
Esempio n. 53
0
        /** Begin reading a new RIFF chunk or list which is part of a parent chunk or list,
         * requiring the chunkID to be chunkID. To begin a list, use "LIST" for chunkID.
         * Upon return, the input file is ready to read the content.  To check
         * the list ID, call requireFOURCC.
         * This will update the bytesRemaining for this and parent RIFF objects.
         *
         * @param parent     the parent RIFF object
         * @param chunkID   the required chunk ID
         * @see #requireFOURCC
         * @exception IOException   if an I/O error occurs
         * @exception RIFFFormatException   if the chunk ID read is not chunkID
         */
        public Riff(Riff parent, String chunkID)
        {
            _parent = parent;
              _input = _parent._input;

              beginChunk();
              if (!_chunkID.Equals(chunkID)) {
            throw new RiffFormatException
            ("Expected chunk ID " + chunkID + ". Got " + _chunkID + ".");
              }
        }
Esempio n. 54
0
 /** Skip past the next chunk in the input stream.
  */
 public void skipChunk()
 {
     Riff child = new Riff(this);
       child.skipRemaining();
 }
Esempio n. 55
0
        /** Peek into the parentInput's input stream and if the next item
         * is one of the recognized NIFF music symbols which subclass
         * MusicSymbol, then return a new object of that subclass.  Otherwise,
         * return null and leave the input stream unchanged.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         */
        public static MusicSymbol maybeNewAnyMusicSymbol(Riff parentInput)
        {
            MusicSymbol musicSymbol;

              if ((musicSymbol = RiffAccidental.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffAugmentationDot.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffBarline.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffBeam.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffClef.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffKeySignature.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffLyric.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffNotehead.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffStem.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffRest.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffTie.maybeNew(parentInput)) != null)
            return musicSymbol;
              else if ((musicSymbol = RiffTimeSignature.maybeNew(parentInput)) != null)
            return musicSymbol;
              else
            return null;
        }
Esempio n. 56
0
        /** Creates new MeasureStartTimeSlice from the parentInput's input stream.
         * The next object in the input stream must be a time slice with type MEASURE_START.
         * After creating the MeasureStartTimeSlice, you can call addTimeSlices()
         * to store the event time slices for this measure start time slice.
         *
         * @param parentInput    the parent RIFF object being used to read the input stream
         * @see #addTimeSlices
         */
        public static MeasureStartTimeSlice newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              int type = riffInput.readBYTE();
              if (type != MEASURE_START)
            throw new RiffFormatException
            ("Expected MEASURE_START for time slice type. Got " + type + ".");

              return new MeasureStartTimeSlice
            (new Rational(riffInput.readSHORT(), riffInput.readSHORT()),
             RiffTags.newInstance(riffInput));
        }
Esempio n. 57
0
        /** Creates new Tie 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 Tie newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new Tie(RiffTags.newInstance(riffInput));
        }
Esempio n. 58
0
        /** Creates a new AugmentationDot 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 AugmentationDot newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

              return new AugmentationDot(RiffTags.newInstance(riffInput));
        }
Esempio n. 59
0
        /** Skip past the next chunk in the input stream.
         */
        public void skipChunk()
        {
            Riff child = new Riff(this);

            child.skipRemaining();
        }
Esempio n. 60
0
        /** Creates new Tie 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 Tie newInstance(Riff parentInput)
        {
            Riff riffInput = new Riff(parentInput, RIFF_ID);

            return(new Tie(RiffTags.newInstance(riffInput)));
        }