editor: pass track-name to client-socket

This makes ClientSocket independent of the track-order in the
SyncDocument, and makes it easier to understand quite a bit
of the logic.
This commit is contained in:
Erik Faye-Lund 2011-03-28 23:11:20 +02:00
parent 55cdc24cef
commit 558dcf01fb
5 changed files with 19 additions and 18 deletions

View File

@ -2,13 +2,14 @@
#include "../sync/track.h"
#include <cassert>
#include <string>
void ClientSocket::sendSetKeyCommand(uint32_t track, const struct track_key &key)
void ClientSocket::sendSetKeyCommand(const std::string &trackName, const struct track_key &key)
{
if (!connected() ||
clientRemap.count(track) == 0)
clientTracks.count(trackName) == 0)
return;
track = htonl(clientRemap[track]);
uint32_t track = htonl(clientTracks[trackName]);
uint32_t row = htonl(key.row);
union {
@ -28,13 +29,13 @@ void ClientSocket::sendSetKeyCommand(uint32_t track, const struct track_key &key
send((char *)&key.type, 1, 0);
}
void ClientSocket::sendDeleteKeyCommand(int track, int row)
void ClientSocket::sendDeleteKeyCommand(const std::string &trackName, int row)
{
if (!connected() ||
clientRemap.count(track) == 0)
clientTracks.count(trackName) == 0)
return;
track = htonl(int(clientRemap[track]));
uint32_t track = htonl(int(clientTracks[trackName]));
row = htonl(row);
unsigned char cmd = DELETE_KEY;

View File

@ -48,14 +48,14 @@ public:
return !!socket_poll(socket);
}
void sendSetKeyCommand(uint32_t track, const struct track_key &key);
void sendDeleteKeyCommand(int track, int row);
void sendSetKeyCommand(const std::string &trackName, const struct track_key &key);
void sendDeleteKeyCommand(const std::string &trackName, int row);
void sendSetRowCommand(int row);
void sendPauseCommand(bool pause);
void sendSaveCommand();
bool clientPaused;
std::map<size_t, size_t> clientRemap;
std::map<const std::string, size_t> clientTracks;
private:
SOCKET socket;

View File

@ -582,12 +582,12 @@ void processCommand(ClientSocket &sock)
int(document.createTrack(trackName));
// setup remap
document.clientSocket.clientRemap[serverIndex] = clientIndex++;
document.clientSocket.clientTracks[trackName] = clientIndex++;
// send key-frames
t = document.tracks[serverIndex];
for (int i = 0; i < (int)t->num_keys; ++i)
document.clientSocket.sendSetKeyCommand(int(serverIndex),
document.clientSocket.sendSetKeyCommand(trackName,
t->keys[i]);
InvalidateRect(trackViewWin, NULL, FALSE);

View File

@ -54,7 +54,7 @@ public:
assert(!is_key_frame(t, key.row));
if (sync_set_key(t, &key))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(track, key); // update clients
data->clientSocket.sendSetKeyCommand(t->name, key); // update clients
}
void undo(SyncDocument *data)
@ -63,7 +63,7 @@ public:
assert(is_key_frame(t, key.row));
if (sync_del_key(t, key.row))
throw std::bad_alloc("sync_del_key");
data->clientSocket.sendDeleteKeyCommand(track, key.row); // update clients
data->clientSocket.sendDeleteKeyCommand(t->name, key.row); // update clients
}
private:
@ -85,7 +85,7 @@ public:
oldKey = t->keys[idx];
if (sync_del_key(t, row))
throw std::bad_alloc("sync_del_key");
data->clientSocket.sendDeleteKeyCommand(track, row); // update clients
data->clientSocket.sendDeleteKeyCommand(t->name, row); // update clients
}
void undo(SyncDocument *data)
@ -94,7 +94,7 @@ public:
assert(!is_key_frame(t, row));
if (sync_set_key(t, &oldKey))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(track, oldKey); // update clients
data->clientSocket.sendSetKeyCommand(t->name, oldKey); // update clients
}
private:
@ -117,7 +117,7 @@ public:
oldKey = t->keys[idx];
if (sync_set_key(t, &key))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(track, key); // update clients
data->clientSocket.sendSetKeyCommand(t->name, key); // update clients
}
void undo(SyncDocument *data)
@ -126,7 +126,7 @@ public:
assert(is_key_frame(t, key.row));
if (sync_set_key(t, &oldKey))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(track, oldKey); // update clients
data->clientSocket.sendSetKeyCommand(t->name, oldKey); // update clients
}
private:

View File

@ -191,7 +191,7 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_LEFT | BF_RIGHT | BF_BOTTOM);
FillRect(hdc, &fillRect, bgBrush);
if (!doc->clientSocket.clientRemap.count(doc->getTrackIndexFromPos(track)))
if (!doc->clientSocket.clientTracks.count(t->name))
SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
else
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));