moar.
This commit is contained in:
parent
0534c70719
commit
04da67a5e4
30
sync/data.h
Normal file
30
sync/data.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cassert>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
|
#include "track.h"
|
||||||
|
|
||||||
|
namespace sync
|
||||||
|
{
|
||||||
|
class Data
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
size_t getTrackIndex(const std::basic_string<TCHAR> &name);
|
||||||
|
Track &getTrack(const std::basic_string<TCHAR> &name);
|
||||||
|
Track &getTrack(size_t track);
|
||||||
|
size_t getTrackCount() const;
|
||||||
|
|
||||||
|
// private:
|
||||||
|
typedef std::map<const std::basic_string<TCHAR>, size_t> TrackContainer;
|
||||||
|
// typedef std::map<const std::basic_string<TCHAR>, SyncTrack> TrackContainer;
|
||||||
|
TrackContainer tracks;
|
||||||
|
std::vector<Track*> actualTracks;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "data.h"
|
||||||
#include "../network.h"
|
#include "../network.h"
|
||||||
#include "../syncdata.h"
|
|
||||||
|
|
||||||
using namespace sync;
|
using namespace sync;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string &baseName;
|
const std::string &baseName;
|
||||||
SyncData syncData;
|
sync::Data syncData;
|
||||||
Timer &timer;
|
Timer &timer;
|
||||||
|
|
||||||
SOCKET serverSocket;
|
SOCKET serverSocket;
|
||||||
@ -34,7 +34,7 @@ ClientDevice::~ClientDevice()
|
|||||||
|
|
||||||
Track &ClientDevice::getTrack(const std::string &trackName)
|
Track &ClientDevice::getTrack(const std::string &trackName)
|
||||||
{
|
{
|
||||||
SyncData::TrackContainer::iterator iter = syncData.tracks.find(trackName);
|
sync::Data::TrackContainer::iterator iter = syncData.tracks.find(trackName);
|
||||||
if (iter != syncData.tracks.end()) return *syncData.actualTracks[iter->second];
|
if (iter != syncData.tracks.end()) return *syncData.actualTracks[iter->second];
|
||||||
|
|
||||||
unsigned char cmd = GET_TRACK;
|
unsigned char cmd = GET_TRACK;
|
||||||
@ -83,6 +83,9 @@ bool ClientDevice::update(float row)
|
|||||||
recv(serverSocket, (char*)&row, sizeof(int), 0);
|
recv(serverSocket, (char*)&row, sizeof(int), 0);
|
||||||
recv(serverSocket, (char*)&value, sizeof(float), 0);
|
recv(serverSocket, (char*)&value, sizeof(float), 0);
|
||||||
printf("set: %d,%d = %f\n", track, row, value);
|
printf("set: %d,%d = %f\n", track, row, value);
|
||||||
|
|
||||||
|
sync::Track &t = syncData.getTrack(track);
|
||||||
|
t.setKeyFrame(row, Track::KeyFrame(value));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -92,6 +95,9 @@ bool ClientDevice::update(float row)
|
|||||||
recv(serverSocket, (char*)&track, sizeof(int), 0);
|
recv(serverSocket, (char*)&track, sizeof(int), 0);
|
||||||
recv(serverSocket, (char*)&row, sizeof(int), 0);
|
recv(serverSocket, (char*)&row, sizeof(int), 0);
|
||||||
printf("delete: %d,%d = %f\n", track, row);
|
printf("delete: %d,%d = %f\n", track, row);
|
||||||
|
|
||||||
|
sync::Track &t = syncData.getTrack(track);
|
||||||
|
t.deleteKeyFrame(row);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -125,7 +131,7 @@ Device *sync::createDevice(const std::string &baseName, Timer &timer)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *device = new ClientDevice(serverSocket, timer);
|
Device *device = new ClientDevice(baseName, serverSocket, timer);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "data.h"
|
||||||
#include "../network.h"
|
#include "../network.h"
|
||||||
#include "../syncdata.h"
|
|
||||||
|
|
||||||
using namespace sync;
|
using namespace sync;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string &baseName;
|
const std::string &baseName;
|
||||||
SyncData syncData;
|
sync::Data syncData;
|
||||||
Timer &timer;
|
Timer &timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ PlayerDevice::~PlayerDevice() { }
|
|||||||
|
|
||||||
Track &PlayerDevice::getTrack(const std::string &trackName)
|
Track &PlayerDevice::getTrack(const std::string &trackName)
|
||||||
{
|
{
|
||||||
SyncData::TrackContainer::iterator iter = syncData.tracks.find(trackName);
|
sync::Data::TrackContainer::iterator iter = syncData.tracks.find(trackName);
|
||||||
if (iter != syncData.tracks.end()) return *syncData.actualTracks[iter->second];
|
if (iter != syncData.tracks.end()) return *syncData.actualTracks[iter->second];
|
||||||
|
|
||||||
sync::Track *track = new sync::Track();
|
sync::Track *track = new sync::Track();
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include "track.h"
|
#include "track.h"
|
||||||
#include "../syncdata.h"
|
#include "data.h"
|
||||||
using namespace sync;
|
using namespace sync;
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|||||||
55
syncdata.h
55
syncdata.h
@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cassert>
|
|
||||||
#include <tchar.h>
|
|
||||||
|
|
||||||
#include "sync/track.h"
|
|
||||||
|
|
||||||
class SyncData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
size_t getTrackIndex(const std::basic_string<TCHAR> &name)
|
|
||||||
{
|
|
||||||
TrackContainer::iterator iter = tracks.find(name);
|
|
||||||
if (iter != tracks.end()) return int(iter->second);
|
|
||||||
|
|
||||||
size_t index = actualTracks.size();
|
|
||||||
tracks[name] = index;
|
|
||||||
actualTracks.push_back(new sync::Track);
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
sync::Track &getTrack(const std::basic_string<TCHAR> &name)
|
|
||||||
{
|
|
||||||
size_t index = getTrackIndex(name);
|
|
||||||
assert(index >= 0);
|
|
||||||
assert(index < int(actualTracks.size()));
|
|
||||||
assert(NULL != actualTracks[index]);
|
|
||||||
return *actualTracks[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
sync::Track &getTrack(size_t track)
|
|
||||||
{
|
|
||||||
assert(track >= 0);
|
|
||||||
assert(track < tracks.size());
|
|
||||||
|
|
||||||
SyncData::TrackContainer::iterator trackIter = tracks.begin();
|
|
||||||
for (size_t currTrack = 0; currTrack < track; ++currTrack, ++trackIter);
|
|
||||||
return *actualTracks[trackIter->second];
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t getTrackCount() const { return tracks.size(); }
|
|
||||||
|
|
||||||
// private:
|
|
||||||
typedef std::map<const std::basic_string<TCHAR>, size_t> TrackContainer;
|
|
||||||
// typedef std::map<const std::basic_string<TCHAR>, SyncTrack> TrackContainer;
|
|
||||||
TrackContainer tracks;
|
|
||||||
std::vector<sync::Track*> actualTracks;
|
|
||||||
};
|
|
||||||
|
|
||||||
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "syncdata.h"
|
#include "sync/data.h"
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
class SyncEditData : public SyncData
|
class SyncEditData : public sync::Data
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SyncEditData() : SyncData() {}
|
SyncEditData() : sync::Data() {}
|
||||||
|
|
||||||
void sendSetKeyCommand(int track, int row, const sync::Track::KeyFrame &key)
|
void sendSetKeyCommand(int track, int row, const sync::Track::KeyFrame &key)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -180,6 +180,10 @@
|
|||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||||
>
|
>
|
||||||
<File
|
<File
|
||||||
|
RelativePath=".\sync\data.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
RelativePath=".\network.cpp"
|
RelativePath=".\network.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
@ -104,12 +104,12 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
||||||
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
||||||
|
|
||||||
SyncData *syncData = getSyncData();
|
sync::Data *syncData = getSyncData();
|
||||||
if (NULL == syncData) return;
|
if (NULL == syncData) return;
|
||||||
|
|
||||||
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||||
|
|
||||||
SyncData::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
sync::Data::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
||||||
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
||||||
{
|
{
|
||||||
ASSERT(trackIter != syncData->tracks.end());
|
ASSERT(trackIter != syncData->tracks.end());
|
||||||
@ -204,7 +204,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
|
|
||||||
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||||
|
|
||||||
SyncData *syncData = getSyncData();
|
sync::Data *syncData = getSyncData();
|
||||||
if (NULL == syncData) return;
|
if (NULL == syncData) return;
|
||||||
|
|
||||||
int selectLeft = min(selectStartTrack, selectStopTrack);
|
int selectLeft = min(selectStartTrack, selectStopTrack);
|
||||||
@ -212,7 +212,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
int selectTop = min(selectStartRow, selectStopRow);
|
int selectTop = min(selectStartRow, selectStopRow);
|
||||||
int selectBottom = max(selectStartRow, selectStopRow);
|
int selectBottom = max(selectStartRow, selectStopRow);
|
||||||
|
|
||||||
SyncData::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
sync::Data::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
||||||
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
||||||
{
|
{
|
||||||
ASSERT(trackIter != syncData->tracks.end());
|
ASSERT(trackIter != syncData->tracks.end());
|
||||||
|
|||||||
@ -110,7 +110,7 @@ private:
|
|||||||
|
|
||||||
int getTrackCount()
|
int getTrackCount()
|
||||||
{
|
{
|
||||||
SyncData *syncData = getSyncData();
|
sync::Data *syncData = getSyncData();
|
||||||
if (NULL == syncData) return 0;
|
if (NULL == syncData) return 0;
|
||||||
return int(syncData->getTrackCount());
|
return int(syncData->getTrackCount());
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user