adding sync-data
This commit is contained in:
parent
bb3aabf667
commit
983fb703f4
75
syncdata.h
Normal file
75
syncdata.h
Normal file
@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <exception>
|
||||
#include <cmath>
|
||||
|
||||
class SyncTrack
|
||||
{
|
||||
public:
|
||||
struct KeyFrame
|
||||
{
|
||||
KeyFrame() : lerp(false) {}
|
||||
KeyFrame(float value) : value(value), lerp(false) {}
|
||||
float value;
|
||||
bool lerp;
|
||||
};
|
||||
|
||||
float getValue(float time)
|
||||
{
|
||||
if (keyFrames.size() == 0) return 0.0f;
|
||||
|
||||
int currRow = int(floor(time));
|
||||
|
||||
// find bounding keyframes
|
||||
keyFrameContainer::const_iterator upper = keyFrames.upper_bound(currRow);
|
||||
keyFrameContainer::const_iterator lower = upper;
|
||||
lower--;
|
||||
|
||||
// bounds check
|
||||
if (lower == keyFrames.end()) return upper->second.value;
|
||||
if (upper == keyFrames.end()) return lower->second.value;
|
||||
|
||||
// lerp, bitch
|
||||
float d = (time - lower->first) / (upper->first - lower->first);
|
||||
return lower->second.value + (upper->second.value - lower->second.value) * d;
|
||||
};
|
||||
|
||||
bool isKeyFrame(int row)
|
||||
{
|
||||
return keyFrames.find(row) != keyFrames.end();
|
||||
}
|
||||
|
||||
KeyFrame &getKeyFrame(int row)
|
||||
{
|
||||
return keyFrames[row];
|
||||
}
|
||||
|
||||
void setKeyFrame(int row, const KeyFrame &keyFrame)
|
||||
{
|
||||
keyFrames[row] = keyFrame;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::map<int, struct KeyFrame> keyFrameContainer;
|
||||
keyFrameContainer keyFrames;
|
||||
};
|
||||
|
||||
class SyncData
|
||||
{
|
||||
public:
|
||||
SyncTrack &getTrack(std::string name)
|
||||
{
|
||||
TrackContainer::iterator iter = tracks.find(name);
|
||||
if (iter != tracks.end()) return iter->second;
|
||||
return tracks[name] = SyncTrack();
|
||||
}
|
||||
|
||||
size_t getTrackCount() { return tracks.size(); }
|
||||
|
||||
private:
|
||||
typedef std::map<const std::string, SyncTrack> TrackContainer;
|
||||
TrackContainer tracks;
|
||||
};
|
||||
@ -61,6 +61,19 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
MSG Msg;
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
SyncData syncData;
|
||||
SyncTrack &testTrack = syncData.getTrack("test");
|
||||
|
||||
// testTrack.setKeyFrame(0, SyncTrack::KeyFrame(1.0f));
|
||||
testTrack.setKeyFrame(1, SyncTrack::KeyFrame(2.0f));
|
||||
testTrack.setKeyFrame(4, SyncTrack::KeyFrame(3.0f));
|
||||
|
||||
for (int i = 0; i < 5 * 2; ++i)
|
||||
{
|
||||
float time = float(i) / 2;
|
||||
printf("%f %d - %f\n", time, testTrack.isKeyFrame(i), testTrack.getValue(time));
|
||||
}
|
||||
|
||||
ATOM mainClass = registerMainWindowClass(hInstance);
|
||||
ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
|
||||
if(!mainClass || ! trackViewClass)
|
||||
|
||||
@ -200,6 +200,10 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\syncdata.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\trackview.h"
|
||||
>
|
||||
</File>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include "trackview.h"
|
||||
|
||||
const TCHAR *trackViewWindowClassName = _T("TrackView");
|
||||
static const TCHAR *trackViewWindowClassName = _T("TrackView");
|
||||
|
||||
static const int topMarginHeight = 20;
|
||||
static const int leftMarginWidth = 60;
|
||||
@ -55,6 +55,8 @@ void TrackView::onPaint()
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
|
||||
// SelectObject(hdc, GetStockObject(SYSTEM_FONT));
|
||||
paintTracks(hdc, ps.rcPaint);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
@ -199,7 +201,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
||||
float val = (float(line) / 16);
|
||||
|
||||
/* format the text */
|
||||
if (!key) _sntprintf_s(temp, 256, _T(" - - -"));
|
||||
if (!key) _sntprintf_s(temp, 256, _T("---"));
|
||||
else _sntprintf_s(temp, 256, _T("%2.2f"), val);
|
||||
TextOut(hdc,
|
||||
patternDataRect.left, patternDataRect.top,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "syncdata.h"
|
||||
|
||||
class TrackView
|
||||
{
|
||||
public:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user