Beispiel #1
0
void GetTimeSegmentPositions(TimeSegment timeSegment, double &dStartPos, double &dEndPos, MediaItem* item)
{
	double dOrgCursorPos = GetCursorPositionEx(0);
	bool bRefreshCurPos = false;

	switch(timeSegment)
	{
		case eTIMESEGMENT_TIMESEL:
			//Main_OnCommandEx(ID_GOTO_TIMESEL_END, 0, 0);
			//dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_TIMESEL_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			GetSet_LoopTimeRange2(0, false, false, &dStartPos, &dEndPos, false);
		break;
		case eTIMESEGMENT_SELITEM:
			if(item != NULL)
			{
				dStartPos = GetMediaItemInfo_Value(item, "D_POSITION");
				dEndPos = dStartPos + GetMediaItemInfo_Value(item, "D_LENGTH");
			}
			else
			{
				Main_OnCommandEx(ID_GOTO_SELITEM_END, 0, 0);
				dEndPos = GetCursorPositionEx(0);
				Main_OnCommandEx(ID_GOTO_SELITEM_START, 0, 0);
				dStartPos = GetCursorPositionEx(0);
				bRefreshCurPos = true;
			}
		break;
		case eTIMESEGMENT_LOOP:
			//Main_OnCommandEx(ID_GOTO_LOOP_END, 0, 0);
			//dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_LOOP_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			GetSet_LoopTimeRange2(0, false, true, &dStartPos, &dEndPos, false);
		break;
		case eTIMESEGMENT_PROJECT:
			Main_OnCommandEx(ID_GOTO_PROJECT_END, 0, 0);
			dEndPos = GetCursorPositionEx(0);
			//Main_OnCommandEx(ID_GOTO_PROJECT_START, 0, 0);
			//dStartPos = GetCursorPositionEx(0);
			dStartPos = *(int*)GetConfigVar("projtimeoffs");
			bRefreshCurPos = true;
		break;
		//case eTIMESEGMENT_CURRENTMEASURE:
		//	Main_OnCommandEx(ID_GOTO_CURMEASURE_START, 0, 0);
		//	dStartPos = GetCursorPositionEx(0);
		//	Main_OnCommandEx(ID_GOTO_NEXTMEASURE_START, 0, 0);
		//	dEndPos = GetCursorPositionEx(0);
		//break;
		default:
		break;
	}

	if(bRefreshCurPos)
		SetEditCurPos2(0, dOrgCursorPos, true, false);
}
Beispiel #2
0
EnvelopeProcessor::ErrorCode EnvelopeProcessor::generateSelectedTrackEnvLfo()
{
	TrackEnvelope* envelope = GetSelectedTrackEnvelope(0);
	if(!envelope)
		return eERRORCODE_NOENVELOPE;

	Undo_BeginBlock2(0);

	//! \todo: use insert/goto actions AFTER error returns
	double dStartPos, dEndPos;
	GetTimeSegmentPositions(_parameters.timeSegment, dStartPos, dEndPos);

	if(dStartPos==dEndPos)
		return eERRORCODE_NULLTIMESELECTION;

	double dOrgCursorPos = GetCursorPositionEx(0);
	SetEditCurPos2(0, dStartPos-EPSILON_TIME, false, false);
	Main_OnCommandEx(ID_ENVELOPE_INSERT_POINT, 0, 0);
	SetEditCurPos2(0, dEndPos+EPSILON_TIME, false, false);
	Main_OnCommandEx(ID_ENVELOPE_INSERT_POINT, 0, 0);
	SetEditCurPos2(0, dOrgCursorPos, false, false);

	//Main_OnCommandEx(ID_MOVE_TIMESEL_NUDGE_LEFTEDGE_LEFT, 0, 0);
	//Main_OnCommandEx(ID_MOVE_TIMESEL_NUDGE_RIGHTEDGE_RIGHT, 0, 0);
	//Main_OnCommandEx(ID_GOTO_TIMESEL_START, 0, 0);
	//Main_OnCommandEx(ID_ENVELOPE_INSERT_POINT, 0, 0);
	//Main_OnCommandEx(ID_GOTO_TIMESEL_END, 0, 0);
	//Main_OnCommandEx(ID_ENVELOPE_INSERT_POINT, 0, 0);
	//Main_OnCommandEx(ID_MOVE_TIMESEL_NUDGE_LEFTEDGE_RIGHT, 0, 0);
	//Main_OnCommandEx(ID_MOVE_TIMESEL_NUDGE_RIGHTEDGE_LEFT, 0, 0);
	//Main_OnCommandEx(ID_ENVELOPE_DELETE_ALL_POINTS_TIMESEL, 0, 0);

	ErrorCode res = generateTrackLfo(envelope, dStartPos, dEndPos, _parameters.waveParams, _parameters.precision);
//UpdateTimeline();

	Undo_EndBlock2(NULL, __LOCALIZE("Track envelope LFO","sws_undo"), UNDO_STATE_TRACKCFG);
	return res;
}
Beispiel #3
0
bool GotoMarkerRegion(ReaProject* _proj, int _num, int _flags, bool _select = false)
{
	bool isrgn; double pos, end;
	int x=0, n; 
	while ((x = EnumProjectMarkers3(_proj, x, &isrgn, &pos, &end, NULL, &n, NULL)))
		if (n == _num && ((!isrgn && _flags&SNM_MARKER_MASK) || (isrgn && _flags&SNM_REGION_MASK)))
		{
			PreventUIRefresh(1);

			if (_select && isrgn && (_flags&SNM_REGION_MASK))
				GetSet_LoopTimeRange2(NULL, true, true, &pos, &end, false); // seek is managed below

			int* opt = (int*)GetConfigVar("smoothseek"); // obeys smooth seek
			SetEditCurPos2(_proj, pos, true, opt && *opt); // includes an undo point, if enabled in prefs

			PreventUIRefresh(-1);

			return true;
		}
	return false;
}
Beispiel #4
0
bool FindWnd::FindMarkerRegion(int _dir)
{
	if (!_dir)
		return false;

	bool update = false, found = false;
	if (g_searchStr && *g_searchStr)
	{
		double startPos = GetCursorPositionEx(NULL);
		int id, x = 0;
		bool bR;
		double dPos, dRend, dMinMaxPos = _dir < 0 ? -DBL_MAX : DBL_MAX;
		const char *cName;
		while ((x=EnumProjectMarkers2(NULL, x, &bR, &dPos, &dRend, &cName, &id)))
		{
			if (_dir == 1 && dPos > startPos) {
				if (stristr(cName, g_searchStr)) {
					found = true;
					dMinMaxPos = min(dPos, dMinMaxPos);
				}
			}
			else if (_dir == -1 && dPos < startPos) {
				if (stristr(cName, g_searchStr)) {
					found = true;
					dMinMaxPos = max(dPos, dMinMaxPos);
				}
			}
		}
		UpdateNotFoundMsg(found);	
		if (found) {
			SetEditCurPos2(NULL, dMinMaxPos, true, false);
			update = true;
		}
	}
	if (update)
		Undo_OnStateChangeEx2(NULL, __LOCALIZE("Find: change edit cursor position","sws_undo"), UNDO_STATE_ALL, -1); // in case the pref "undo pt for edit cursor positions" is enabled..
	return update;
}
Beispiel #5
0
void MoveTempo (COMMAND_T* ct)
{
	BR_Envelope tempoMap(GetTempoEnv());
	if (!tempoMap.Count())
		return;
	double cursor = GetCursorPositionEx(NULL);
	double tDiff = 0;
	int targetId = -1;

	// Find tempo marker closest to the edit cursor
	if ((int)ct->user == 3)
	{
		targetId = tempoMap.FindClosest(cursor);
		if (targetId == 0) ++targetId;
		if (!tempoMap.ValidateId(targetId))
			return;

		double cTime; tempoMap.GetPoint(targetId, &cTime, NULL, NULL, NULL);
		tDiff = cursor - cTime;
	}

	// Just get time difference for selected points
	else
	{
		if ((int)ct->user == 2 || (int)ct->user == -2)
			tDiff = 1 / GetHZoomLevel() * (double)ct->user / 2;
		else
			tDiff = (double)ct->user/10000;
	}

	if (tDiff == 0)
		return;

	// Loop through selected points
	int skipped = 0;
	int count = (targetId != -1) ? (1) : (tempoMap.CountSelected());
	for (int i = 0; i < count; ++i)
	{
		if (int id = ((int)ct->user == 3) ? (targetId) : (tempoMap.GetSelected(i))) // skip first point
			skipped += (MoveTempo(tempoMap, id, tDiff)) ? (0) : (1);
	}

	// Commit changes
	PreventUIRefresh(1); // prevent jumpy cursor
	if (tempoMap.Commit())
	{
		if ((int)ct->user == 3)
			SetEditCurPos2(NULL, cursor, false, false); // always keep cursor position when moving to closest tempo marker
		Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ALL, -1);
	}
	PreventUIRefresh(-1);

	// Warn user if some points weren't processed
	static bool s_warnUser = true;
	if (s_warnUser && skipped != 0)
	{
		char buffer[512];
		_snprintfSafe(buffer, sizeof(buffer), __LOCALIZE_VERFMT("%d of the selected points didn't get processed because some points would end up with illegal BPM or position. Would you like to be warned if it happens again?", "sws_mbox"), skipped);
		int userAnswer = ShowMessageBox(buffer, __LOCALIZE("SWS - Warning", "sws_mbox"), 4);
		if (userAnswer == 7)
			s_warnUser = false;
	}
}
Beispiel #6
0
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);
}