示例#1
0
文件: Context.cpp 项目: tweed/sws
void SmartSplit(COMMAND_T*)
{
	double t1, t2;
	GetSet_LoopTimeRange(false, false, &t1, &t2, false);
	if (AreThereSelItemsInTimeSel() || (t1 != t2 && !CountSelectedMediaItems(0)))
		Main_OnCommand(40061, 0); // Split at time sel
	else
		Main_OnCommand(40012, 0); // Std split at cursor
}
示例#2
0
文件: Context.cpp 项目: tweed/sws
bool AreThereItemsUnderCursor(bool bSel)
{
	double dCursor = GetCursorPosition();
	for (int i = 0; i < (bSel ? CountSelectedMediaItems(0) : CountMediaItems(0)); i++)
	{
		MediaItem* item = bSel ? GetSelectedMediaItem(0, i) : GetMediaItem(0, i);
		double dItemStart = *(double*)GetSetMediaItemInfo(item, "D_POSITION", NULL);
		double dItemEnd   = *(double*)GetSetMediaItemInfo(item, "D_LENGTH", NULL) + dItemStart;
		if (dItemStart < dCursor && dItemEnd > dCursor)
				return true;
	}
	return false;
}
示例#3
0
文件: Context.cpp 项目: tweed/sws
bool AreThereSelItemsInTimeSel()
{
	double t1, t2;
	GetSet_LoopTimeRange(false, false, &t1, &t2, false);
	if (t1 != t2)
	{
		// see if sel items are in the time selection
		for (int i = 0; i < CountSelectedMediaItems(0); i++)
		{
			MediaItem* item = GetSelectedMediaItem(0, i);
			double dItemPos = *(double*)GetSetMediaItemInfo(item, "D_POSITION", NULL);
			double dItemLen = *(double*)GetSetMediaItemInfo(item, "D_LENGTH", NULL);
			if ((dItemPos >= t1 && dItemPos < t2) || (dItemPos < t1 && dItemLen > t1 - dItemPos))
				return true;
		}
	}
	return false;
}
示例#4
0
SimpleExampleWindow::SimpleExampleWindow(HWND parent, std::string title) : MRPWindow(parent,title)
{
	m_last_project_change_count = GetProjectStateChangeCount(nullptr);
	m_but1 = std::make_shared<WinButton>(this, "Get take name");
	m_but1->GenericNotifyCallback = [this](GenericNotifications)
	{
		if (CountSelectedMediaItems(nullptr) > 0)
		{
			MediaItem* item = GetSelectedMediaItem(nullptr, 0);
			MediaItem_Take* take = GetActiveTake(item);
			if (take != nullptr)
			{
				char buf[2048];
				GetSetMediaItemTakeInfo_String(take, "P_NAME", buf, false);
				m_edit1->setText(buf);
			}
		}
	};
	add_control(m_but1);
	m_but2 = std::make_shared<WinButton>(this, "Set take name");
	m_but2->GenericNotifyCallback = [this](GenericNotifications)
	{
		if (CountSelectedMediaItems(nullptr) > 0)
		{
			MediaItem* item = GetSelectedMediaItem(nullptr, 0);
			MediaItem_Take* take = GetActiveTake(item);
			if (take != nullptr)
			{
				GetSetMediaItemTakeInfo_String(take, "P_NAME", (char*)m_edit1->getText().c_str(), true);
				UpdateArrange();
			}
		}
	};
	add_control(m_but2);
	
	m_but3 = std::make_shared<WinButton>(this, "Refresh item list");
	m_but3->GenericNotifyCallback = [this](GenericNotifications)
	{
		populate_listbox();
	};
	add_control(m_but3);
	
	m_but4 = std::make_shared<WinButton>(this, "Remove selected listbox item foffoffooo");
	m_but4->GenericNotifyCallback = [this](GenericNotifications)
	{
		int selindex = m_listbox1->getSelectedIndex();
		if (selindex >= 0)
		{
			m_listbox1->removeItem(selindex);
			m_itemmap.erase(m_listbox1->userIDfromIndex(selindex));
		}
	};
	add_control(m_but4);
	
	m_edit1 = std::make_shared<WinLineEdit>(this, "No take name yet");
	add_control(m_edit1);
	m_listbox1 = std::make_shared<WinListBox>(this);
	
	m_listbox1->SelectedChangedCallback = [this](int index) mutable
	{
		if (index >= 0)
		{
			std::string temp = m_listbox1->getItemText(index);
			readbg() << "you chose " << temp << " from the listbox\n";
			int user_id = m_listbox1->userIDfromIndex(index);
			MediaItem* itemfromlist = m_itemmap[user_id];
			if (ValidatePtr((void*)itemfromlist, "MediaItem*") == true)
			{
				m_edit1->setText(std::string("You chose item with mem address " +
					std::to_string((uint64_t)itemfromlist) + " from the listbox"));
			}
			else m_edit1->setText(("You chose an item from listbox that's no longer valid!"));
		}
		else readbg() << "you managed to choose no item from the listbox\n";
	};
	add_control(m_listbox1);
	add_control(m_listbox1);
	
	m_checkbox1 = std::make_shared<WinCheckBox>(this,"The check box");
	add_control(m_checkbox1);
	m_checkbox1->GenericNotifyCallback = [this](GenericNotifications reason)
	{
		if (reason == GenericNotifications::Checked)
			readbg() << "check box was checked\n";
		else readbg() << "check box was unchecked\n";
	};
	
	m_label1 = std::make_shared<WinLabel>(this, "Ok, will all this text be shown by default...? I wonder...");
	add_control(m_label1);
	m_label1->setTopLeftPosition(150, 60);

	m_rectcontrol1 = std::make_shared<RectangleTestControl>(this);
	add_control(m_rectcontrol1);

	setSize(900, 650);
}
示例#5
0
文件: BR_Tempo.cpp 项目: wolqws/sws
void DeleteTempoPreserveItems (COMMAND_T* ct)
{
	BR_Envelope tempoMap(GetTempoEnv());
	if (!tempoMap.CountSelected())
		return;

	// Get items' position info and set their timebase to time
	vector<BR_MidiItemTimePos> items;
	double firstMarker;
	tempoMap.GetPoint(tempoMap.GetSelected(0), &firstMarker, NULL, NULL, NULL);

	int itemCount = ((int)ct->user) ? CountSelectedMediaItems(NULL) : CountMediaItems(NULL);
	items.reserve(itemCount);
	for (int i = 0; i < itemCount; ++i)
	{
		MediaItem* item = ((int)ct->user) ? GetSelectedMediaItem(NULL, i) : GetMediaItem(NULL, i);
		double itemEnd = GetMediaItemInfo_Value(item, "D_POSITION") + GetMediaItemInfo_Value(item, "D_LENGTH");
		if (itemEnd >= firstMarker)
		{
			items.push_back(BR_MidiItemTimePos(item));
			SetMediaItemInfo_Value(item, "C_BEATATTACHMODE", 0);
		}
	}

	// Readjust unselected tempo markers
	double offset = 0;
	for (int i = 0; i < tempoMap.CountConseq(); ++i)
	{
		int startId, endId;
		tempoMap.GetConseq (i, &startId, &endId);

		if (endId == tempoMap.Count()-1) continue;         // no points after selection, nothing to adjust
		if (startId == 0 && (++startId > endId)) continue; // skip first point

		// Get musical length of selection
		double musicalLen = 0;
		for (int i = startId - 1; i <= endId; ++i )
		{
			double t0, t1, b0, b1; int s0;
			tempoMap.GetPoint(i,   &t0, &b0, &s0, NULL);
			tempoMap.GetPoint(i+1, &t1, &b1, NULL, NULL);
			if (i == startId-1) t0 -= offset; // readjust position to original (earlier iterations moved it)

			if (s0 == SQUARE)
				musicalLen += (t1-t0) * b0 / 240;
			else
				musicalLen += (t1-t0) * (b0+b1) / 480;
		}

		// Readjust points after selection
		double t0, t1, b0, b1; int s0;
		tempoMap.GetPoint(startId - 1, &t0, &b0, &s0, NULL);
		tempoMap.GetPoint(endId   + 1, &t1, &b1, NULL, NULL);

		if (s0 == SQUARE)
			offset = (t0 + (240*musicalLen) / b0) - t1;
		else
			offset = (t0 + (480*musicalLen) / (b0 + b1)) - t1;

		while (!tempoMap.GetSelection(++endId) && endId < tempoMap.Count())
		{
			double t;
			tempoMap.GetPoint(endId, &t, NULL, NULL, NULL);
			t += offset;
			tempoMap.SetPoint (endId, &t, NULL, NULL, NULL);
		}
	}

	// Delete selected tempo markers
	int idOffset = 0;
	for (int i = 0; i < tempoMap.CountSelected(); ++i)
	{
		int id = tempoMap.GetSelected(i) - idOffset;
		if (id != 0) // skip first point
		{
			tempoMap.DeletePoint(id);
			++idOffset;
		}
	}

	// Commit tempo map and restore position info
	PreventUIRefresh(1);
	if (tempoMap.Commit(false))
	{
		for (size_t i = 0; i < items.size(); ++i)
			items[i].Restore();
		Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ALL, -1);
	}
	PreventUIRefresh(-1);
}