void InsertMarker(COMMAND_T* _ct) { AddProjectMarker2(NULL, false, (int)_ct->user && (GetPlayStateEx(NULL)&1) ? GetPlayPositionEx(NULL) : GetCursorPositionEx(NULL), 0.0, "", -1, 0); UpdateTimeline(); Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(_ct), UNDO_STATE_MISCCFG, -1); }
void MoveGridToEditPlayCursor (COMMAND_T* ct) { // Find cursor immediately (in case of playback we want the most accurate position) double cursor = ((int)ct->user == 1 || (int)ct->user == 3) ? (GetPlayPositionEx(NULL)) : (GetCursorPositionEx(NULL)); // Make sure tempo map already has at least one point created (for some reason it won't work if creating it directly in chunk) InitTempoMap(); BR_Envelope tempoMap(GetTempoEnv()); if (!tempoMap.Count()) return; // Set preferences to prevent play cursor from jumping int seekmodes = 0; if ((int)ct->user == 1 || (int)ct->user == 3) { GetConfig("seekmodes", seekmodes); SetConfig("seekmodes", ClearBit(seekmodes, 5)); } // Find closest grid double grid = 0; if ((int)ct->user == 0 || (int)ct->user == 1) grid = GetClosestGrid(cursor); else if ((int)ct->user == 2 || (int)ct->user == 3) grid = GetClosestMeasureGrid(cursor); else if ((int)ct->user == 4) grid = GetClosestLeftSideGrid(cursor); else grid = GetClosestRightSideGrid(cursor); int targetId = tempoMap.Find(grid, MIN_TEMPO_DIST); // No tempo marker on grid, create it if (!tempoMap.ValidateId(targetId)) { int prevId = tempoMap.FindPrevious(grid); double value = tempoMap.ValueAtPosition(grid); int shape; tempoMap.GetPoint(prevId, NULL, NULL, &shape, NULL); tempoMap.CreatePoint(prevId+1, grid, value, shape, 0, false); targetId = prevId+1; } double tDiff = cursor - grid; // Commit changes and warn user if needed if (tDiff != 0) { if (MoveTempo(tempoMap, targetId, tDiff)) { PreventUIRefresh(1); // prevent jumpy cursor if (tempoMap.Commit()) { // Restore edit cursor only if moving to it if ((int)ct->user != 1 && (int)ct->user != 3) SetEditCurPos2(NULL, cursor, false, false); Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ALL, -1); } PreventUIRefresh(-1); } else { static bool s_warnUser = true; if (s_warnUser) { int userAnswer = ShowMessageBox(__LOCALIZE("Moving grid failed because some tempo markers would end up with illegal BPM or position. Would you like to be warned if it happens again?", "sws_mbox"), __LOCALIZE("SWS - Warning", "sws_mbox"), 4); if (userAnswer == 7) s_warnUser = false; } } } // Restore preferences if ((int)ct->user == 1 || (int)ct->user == 3) SetConfig("seekmodes", seekmodes); }