示例#1
0
void SimpleExampleWindow::populate_listbox()
{
	int old_index = m_listbox1->getSelectedIndex();
	m_listbox1->clearItems();
	m_itemmap.clear();
	int numitems = CountMediaItems(nullptr);
	
	for (int i=0;i<numitems;++i)
	{
		MediaItem* item = GetMediaItem(nullptr,i);
		MediaItem_Take* take = GetActiveTake(item);
		if (item!=nullptr)
		{
			char namebuf[1024];
			if (GetSetMediaItemTakeInfo_String(take,"P_NAME",namebuf,false))
			{
				m_listbox1->addItem(namebuf, i);
				// Note that the item pointers stored into this map
				// may easily become invalid if the items are removed by the user etc...
				// It doesn't matter in this code as we don't dereference the pointers in any way yet.
				// Note how the validation can be done in the button3 handler lambda!
				m_itemmap[i]=item;
			}
			
		}
	}
	//readbg() << "listbox has " << m_listbox1->numItems() << " items\n";
}
示例#2
0
ECode COverlayFrame::SetBitmap(
        /* [in] */ IBitmap* bitmap)
{
    AutoPtr<IMediaItem> mediaItem;
    GetMediaItem((IMediaItem**)&mediaItem);
    AutoPtr<MediaArtistNativeHelper> helper;
    ((MediaItem*)mediaItem.Get())->GetNativeContext((MediaArtistNativeHelper**)&helper);
    helper->SetGeneratePreview(TRUE);

    Invalidate();

    mBitmap = bitmap;
    if (mFilename != NULL) {
        /**
         *  Delete the file
         */
        AutoPtr<IFile> file;
        CFile::New(mFilename, (IFile**)&file);
        Boolean b;
        file->Delete(&b);
        /**
         *  Invalidate the filename
         */
        mFilename = NULL;
    }

    /**
     *  Invalidate the transitions if necessary
     */
    return ((MediaItem*)mediaItem.Get())->InvalidateTransitions(mStartTimeMs, mDurationMs);
}
示例#3
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;
}
示例#4
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);
}