コード例 #1
0
ファイル: fluid_midi.c プロジェクト: midifi/fluidsynth
/*
 * fluid_midi_file_read_mthd
 */
int
fluid_midi_file_read_mthd(fluid_midi_file *mf)
{
    char mthd[15];
    if (fluid_midi_file_read(mf, mthd, 14) != FLUID_OK) {
        return FLUID_FAILED;
    }
    if ((FLUID_STRNCMP(mthd, "MThd", 4) != 0) || (mthd[7] != 6)
            || (mthd[9] > 2)) {
        FLUID_LOG(FLUID_ERR,
                "Doesn't look like a MIDI file: invalid MThd header");
        return FLUID_FAILED;
    }
    mf->type = mthd[9];
    mf->ntracks = (unsigned) mthd[11];
    mf->ntracks += (unsigned int) (mthd[10]) << 16;
    if ((mthd[12]) < 0) {
        mf->uses_smpte = 1;
        mf->smpte_fps = -mthd[12];
        mf->smpte_res = (unsigned) mthd[13];
        FLUID_LOG(FLUID_ERR, "File uses SMPTE timing -- Not implemented yet");
        return FLUID_FAILED;
    } else {
        mf->uses_smpte = 0;
        mf->division = (mthd[12] << 8) | (mthd[13] & 0xff);
        FLUID_LOG(FLUID_DBG, "Division=%d", mf->division);
    }
    return FLUID_OK;
}
コード例 #2
0
ファイル: fluid_sys.c プロジェクト: tecan/LunaLibs
/**
 * Check if a file is a SoundFont file.
 * @param filename Path to the file to check
 * @return TRUE if it could be a SoundFont, FALSE otherwise
 *
 * @note The current implementation only checks for the "RIFF" and "sfbk" headers in
 * the file. It is useful to distinguish between SoundFont and other (e.g. MIDI) files.
 */
int
fluid_is_soundfont(const char *filename)
{
  FILE* fp = fopen(filename, "rb");
  char riff_id[4], sfbk_id[4];

  if (fp == NULL) {
    return 0;
  }
  if((fread((void*) riff_id, 1, sizeof(riff_id), fp) != sizeof(riff_id)) ||
     (fseek(fp, 4, SEEK_CUR) != 0) || 
     (fread((void*) sfbk_id, 1, sizeof(sfbk_id), fp) != sizeof(sfbk_id)))
  {
      goto error_rec;
  }
  
  fclose(fp);
  return (FLUID_STRNCMP(riff_id, "RIFF", sizeof(riff_id)) == 0) &&
         (FLUID_STRNCMP(sfbk_id, "sfbk", sizeof(sfbk_id)) == 0);
  
error_rec:
    fclose(fp);
    return 0;
}
コード例 #3
0
ファイル: fluid_sys.c プロジェクト: tecan/LunaLibs
/**
 * Check if a file is a MIDI file.
 * @param filename Path to the file to check
 * @return TRUE if it could be a MIDI file, FALSE otherwise
 *
 * The current implementation only checks for the "MThd" header in the file.
 * It is useful only to distinguish between SoundFont and MIDI files.
 */
int
fluid_is_midifile(const char *filename)
{
  FILE* fp = fopen(filename, "rb");
  char id[4];

  if (fp == NULL) {
    return 0;
  }
  if (fread((void*) id, 1, 4, fp) != 4) {
    fclose(fp);
    return 0;
  }
  fclose(fp);

  return FLUID_STRNCMP(id, "MThd", 4) == 0;
}