Esempio n. 1
0
void fileNew()
{
	// document.purgeUnusedTracks();
	SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
	for (size_t i = 0; i < document.num_tracks; ++i) {
		sync_track *t = document.tracks[i];
		for (size_t j = 0; j < t->num_keys; ++j)
			multiCmd->addCommand(new SyncDocument::DeleteCommand(i, t->keys[j].row));
	}
	document.exec(multiCmd);

	setWindowFileName(L"Untitled");
	fileName.clear();

	document.clearUndoStack();
	document.clearRedoStack();
}
Esempio n. 2
0
void TrackView::editBiasValue(float amount)
{
	SyncDocument *doc = getDocument();
	if (NULL == doc) return;
	
	int selectLeft  = min(selectStartTrack, selectStopTrack);
	int selectRight = max(selectStartTrack, selectStopTrack);
	int selectTop    = min(selectStartRow, selectStopRow);
	int selectBottom = max(selectStartRow, selectStopRow);
	
	if (0 == getTrackCount()) {
		MessageBeep(~0U);
		return;
	}
	
	SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
	for (int track = selectLeft; track <= selectRight; ++track) {
		assert(track < int(getTrackCount()));
		size_t trackIndex = doc->getTrackIndexFromPos(track);
		const sync_track *t = doc->tracks[trackIndex];

		for (int row = selectTop; row <= selectBottom; ++row) {
			int idx = sync_find_key(t, row);
			if (idx >= 0) {
				struct track_key k = t->keys[idx]; // copy old key
				k.value += amount; // modify value

				// add sub-command
				SyncDocument::Command *cmd = doc->getSetKeyFrameCommand(int(trackIndex), k);
				multiCmd->addCommand(cmd);
			}
		}
	}
	
	if (0 == multiCmd->getSize()) {
		MessageBeep(~0U);
		delete multiCmd;
	}
	else
	{
		doc->exec(multiCmd);
		
		SendMessage(GetParent(getWin()), WM_CURRVALDIRTY, 0, 0);
		invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
	}
}
Esempio n. 3
0
void TrackView::editDelete()
{
	SyncDocument *doc = getDocument();
	if (NULL == doc) return;
	
	int selectLeft  = min(selectStartTrack, selectStopTrack);
	int selectRight = max(selectStartTrack, selectStopTrack);
	int selectTop    = min(selectStartRow, selectStopRow);
	int selectBottom = max(selectStartRow, selectStopRow);
	
	if (0 == getTrackCount()) return;
	assert(selectRight < int(getTrackCount()));
	
	SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
	for (int track = selectLeft; track <= selectRight; ++track) {
		size_t trackIndex = doc->getTrackIndexFromPos(track);
		const sync_track *t = doc->tracks[trackIndex];

		for (int row = selectTop; row <= selectBottom; ++row) {
			if (is_key_frame(t, row)) {
				SyncDocument::Command *cmd = new SyncDocument::DeleteCommand(int(trackIndex), row);
				multiCmd->addCommand(cmd);
			}
		}
	}
	
	if (0 == multiCmd->getSize()) {
		MessageBeep(~0U);
		delete multiCmd;
	}
	else
	{
		doc->exec(multiCmd);
		
		SendMessage(GetParent(getWin()), WM_CURRVALDIRTY, 0, 0);
		InvalidateRect(getWin(), NULL, FALSE);
	}
}
Esempio n. 4
0
void TrackView::editPaste()
{
	SyncDocument *doc = getDocument();
	if (NULL == doc) return;
	
	if (0 == getTrackCount()) {
		MessageBeep(~0U);
		return;
	}
	
	if (FAILED(OpenClipboard(getWin())))
	{
		MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
		return;
	}
	
	if (IsClipboardFormatAvailable(clipboardFormat))
	{
		HGLOBAL hmem = GetClipboardData(clipboardFormat);
		char *clipbuf = (char *)GlobalLock(hmem);
		
		// copy data
		int buffer_width, buffer_height, buffer_size;
		memcpy(&buffer_width,  clipbuf + 0,               sizeof(int));
		memcpy(&buffer_height, clipbuf + sizeof(int),     sizeof(int));
		memcpy(&buffer_size,   clipbuf + 2 * sizeof(int), sizeof(size_t));
		
		SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
		for (int i = 0; i < buffer_width; ++i) {
			size_t trackPos = editTrack + i;
			if (trackPos >= getTrackCount()) continue;

			size_t trackIndex = doc->getTrackIndexFromPos(trackPos);
			const sync_track *t = doc->tracks[trackIndex];
			for (int j = 0; j < buffer_height; ++j) {
				int row = editRow + j;
				if (is_key_frame(t, row))
					multiCmd->addCommand(new SyncDocument::DeleteCommand(int(trackIndex), row));
			}
		}
		
		char *src = clipbuf + 2 * sizeof(int) + sizeof(size_t);
		for (int i = 0; i < buffer_size; ++i)
		{
			struct CopyEntry ce;
			memcpy(&ce, src, sizeof(CopyEntry));
			src += sizeof(CopyEntry);
			
			assert(ce.track >= 0);
			assert(ce.track < buffer_width);
			assert(ce.keyFrame.row >= 0);
			assert(ce.keyFrame.row < buffer_height);

			size_t trackPos = editTrack + ce.track;
			if (trackPos < getTrackCount())
			{
				size_t trackIndex = doc->getTrackIndexFromPos(trackPos);
				track_key key = ce.keyFrame;
				key.row += editRow;

				// since we deleted all keyframes in the edit-box already, we can just insert this one. 
				SyncDocument::Command *cmd = new SyncDocument::InsertCommand(int(trackIndex), key);
				multiCmd->addCommand(cmd);
			}
		}
		doc->exec(multiCmd);
		
		GlobalUnlock(hmem);
		clipbuf = NULL;
	}
	else
		MessageBeep(~0U);
	
	CloseClipboard();
}