コード例 #1
0
void PitchmarkParameters::load(const boost::filesystem::wpath& path)
{
  boost::filesystem::wifstream ifs(path);
  wstring json((istreambuf_iterator<wchar_t>(ifs)), istreambuf_iterator<wchar_t>());
  GenericStringStream< UTF16<> > buffer(json.c_str());

  GenericDocument< UTF16<> > doc;
  doc.ParseStream(buffer);
  filename = doc[L"filename"].GetString();
  sub_fade_start = doc[L"sub_fade_start"].IsInt()?doc[L"sub_fade_start"].GetInt():0;
  base_pitch = doc[L"base_pitch"].IsInt() ? doc[L"base_pitch"].GetInt() : 0;
  {
    const GenericValue< UTF16<> >& tmp_val = doc[L"base_vowel_wav"];
    if (tmp_val.IsObject()) {
      if (tmp_val[L"filename"].IsString()) {
        base_vowel_wav_filename = tmp_val[L"filename"].GetString();
      }
      if (tmp_val[L"from"].IsInt()) {
        base_vowel_wav_from = tmp_val[L"from"].GetInt();
      }
      if (tmp_val[L"to"].IsInt()) {
        base_vowel_wav_from = tmp_val[L"to"].GetInt();
      }
    }
  }
  {
    const GenericValue< UTF16<> >& tmp_val = doc[L"prefix_vowel_wav"];
    if (tmp_val.IsObject()) {
      if (tmp_val[L"filename"].IsString()) {
        prefix_vowel_wav_filename = tmp_val[L"filename"].GetString();
      }
      if (tmp_val[L"from"].IsInt()) {
        prefix_vowel_wav_from = tmp_val[L"from"].GetInt();
      }
      if (tmp_val[L"to"].IsInt()) {
        prefix_vowel_wav_from = tmp_val[L"to"].GetInt();
      }
    }
  }
  {
    const GenericValue< UTF16<> >& tmp_val = doc[L"pitchmark_points"];
    if (tmp_val.IsArray()) {
      pitchmark_points.resize(tmp_val.Size(),0);
      for (SizeType i = 0; i < tmp_val.Size(); i++) {
        pitchmark_points[i] = tmp_val[i].IsInt()?tmp_val[i].GetInt():0;
      }
    }
  }
}
コード例 #2
0
ファイル: json.cpp プロジェクト: yutsis/YMSPlugins
HANDLE WINAPI EXP_NAME(OpenFilePlugin)(LPCTSTR name, LPCBYTE data, int dataSize
#ifdef UNICODE
                    , int OpMode
#endif
                    )
{
    /*if(!SETTINGS_GET(sBrowseXMLFiles, 1))
	return INVALID_HANDLE_VALUE;*/

/*    int sz = dataSize;
    while(sz) {
	if(strchr(" \t\r\n", *data)) {
	    data++;
	    sz--;
	    if(*data != '{' && 
	}
	break;
    }*/

    {
        MemoryStream ms((LPCSTR)data, dataSize);
        AutoUTFInputStream<unsigned, MemoryStream> is(ms);
        GenericDocument<DocType> d;
        d.ParseStream(is);
        auto err = d.GetParseError();
        auto ofs= d.GetErrorOffset();
        if(err != kParseErrorNone && ofs < (unsigned)dataSize-4)
            return INVALID_HANDLE_VALUE;
    }
    auto plugin = new JsonPlugin(name, data);
    if(!plugin->IsValidDir())
    {
        delete plugin;
        return INVALID_HANDLE_VALUE;
    }
    return plugin;
}
コード例 #3
0
void ScoreNAK::load()
{
  clearNotes();

  wcout << L"nak: " << getScorePath() << endl;

  boost::filesystem::wifstream ifs(path_score);
  wstring json((istreambuf_iterator<wchar_t>(ifs)), istreambuf_iterator<wchar_t>());
  GenericStringStream< UTF16<> > buffer(json.c_str());

  GenericDocument< UTF16<> > doc;
  doc.ParseStream(buffer);
  if (!doc.HasMember(L"Score")) {
    cerr << "[ScoreNAK::load]" << getScorePath() << " is not nak score." << endl;
    return;
  }
  const GenericValue< UTF16<> >& tmp_score = doc[L"Score"];
  if (!tmp_score.HasMember(L"Notes")) {
    cerr << "[ScoreNAK::load]" << getScorePath() << " does not have Notes." << endl;
    return;
  }
  const GenericValue< UTF16<> >& tmp_notes = tmp_score[L"Notes"];
  if (tmp_notes.IsArray()) {
    for (SizeType i = 0; i < tmp_notes.Size(); i++) {
      if (tmp_notes[i][L"id"].IsInt()) {
        Note tmp_note(this, tmp_notes[i][L"id"].GetInt());
        if (tmp_notes[i].HasMember(L"alias") && tmp_notes[i][L"alias"].IsString()) {
          tmp_note.setPronAlias(tmp_notes[i][L"alias"].GetString());
        }
        if (tmp_notes[i].HasMember(L"start") && tmp_notes[i][L"start"].IsInt()) {
          tmp_note.setStart(tmp_notes[i][L"start"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"end") && tmp_notes[i][L"end"].IsInt()) {
          tmp_note.setEnd(tmp_notes[i][L"end"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"front_margin") && tmp_notes[i][L"front_margin"].IsInt()
          && tmp_notes[i].HasMember(L"back_margin") && tmp_notes[i][L"back_margin"].IsInt()) {
          tmp_note.setMargin(tmp_notes[i][L"front_margin"].GetInt(), tmp_notes[i][L"back_margin"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"front_padding") && tmp_notes[i][L"front_padding"].IsInt()
          && tmp_notes[i].HasMember(L"back_padding") && tmp_notes[i][L"back_padding"].IsInt()) {
          tmp_note.setPadding(tmp_notes[i][L"front_padding"].GetInt(), tmp_notes[i][L"back_padding"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"vel") && tmp_notes[i][L"vel"].IsInt()) {
          tmp_note.setBaseVelocity(tmp_notes[i][L"vel"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"pitch") && tmp_notes[i][L"pitch"].IsInt()) {
          tmp_note.setBasePitch(tmp_notes[i][L"pitch"].GetInt());
        }
        if (tmp_notes[i].HasMember(L"vel_points") && tmp_notes[i][L"vel_points"].IsArray()) {
          const GenericValue< UTF16<> >& tmp_vel_points = tmp_notes[i][L"vel_points"];
          for (SizeType i = 0; i < tmp_vel_points.Size(); i++) {
            if (tmp_vel_points[L"vel_points"].IsArray()) {
              const GenericValue< UTF16<> >& tmp_vel_point = tmp_vel_points[i][L"vel_points"];
              tmp_note.addVelocityPoint(tmp_vel_point[SizeType(0)].IsInt()?tmp_vel_point[SizeType(0)].GetInt():0,
                                        tmp_vel_point[SizeType(1)].IsInt()?tmp_vel_point[SizeType(1)].GetInt():0);
            }
          }
        }
        addNote(tmp_note);
      }
    }
  }

  reloadPitches();
}