/**
 * Description: This is a SoundFont2 parser.
 *
 * @package     midi-Synth
 * @category    module js
 * @author      Mrtenz <https://github.com/Mrtenz/soundfont2>
 * @copyright   soundfont2
 * @license     GPL-2.0-or-later
 */

/**
 * Get all instrument headers from a `inst` sub-chunk.
 *
 * @param {SF2Chunk} chunk - The input chunk
 */
const getInstrumentHeaders = chunk => {
  if (chunk.id !== "inst") {
    throw new ParseError("Unexpected chunk ID", `'inst'`, `'${chunk.id}'`)
  }

  if (chunk.length % SF_INSTRUMENT_HEADER_SIZE) {
    throw new ParseError(`Invalid size for the 'inst' sub-chunk`)
  }

  return chunk.iterate(iterator => {
    return {
      name: iterator.getString(),
      bagIndex: iterator.getInt16()
    }
  })
}
