//--------------------------------------------------------------------------------------- int IdfyScalesCtrol::ReconfigureGroup(int iBt, int iStartC, int iEndC, wxString sRowLabel) { //Reconfigure a group of buttons int iC; // real scale. Correspondence to EScaleTypes int iB; // button index: 0 .. k_num_buttons-1 int iR; // row index: 0 .. k_num_rows-1 iB = iBt; iR = iB / k_num_cols; m_pRowLabel[iR]->set_text( to_std_string(sRowLabel) ); for (iC=iStartC; iC <= iEndC; iC++) { if (m_pConstrains->IsScaleValid((EScaleType)iC)) { m_nRealScale[iB] = iC; m_pAnswerButton[iB]->set_label( m_sButtonLabel[iC] ); m_pAnswerButton[iB]->set_visible(true); //m_pAnswerButton[iB]->enable(true); iB++; if (iB % k_num_cols == 0) { iR++; m_pRowLabel[iR]->set_text(""); } } } if (iB % k_num_cols != 0) iB += (k_num_cols - (iB % k_num_cols)); return iB; }
as3_value operator+(const as3_value& v1, const as3_value& v2) { auto p1 = v1.to_primitive(); auto p2 = v2.to_primitive(); if(p1.type_ == as3_value::STRING || p2.type_ == as3_value::STRING) { return as3_value(p1.to_string() + p2.to_std_string()); } return as3_value(p1.to_number() + p2.to_number()); }
//---------------------------------------------------------------------- // Given a uri string as a starting point, walk the graph created by // the rdf documents. Each time a URI appears as the object of a // triple, attempt to parse it and contine walking. The walking order // is breadth-first-search (it uses a queue) but this may be changed // via a tag class or something later on... //---------------------------------------------------------------------- void operator()(std::string uri) const { std::unordered_set<std::string> closed_list; std::queue<std::string> fringe; fringe.push(uri); while (!fringe.empty()) { // Get the next element and remove it from the fringe. std::string current_uri = fringe.front(); fringe.pop(); if (closed_list.find(current_uri) == closed_list.end()) { // Not seen this uri yet... closed_list.insert(current_uri); // Parse the uri into triples. rdf_web_parser p; std::list<rdf_triple> triples; bool good_rdf = p(current_uri, std::back_inserter(triples)); if (good_rdf) { // Remove the triples that do not match the supplied predicate. auto new_end = std::remove_if(std::begin(triples), std::end(triples), [&pred_](rdf_triple const& t) { return !pred_(t); }); // Apply the visitor function to the triples that made it past the filter. func_(current_uri, std::begin(triples), new_end); // Add those triples that are uris to the fringe. std::for_each( std::begin(triples), new_end, [&fringe, &pred_](rdf_triple t) { // If the triple matches the predicate, add it to the fringe. auto obj = t.object(); if (is_uri(obj)) { auto next_uri = term_cast<rdf_uri>(obj); fringe.push(to_std_string(next_uri.uri())); } }); } } } }
//--------------------------------------------------------------------------------------- void Paths::create_folders() { //create temp folder if it does not exist. Otherwise the program will //fail when the user tries to open an eMusicBook if (!::wxDirExists(m_sTemp)) { //bypass for bug in unicode build (GTK) for wxMkdir //::wxMkDir(m_sTemp.wx_str()); wxFileName oFN(m_sTemp); oFN.Mkdir(0777); if (!::wxDirExists(m_sTemp)) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oFN.GetFullPath().wx_str() ))); } #if (LENMUS_PLATFORM_UNIX == 1) //create folders if they don't exist if (!::wxDirExists(m_sLogs)) { wxFileName oFN(m_sLogs); oFN.Mkdir(0777); if (!::wxDirExists(m_sLogs)) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oFN.GetFullPath().wx_str() ))); } if (!::wxDirExists(m_sConfig)) { wxFileName oFN(m_sConfig); oFN.Mkdir(0777); if (!::wxDirExists(m_sConfig)) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oFN.GetFullPath().wx_str() ))); } #endif }
//--------------------------------------------------------------------------------------- void IdfyTonalityCtrol::on_settings_changed() { // The settings have been changed. Reconfigure answer keyboard for the new settings Colors* pColors = m_appScope.get_colors(); //set buttons int iB = 0; if (m_pConstrains->UseMajorMinorButtons()) { //Only major / minor buttons m_pAnswerButton[iB]->set_label( to_std_string(_("Major")) ); m_pAnswerButton[iB]->set_visible(true); //m_pAnswerButton[iB]->enable(true); set_button_color(iB, pColors->Normal()); iB++; m_pAnswerButton[iB]->set_label( to_std_string(_("Minor")) ); m_pAnswerButton[iB]->set_visible(true); //m_pAnswerButton[iB]->enable(true); set_button_color(iB, pColors->Normal()); iB++; } else { EKeySignature nKeys[] = { k_key_C, k_key_Cs, k_key_c, k_key_cs, k_key_Cf, k_key_D, k_key_Df, k_key_d, k_key_ds, k_key_undefined, k_key_E, k_key_Ef, k_key_e, k_key_ef, k_key_undefined, k_key_F, k_key_Fs, k_key_f, k_key_fs, k_key_undefined, k_key_G, k_key_Gf, k_key_g, k_key_gs, k_key_undefined, k_key_A, k_key_Af, k_key_a, k_key_as, k_key_af, k_key_B, k_key_Bf, k_key_b, k_key_bf, k_key_undefined, }; //use a button for each enabled key signature iB=0; for (unsigned i = 0; i < sizeof(nKeys)/sizeof(EKeySignature); i++, iB++) { EKeySignature nKey = nKeys[i]; if (nKey != k_key_undefined) { m_pAnswerButton[iB]->set_label( to_std_string(get_key_signature_name(nKey)) ); } m_nRealKey[iB] = nKey; m_pAnswerButton[iB]->set_visible(nKey != k_key_undefined); // bool fEnable = m_pConstrains->IsValidKey(nKey); // m_pAnswerButton[iB]->enable(fEnable); // set_button_color(iB, fEnable ? pColors->Normal() : Color(255,255,255)); } } //hide all other buttons while (iB < k_num_buttons) { m_pAnswerButton[iB]->set_visible(false); m_pAnswerButton[iB]->enable(false); iB++; } m_pDoc->set_dirty(); // if (m_pConstrains->is_theory_mode()) // new_problem(); // else // m_pProblemScore = NULL; }
//======================================================================================= // Paths implementation //======================================================================================= Paths::Paths(wxString sBinPath, ApplicationScope& appScope) : m_appScope(appScope) { //Receives the full path to the LenMus executable folder (/bin) and //extracts the root path m_sBin = sBinPath; #if (LENMUS_DEBUG_BUILD == 1 || LENMUS_RELEASE_INSTALL == 0) m_root.AssignDir(LENMUS_SOURCE_ROOT); #if (LENMUS_PLATFORM_WIN32 == 1) //Ignore drive letter in Windows wxFileName drive; drive.GetCwd(); m_root.SetVolume( drive.GetVolume() ); #endif #else m_root.AssignDir(sBinPath); m_root.RemoveLastDir(); #endif m_root.Normalize(); // ------------------------------------------------------------------------------ // Linux Windows Windows (Debug) // Default <prefix> = /usr/local // // 0. The lenmus program // ------------------------------------------------------------------------------ // <prefix> lenmus lm\temp\lenmus // + /bin + \bin + \z_bin // // 1. Shared non-modificable files (INSTALL_ROOT): // ------------------------------------------------------------------------------ // <prefix>/share/lenmus lenmus lm\projects\lenmus\trunk // + /xrc + \xrc // + /res + \res // + /locale + \locale // + /books + \books // + /templates + \templates // + /test-scores + \test-scores // + /samples // // 2. Logs & temporal files (ROOT_G2) // ------------------------------------------------------------------------------ // ~/.config/lenmus/ lenmus lm\temp\lenmus // + /logs + \logs // + /temp + \temp // // 3. Configuration files (user dependent): // ------------------------------------------------------------------------------ // ~/.config/lenmus/5.0/ lenmus\bin lm\temp\lenmus // // 4. User data: scores, samples, etc. // ------------------------------------------------------------------------------ // ~/lenmus lenmus lm\projects\lenmus\trunk // + /scores + \scores (INSTALL_ROOT) // + /5.0/samples + \5.0\samples // wxFileName path; wxString sVersion = m_appScope.get_version_string(); #if (LENMUS_DEBUG_BUILD == 1 || LENMUS_RELEASE_INSTALL == 0) //Debug version or Release version for tests. //Use source tree wxFileName oInstallHome = m_root; wxFileName oLogsHome = m_root; oLogsHome.AssignDir(sBinPath); wxFileName oConfigHome = m_root; oConfigHome.AssignDir(sBinPath); wxFileName oDataHome = m_root; #elif (LENMUS_PLATFORM_WIN32 == 1) //Windows Release version, to install //Use install root. Binaries in /bin folder //Configuration files in /bin, All others in install root wxFileName oInstallHome = m_root; wxFileName oLogsHome = m_root; wxFileName oConfigHome = m_root; oConfigHome.AppendDir("bin"); wxFileName oDataHome = m_root; #elif (LENMUS_PLATFORM_UNIX == 1) //Linux Release version, to install //Use install root. Binaries in /bin folder //Configuration and user dependent files in /home //get user home folder char* homedir = getenv("HOME"); if (homedir == NULL) { struct passwd* pw = getpwuid(getuid()); homedir = pw->pw_dir; } string sHomedir(homedir); wxString sHome = to_wx_string(sHomedir); //1. Shared non-modificable files: LENMUS_INSTALL_ROOT (<prefix>/share/lenmus) wxFileName oInstallHome; oInstallHome.AssignDir( LENMUS_INSTALL_ROOT ); //2. Logs & temporal files: ~/.config/lenmus/ wxFileName oLogsHome; oLogsHome.AssignDir( sHome ); oLogsHome.AppendDir(".config"); if (!::wxDirExists( oLogsHome.GetFullPath() )) { oLogsHome.Mkdir(0777); if (!::wxDirExists( oLogsHome.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oLogsHome.GetFullPath().wx_str() ))); } oLogsHome.AppendDir("lenmus"); if (!::wxDirExists( oLogsHome.GetFullPath() )) { oLogsHome.Mkdir(0777); if (!::wxDirExists( oLogsHome.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oLogsHome.GetFullPath().wx_str() ))); } //3. Configuration files: ~/.config/lenmus/5.x/ wxFileName oConfigHome; oConfigHome.AssignDir( sHome ); oConfigHome.AppendDir(".config"); oConfigHome.AppendDir("lenmus"); oConfigHome.AppendDir(sVersion); if (!::wxDirExists( oConfigHome.GetFullPath() )) { oConfigHome.Mkdir(0777); if (!::wxDirExists( oConfigHome.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oConfigHome.GetFullPath().wx_str() ))); } //4. User data: ~/lenmus/ wxFileName oDataHome; oDataHome.AssignDir( sHome ); oDataHome.AppendDir("lenmus"); if (!::wxDirExists( oDataHome.GetFullPath() )) { oDataHome.Mkdir(0777); if (!::wxDirExists( oDataHome.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , oDataHome.GetFullPath().wx_str() ))); } #endif // Group 1. Software and essentials path = oInstallHome; path.AppendDir("xrc"); m_sXrc = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("res"); path.AppendDir("icons"); m_sImages = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("res"); path.AppendDir("cursors"); m_sCursors = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("res"); path.AppendDir("sounds"); m_sSounds = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("locale"); m_sLocaleRoot = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("templates"); m_sTemplates = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("test-scores"); m_sTestScores = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); path = oInstallHome; path.AppendDir("res"); path.AppendDir("fonts"); m_sFonts = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); // Group 2. Logs and temporal files path = oLogsHome; path.AppendDir("temp"); m_sTemp = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); if (!::wxDirExists( path.GetFullPath() )) { path.Mkdir(0777); if (!::wxDirExists( path.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , path.GetFullPath().wx_str() ))); } path = oLogsHome; path.AppendDir("logs"); m_sLogs = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); if (!::wxDirExists( path.GetFullPath() )) { path.Mkdir(0777); if (!::wxDirExists( path.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , path.GetFullPath().wx_str() ))); } // Group 3. Configuration files, user dependent path = oConfigHome; m_sConfig = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); // Group 4. User scores and samples path = oDataHome; //TODO: Else code fails: no permision to create folders if they do not exist #if 1 m_sScores = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); m_sSamples = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); #else path.AppendDir("scores"); m_sScores = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); if (!::wxDirExists( path.GetFullPath() )) { path.Mkdir(0777); if (!::wxDirExists( path.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , path.GetFullPath().wx_str() ))); } path.AppendDir(sVersion); if (!::wxDirExists( path.GetFullPath() )) { path.Mkdir(0777); if (!::wxDirExists( path.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , path.GetFullPath().wx_str() ))); } path.AppendDir("samples"); m_sSamples = path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); if (!::wxDirExists( path.GetFullPath() )) { path.Mkdir(0777); if (!::wxDirExists( path.GetFullPath() )) LOMSE_LOG_ERROR(to_std_string( wxString::Format("Failed to create '%s'." , path.GetFullPath().wx_str() ))); } #endif }
//--------------------------------------------------------------------------------------- string Paths::dump_paths() { stringstream s; s << "SrcRoot = " << to_std_string(GetSrcRootPath()) << endl; s << "Bin = " << to_std_string(GetBinPath()) << endl; s << "Xrc = " << to_std_string(GetXrcPath()) << endl; s << "Temp = " << to_std_string(GetTemporaryPath()) << endl; s << "Img = " << to_std_string(GetImagePath()) << endl; s << "Cursors = " << to_std_string(GetCursorsPath()) << endl; s << "Sounds = " << to_std_string(GetSoundsPath()) << endl; s << "Locale = " << to_std_string(GetLocaleRootPath()) << endl; s << "Scores = " << to_std_string(GetScoresPath()) << endl; s << "TestScores = " << to_std_string(GetTestScoresPath()) << endl; s << "Samples = " << to_std_string(GetSamplesPath()) << endl; s << "Templates = " << to_std_string(GetTemplatesPath()) << endl; s << "Config = " << to_std_string(GetConfigPath()) << endl; s << "Log = " << to_std_string(GetLogPath()) << endl; s << "Fonts = " << to_std_string(GetFontsPath()) << endl; return s.str(); }
//--------------------------------------------------------------------------------------- void Paths::log_paths() { LOMSE_LOG_INFO(to_std_string(wxString::Format("LENMUS_INSTALL_ROOT = [%s]", LENMUS_INSTALL_ROOT ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("SrcRoot = %s", GetSrcRootPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Bin = %s", GetBinPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Xrc = %s", GetXrcPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Temp = %s", GetTemporaryPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Img = %s", GetImagePath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Cursors = %s", GetCursorsPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Sounds = %s", GetSoundsPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Locale = %s", GetLocaleRootPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Scores = %s", GetScoresPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("TestScores = %s", GetTestScoresPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Samples = %s", GetSamplesPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Templates = %s", GetTemplatesPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Config = %s", GetConfigPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Log = %s", GetLogPath().wx_str() ))); LOMSE_LOG_INFO(to_std_string(wxString::Format("Fonts = %s\n", GetFontsPath().wx_str() ))); //DBG: For debugging code for home folder assignment -------------------------- #if (LENMUS_PLATFORM_UNIX == 1) char* homedir = getenv("HOME"); if (homedir == NULL) { struct passwd* pw = getpwuid(getuid()); homedir = pw->pw_dir; } string sHomedir(homedir); wxString sHome = to_wx_string(sHomedir); LOMSE_LOG_INFO(to_std_string(wxString::Format("homedir = %s", sHome.wx_str() ))); wxFileName oLogsHome; oLogsHome.AssignDir( sHome ); LOMSE_LOG_INFO(to_std_string(wxString::Format("initial oLogsHome = %s", oLogsHome.GetFullPath().wx_str() ))); oLogsHome.AppendDir(".config"); oLogsHome.AppendDir("lenmus"); LOMSE_LOG_INFO(to_std_string(wxString::Format("final oLogsHome = %s", oLogsHome.GetFullPath().wx_str() ))); //END_DBG ----------------------------------------------------------------------- #endif }
//--------------------------------------------------------------------------------------- void IdfyScalesCtrol::initialize_strings() { //button labels. // Major scales m_sButtonLabel[est_MajorNatural] = to_std_string( _("Natural") ); m_sButtonLabel[est_MajorTypeII] = to_std_string( _("Type II") ); m_sButtonLabel[est_MajorTypeIII] = to_std_string( _("Type III") ); m_sButtonLabel[est_MajorTypeIV] = to_std_string( _("Type IV") ); // Minor scales m_sButtonLabel[est_MinorNatural] = to_std_string( _("Natural") ); m_sButtonLabel[est_MinorDorian] = to_std_string( _("Dorian") ); m_sButtonLabel[est_MinorHarmonic] = to_std_string( _("Harmonic") ); m_sButtonLabel[est_MinorMelodic] = to_std_string( _("Melodic") ); // Gregorian modes m_sButtonLabel[est_GreekIonian] = to_std_string( _("Ionian") ); m_sButtonLabel[est_GreekDorian] = to_std_string( _("Dorian") ); m_sButtonLabel[est_GreekPhrygian] = to_std_string( _("Phrygian") ); m_sButtonLabel[est_GreekLydian] = to_std_string( _("Lydian") ); m_sButtonLabel[est_GreekMixolydian] = to_std_string( _("Mixolydian") ); m_sButtonLabel[est_GreekAeolian] = to_std_string( _("Aeolian") ); m_sButtonLabel[est_GreekLocrian] = to_std_string( _("Locrian") ); // Other scales m_sButtonLabel[est_PentatonicMinor] = to_std_string( _("Pentatonic minor") ); m_sButtonLabel[est_PentatonicMajor] = to_std_string( _("Pentatonic major") ); m_sButtonLabel[est_Blues] = to_std_string( _("Blues") ); m_sButtonLabel[est_WholeTones] = to_std_string( _("Whole tones") ); m_sButtonLabel[est_Chromatic] = to_std_string( _("Chromatic") ); }