Merge pull request #108 from alkama/master

Moving to the head of the base rocket project
This commit is contained in:
Daniel Collin 2015-12-13 11:22:17 +01:00
commit f5c7d67511
74 changed files with 6014 additions and 5493 deletions

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
*.o
*.a
*.lib
*.ncb
*.pdb
*.suo
*.idb
*.user
*.sdf
*.opensdf
moc_*.cpp
qrc_*.cpp
ui_*.h
.*.swp
.DS_Store
*~
/editor/Makefile*
/editor/editor.vcproj
/editor/editor.sln
/editor/debug/
/editor/release/
/editor/editor/
/editor/editor.app/
/example_bass/example_bass
/example_bass/Debug Client/
/example_bass/Debug/
/example_bass/Release Client/
/example_bass/Release/
/example_bass/x64/
/example_bass/include/
/example_bass/lib/
/lib/Debug Client/
/lib/Debug/
/lib/Release Client/
/lib/Release/
/lib/x64/
/packages/
build-*

10
.travis.yml Normal file
View File

@ -0,0 +1,10 @@
language: c
os:
- linux
- osx
before_script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install qt; fi
script: make

View File

@ -1,4 +1,4 @@
Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
Copyright (C) 2007 Contributors
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

View File

@ -1,6 +1,10 @@
# default target
all:
.PHONY: all clean editor
QMAKE ?= qmake
# default build flags
CFLAGS = -g -O2 -Wall
@ -13,31 +17,57 @@ ifdef COMSPEC
SDL_LIBS = -lSDL
LDLIBS += -lws2_32
else
OPENGL_LIBS = -lGL -lGLU
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
CPPFLAGS += -DUSE_GETADDRINFO
OPENGL_LIBS = -lGL -lGLU
else ifeq ($(UNAME_S), Darwin)
CPPFLAGS += -DUSE_GETADDRINFO
OPENGL_LIBS = -framework OpenGL
else
OPENGL_LIBS = -lGL -lGLU
endif
SDL_CFLAGS = $(shell sdl-config --cflags)
SDL_LIBS = $(shell sdl-config --libs)
LDLIBS += -lm
endif
SYNC_OBJS = \
sync/data.o \
sync/device.o \
sync/track.o
LIB_OBJS = \
lib/device.o \
lib/track.o
all: lib/librocket.a
all: lib/librocket.a lib/librocket-player.a editor
bin/example_bass$X: CPPFLAGS += -Iexample_bass/include
bin/example_bass$X: CXXFLAGS += $(SDL_CFLAGS)
bin/example_bass$X: LDLIBS += -Lexample_bass/lib -lbass
bin/example_bass$X: LDLIBS += $(OPENGL_LIBS) $(SDL_LIBS)
example_bass/%$X: CPPFLAGS += -Iexample_bass/include
example_bass/%$X: CXXFLAGS += $(SDL_CFLAGS)
example_bass/%$X: LDLIBS += -Lexample_bass/lib -lbass
example_bass/%$X: LDLIBS += $(OPENGL_LIBS) $(SDL_LIBS)
clean:
$(RM) -rf $(SYNC_OBJS) lib bin
$(RM) $(LIB_OBJS) lib/librocket.a lib/librocket-player.a
$(RM) example_bass/example_bass$X example_bass/example_bass-player$X
if test -e editor/Makefile; then $(MAKE) -C editor clean; fi;
$(RM) editor/editor editor/Makefile
lib/librocket.a: $(SYNC_OBJS)
@mkdir -p lib
lib/librocket.a: $(LIB_OBJS)
$(AR) $(ARFLAGS) $@ $^
bin/example_bass$X: example_bass/example_bass.cpp lib/librocket.a
@mkdir -p bin
%.player.o : %.c
$(COMPILE.c) -DSYNC_PLAYER $(OUTPUT_OPTION) $<
lib/librocket-player.a: $(LIB_OBJS:.o=.player.o)
$(AR) $(ARFLAGS) $@ $^
example_bass/example_bass$X: example_bass/example_bass.cpp lib/librocket.a
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@
example_bass/example_bass-player$X: example_bass/example_bass.cpp lib/librocket-player.a
$(LINK.cpp) -DSYNC_PLAYER $^ $(LOADLIBES) $(LDLIBS) -o $@
editor/Makefile: editor/editor.pro
cd editor && $(QMAKE) editor.pro -o Makefile
editor: editor/Makefile
$(MAKE) -C editor

91
README
View File

@ -1,91 +0,0 @@
GNU Rocket
==========
GNU Rocket is an intuitive new way of... bah, whatever. It's a sync-tracker,
a tool for synchronizing music and visuals in demoscene productions. It
consists of a GUI editor that runs on Microsoft Windows, and an ANSI C
library that can either communicate with the editor over a network socket,
or play back an exported data-set.
Compile Editor
--------------
GNU Rocket compiles using Microsoft Visual Studio 2008. Open editor.sln and
select "Build" -> "Build Solution" from the menu to build the editor.
Compile Example
---------------
GNU Rocket contains an example client called example_bass. This is a simple
OpenGL, SDL 1.2 and BASS audio library application, that demonstrates how to
use the GNU Rocket API.
Before compiling the example, you need to make sure you have recent
SDL and BASS libraries and includes. These can be downloaded from the
following web-sites:
http://www.libsdl.org/
http://www.un4seen.com/
The header files and libraries can be installed local to the project by
copying all .lib-files to the example_bass/lib/, all .h files to
example_bass/inclide/, and all .dll files to the example_bass/.
Once the prerequisites are installed, the example can be compiled much like
the editor; by opening examples.sln and selecting "Build" -> "Build Solution"
from the menu.
Using the editor
----------------
The GNU Rocket editor is laid out like a music-tracker; tracks (or columns)
and rows. Each track represents a separate "variable" in the demo, over the
entire time-domain of the demo. Each row represents a specific point in time,
and consists of a set of key-frames. The key-frames are interpolated over time
according to their interpolation modes.
Interpolation modes
-------------------
Each key-frame has an interpolation mode associated with it, and that
interpolation mode is valid until the next key-frame is reached. The different
interpolation modes are the following:
* Step : This is the simplest mode, and always returns the key's value.
* Linear : This does a linear interpolation between the current and the next
key's values.
* Smooth : This interpolates in a smooth fashion, the exact function is what
is usually called "smoothstep". Do not confuse this mode with
splines; this only interpolates smoothly between two different
values, it does not try to calculate tangents or any such things.
* Ramp : This is similar to "Linear", but additionally applies an
exponentiation of the interpolation factor.
Keyboard shortcuts
-------------------
Some of the GNU Rocket editor's features are available through the menu and
some keyboard shortcut. Here's a list of the supported keyboard shortcuts:
Up/Down/Left/Right Move cursor
PgUp/PgDn Move cursor 16 rows up/down
Home/End Move cursor to begining/end
Ctrl+Left/Right Move track
Enter Enter key-frame value
Del Delete key-frame
i Enumerate interpolation mode
k Toggle bookmark
Alt+PgUp/PgDn Go to prev/next bookmark
Space Pause/Resume demo
Shift+Up/Down/Left/Right Select
Ctrl+C Copy
Ctrl+V Paste
Ctrl+Z Undo
Shift+Ctrl+Z Redo
Ctrl+B Bias keyframes
Shift+Ctrl+Up/Down Quick-bias by +/- 0.1
Ctrl+Up/Down Quick-bias by +/- 1
Ctrl+PgUp/PgDn Quick-bias by +/- 10
Shift+Ctrl+PgUp/PgDn Quick-bias by +/- 100
Bugs and feed-back
------------------
Please report bugs or other feed-back to the GNU Rocket mailing list:
rocket-users@lists.sourceforge.net
Patches or technical questions can be sent to the developer-list:
rocket-developers@lists.sourceforge.net

92
README.md Normal file
View File

@ -0,0 +1,92 @@
GNU Rocket
==========
[![Build status](https://ci.appveyor.com/api/projects/status/dfq8qaedc6mtsefg/branch/master?svg=true)](https://ci.appveyor.com/project/kusma/rocket/branch/master)
[![Build Status](https://travis-ci.org/kusma/rocket.svg?branch=master)](https://travis-ci.org/kusma/rocket)
GNU Rocket is an intuitive new way of... bah, whatever. It's a sync-tracker,
a tool for synchronizing music and visuals in demoscene productions. It
consists of a GUI editor (using Qt), and an ANSI C library that can either
communicate with the editor over a network socket, or play back an exported
data-set.
Compile Editor
--------------
The GNU Rocket editor uses qmake as a build-system abstraction, which can
be used to output Makefiles, Visual Studio project files or can be built
directly from QtCreator. See the qmake documentation for details.
Compile Example
---------------
GNU Rocket contains an example client called example\_bass. This is a simple
OpenGL, SDL 1.2 and BASS audio library application, that demonstrates how to
use the GNU Rocket API.
Before compiling the example, you need to make sure you have recent [SDL](http://www.libsdl.org/)
and [BASS](http://www.un4seen.com/) libraries and includes.
The header files and libraries can be installed local to the project by
copying all .lib-files to the example\_bass/lib/, all .h files to
example\_bass/include/, and all .dll files to the example\_bass/.
Once the prerequisites are installed, the example can be compiled either by
opening examples.sln and selecting "Build" -> "Build Solution" from Visual
Studio 2008, or by doing "make example_bass/example_bass" on Unix-base
systems.
Using the editor
----------------
The GNU Rocket editor is laid out like a music-tracker; tracks (or columns)
and rows. Each track represents a separate "variable" in the demo, over the
entire time-domain of the demo. Each row represents a specific point in time,
and consists of a set of key frames. The key frames are interpolated over time
according to their interpolation modes.
Interpolation modes
-------------------
Each key frame has an interpolation mode associated with it, and that
interpolation mode is valid until the next key frame is reached. The different
interpolation modes are the following:
* Step : This is the simplest mode, and always returns the key's value.
* Linear : This does a linear interpolation between the current and the next
key's values.
* Smooth : This interpolates in a smooth fashion, the exact function is what
is usually called "smoothstep". Do not confuse this mode with
splines; this only interpolates smoothly between two different
values, it does not try to calculate tangents or any such things.
* Ramp : This is similar to "Linear", but additionally applies an
exponentiation of the interpolation factor.
Keyboard shortcuts
-------------------
Some of the GNU Rocket editor's features are available through the menu and
some keyboard shortcut. Here's a list of the supported keyboard shortcuts:
| Shortcut | Action |
|:-------------------------|:-----------------------------|
| Up/Down/Left/Right | Move cursor |
| PgUp/PgDn | Move cursor 16 rows up/down |
| Home/End | Move cursor to begining/end |
| Ctrl+Left/Right | Move track |
| Enter | Enter key frame value |
| Del | Delete key frame |
| i | Enumerate interpolation mode |
| k | Toggle bookmark |
| Alt+PgUp/PgDn | Go to prev/next bookmark |
| Space | Pause/Resume demo |
| Shift+Up/Down/Left/Right | Select |
| Ctrl+C | Copy |
| Ctrl+V | Paste |
| Ctrl+Z | Undo |
| Shift+Ctrl+Z | Redo |
| Ctrl+B | Bias key frames |
| Shift+Ctrl+Up/Down | Quick-bias by +/- 0.1 |
| Ctrl+Up/Down | Quick-bias by +/- 1 |
| Ctrl+PgUp/PgDn | Quick-bias by +/- 10 |
| Shift+Ctrl+PgUp/PgDn | Quick-bias by +/- 100 |
Bugs and feedback
------------------
Please report bugs or other feedback to the GNU Rocket mailing list:
gnu-rocket@googlegroups.com

48
appveyor.yml Normal file
View File

@ -0,0 +1,48 @@
version: '{build}'
environment:
matrix:
- platform: x64
cc: VS2013
QTDIR: C:\Qt\5.5\msvc2013_64
- platform: Win32
cc: VS2013
QTDIR: C:\Qt\5.5\msvc2013
configuration:
- Release
cache:
- packages -> **\packages.config
install:
- nuget restore examples.vs2013.sln
# download and install bass
- curl -fsS -o bass24.zip http://www.un4seen.com/files/bass24.zip
- 7z x -obass24 bass24.zip > NUL
- mkdir example_bass\lib
- mkdir example_bass\lib64
- mkdir example_bass\include
- copy bass24\c\bass.lib example_bass\lib
- copy bass24\c\x64\bass.lib example_bass\lib64
- copy bass24\c\bass.h example_bass\include
before_build:
- set PATH=%QTDIR%\bin;%PATH%
build_script:
- msbuild examples.vs2013.sln
- msbuild examples.vs2013.sln /property:Configuration="Release Client"
- cd editor
- qmake -tp vc editor.pro
- msbuild
after_build:
- mkdir staging
- cd staging
- copy ..\release\editor.exe .
- windeployqt --release editor.exe
artifacts:
- path: editor\staging
name: editor

View File

@ -4,21 +4,22 @@
#include "DotRocket.h"
#include "../../../sync/sync.h"
#include "../../../sync/track.h"
#include "../../../lib/sync.h"
#include "../../../lib/track.h"
using System::Runtime::InteropServices::Marshal;
using DotRocket::Track;
using DotRocket::PlayerDevice;
private ref class PlayerTrack: public Track {
private ref class PlayerTrack: public Track
{
const sync_track *track;
public:
PlayerTrack(const sync_track *track): track(track) {}
virtual float GetValue(double time) override
virtual double GetValue(double time) override
{
return sync_get_val(track, time);
};
}
};
PlayerDevice::PlayerDevice(System::String ^name)

View File

@ -3,7 +3,6 @@
#pragma once
struct sync_device;
struct sync_track;
using namespace System;
using namespace System::Collections::Generic;
@ -13,7 +12,7 @@ namespace DotRocket
public ref class Track abstract
{
public:
virtual float GetValue(double time) = 0;
virtual double GetValue(double time) = 0;
};
public delegate void PauseEventHandler(bool flag);

View File

@ -59,7 +59,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\Release\sync_player.lib"
AdditionalDependencies="..\..\..\lib\librocket-playerd.lib"
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
@ -129,7 +129,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\..\..\Release\sync_player.lib"
AdditionalDependencies="..\..\..\lib\librocket-player.lib"
TargetMachine="1"
/>
<Tool

View File

@ -2,48 +2,57 @@
#include "stdafx.h"
#include "../../../sync/sync.h"
#include "../../../sync/track.h"
#include "../../../lib/sync.h"
#include "../../../lib/track.h"
using System::Runtime::InteropServices::Marshal;
#include "DotRocketClient.h"
#include <vcclr.h>
using DotRocket::Track;
using DotRocket::Device;
using DotRocket::ClientDevice;
private ref class ClientTrack: public Track {
private ref class ClientTrack: public Track
{
const sync_track *track;
public:
ClientTrack(const sync_track *track) : track(track) {}
virtual float GetValue(double time) override
virtual double GetValue(double time) override
{
return sync_get_val(track, time);
}
};
namespace
{
class DeviceReference
{
public:
DeviceReference(Device ^dev) : dev(dev) {}
Device ^GetDevice() { return dev; }
private:
gcroot<Device^> dev;
};
};
ref class Callbacks {
public:
static Device ^DeviceCurrenltyBeingProcessed = nullptr;
};
void cb_pause(void *arg, int row)
{
Callbacks::DeviceCurrenltyBeingProcessed->Pause(row);
}
void cb_set_row(void *arg, int row)
static void cb_pause(void *arg, int flag)
{
Callbacks::DeviceCurrenltyBeingProcessed->SetRow(row);
((DeviceReference *)arg)->GetDevice()->Pause(!!flag);
}
int cb_is_playing(void *arg)
static void cb_set_row(void *arg, int row)
{
return !!Callbacks::DeviceCurrenltyBeingProcessed->IsPlaying();
((DeviceReference *)arg)->GetDevice()->SetRow(row);
}
sync_cb callbacks[] = {
static int cb_is_playing(void *arg)
{
return ((DeviceReference *)arg)->GetDevice()->IsPlaying();
}
static sync_cb callbacks[] = {
cb_pause,
cb_set_row,
cb_is_playing
@ -76,13 +85,13 @@ ClientDevice::!ClientDevice()
bool ClientDevice::Connect(System::String^ host, unsigned short port)
{
char *chost = (char *)(void *)Marshal::StringToHGlobalAnsi(host);
int result = sync_connect((sync_device *)device, chost, port);
int result = sync_connect(device, chost, port);
Marshal::FreeHGlobal((System::IntPtr)chost);
return !result;
}
bool ClientDevice::Update(int row)
{
Callbacks::DeviceCurrenltyBeingProcessed = this;
return !sync_update(device, row, callbacks, device);
DeviceReference devref(this);
return !sync_update(device, row, callbacks, &devref);
}

View File

@ -3,13 +3,14 @@
#pragma once
struct sync_device;
struct sync_track;
using namespace System;
using namespace System::Collections::Generic;
namespace DotRocket {
public ref class ClientDevice: public Device {
namespace DotRocket
{
public ref class ClientDevice: public Device
{
protected:
sync_device *device;
Dictionary<System::String ^, Track ^> ^tracks;

View File

@ -59,7 +59,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\..\..\Release Client\sync_player.lib&quot;"
AdditionalDependencies="&quot;..\..\..\lib\librocketd.lib&quot;"
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
@ -129,7 +129,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;..\..\..\Release Client\sync_player.lib&quot;"
AdditionalDependencies="&quot;..\..\..\lib\librocket.lib&quot;"
TargetMachine="1"
/>
<Tool

View File

@ -1,12 +0,0 @@
#include <windows.h>
#define ID_FILE_NEW 0xE100
#define ID_FILE_OPEN 0xE101
#define ID_FILE_SAVE 0xE103
#define ID_FILE_SAVE_AS 0xE104
#define ID_EDIT_CLEAR 0xE120
#define ID_EDIT_COPY 0xE122
#define ID_EDIT_CUT 0xE123
#define ID_EDIT_PASTE 0xE125
#define ID_EDIT_SELECT_ALL 0xE12A
#define ID_EDIT_UNDO 0xE12B
#define ID_EDIT_REDO 0xE12C

BIN
editor/appicon.icns Normal file

Binary file not shown.

View File

@ -1,47 +1,177 @@
#include "clientsocket.h"
#include "../sync/track.h"
#include "syncdocument.h"
#include <cassert>
#include <string>
#include <QCryptographicHash>
#include <QtEndian>
void ClientSocket::sendSetKeyCommand(const std::string &trackName, const struct track_key &key)
bool WebSocket::readFrame(QByteArray &buf)
{
unsigned char header[2];
if (!TcpSocket::recv((char *)header, 2))
return false;
// int flags = header[0] >> 4;
int opcode = header[0] & 0xF;
int masked = header[1] >> 7;
int payload_len = header[1] & 0x7f;
if (payload_len == 126) {
quint16 tmp;
if (!TcpSocket::recv((char *)&tmp, 2))
return false;
payload_len = qFromBigEndian(tmp);
} else if (payload_len == 127) {
// dude, that's one crazy big payload! let's bail!
return false;
}
unsigned char mask[4] = { 0 };
if (masked) {
if (!TcpSocket::recv((char *)mask, sizeof(mask)))
return false;
}
buf.resize(payload_len);
if (payload_len > 0) {
if (!TcpSocket::recv(buf.data(), payload_len))
return false;
}
for (int i = 0; i < payload_len; ++i)
buf[i] = buf[i] ^ mask[i & 3];
switch (opcode) {
case 9:
// got ping, send pong!
sendFrame(10, buf.data(), buf.length(), true);
buf.clear();
return true;
case 8:
// close
disconnect();
buf.clear();
return false;
}
return true;
}
bool WebSocket::recv(char *buffer, int length)
{
if (!connected())
return false;
while (length) {
while (!buf.length() && !readFrame(buf))
return false;
int bytes = qMin(buf.length(), length);
memcpy(buffer, buf.data(), bytes);
buf.remove(0, bytes);
buffer += bytes;
length -= bytes;
}
return true;
}
bool WebSocket::sendFrame(int opcode, const char *payloadData, size_t payloadLength, bool endOfMessage)
{
unsigned char header[2];
header[0] = (endOfMessage ? 0x80 : 0) | (unsigned char)opcode;
header[1] = payloadLength < 126 ? (unsigned char)(payloadLength) : 126;
if (!TcpSocket::send((const char *)header, 2, false))
return false;
if (payloadLength >= 126) {
Q_ASSERT(payloadLength < 0xffff);
quint16 tmp = qToBigEndian((quint16)(payloadLength));
if (!TcpSocket::send((const char *)&tmp, 2, false))
return false;
}
firstFrame = endOfMessage;
return TcpSocket::send(payloadData, payloadLength, endOfMessage);
}
WebSocket *WebSocket::upgradeFromHttp(QTcpSocket *socket)
{
QByteArray key;
for (;;) {
QByteArray line;
for (;;) {
char ch;
if (socket->read(&ch, 1) != 1)
return NULL;
if (ch == '\n')
break;
if (ch != '\r')
line.push_back(ch);
}
const char *prefix = "Sec-WebSocket-Key: ";
if (line.startsWith(prefix))
key = line.right(line.length() - int(strlen(prefix)));
else if (!line.length())
break;
}
if (!key.length())
return NULL;
key.append("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(key.data(), key.size());
QString response = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ";
response.append(hash.result().toBase64());
response.append("\r\n\r\n");
socket->write(response.toUtf8().constData(), response.length());
return new WebSocket(socket);
}
void ClientSocket::sendSetKeyCommand(const QString &trackName, const SyncTrack::TrackKey &key)
{
if (!connected() ||
clientTracks.count(trackName) == 0)
return;
uint32_t track = htonl(clientTracks[trackName]);
uint32_t row = htonl(key.row);
quint32 track = qToBigEndian((quint32)clientTracks[trackName]);
quint32 row = qToBigEndian((quint32)key.row);
union {
float f;
uint32_t i;
quint32 i;
} v;
v.f = key.value;
v.i = htonl(v.i);
v.i = qToBigEndian(v.i);
assert(key.type < KEY_TYPE_COUNT);
Q_ASSERT(key.type < SyncTrack::TrackKey::KEY_TYPE_COUNT);
unsigned char cmd = SET_KEY;
send((char *)&cmd, 1, 0);
send((char *)&track, sizeof(track), 0);
send((char *)&row, sizeof(row), 0);
send((char *)&v.i, sizeof(v.i), 0);
send((char *)&key.type, 1, 0);
send((char *)&cmd, 1, false);
send((char *)&track, sizeof(track), false);
send((char *)&row, sizeof(row), false);
send((char *)&v.i, sizeof(v.i), false);
send((char *)&key.type, 1, true);
}
void ClientSocket::sendDeleteKeyCommand(const std::string &trackName, int row)
void ClientSocket::sendDeleteKeyCommand(const QString &trackName, int row)
{
if (!connected() ||
clientTracks.count(trackName) == 0)
return;
uint32_t track = htonl(int(clientTracks[trackName]));
row = htonl(row);
quint32 track = qToBigEndian((quint32)clientTracks[trackName]);
row = qToBigEndian((quint32)row);
unsigned char cmd = DELETE_KEY;
send((char *)&cmd, 1, 0);
send((char *)&track, sizeof(int), 0);
send((char *)&row, sizeof(int), 0);
send((char *)&cmd, 1, false);
send((char *)&track, sizeof(int), false);
send((char *)&row, sizeof(int), true);
}
void ClientSocket::sendSetRowCommand(int row)
@ -50,9 +180,9 @@ void ClientSocket::sendSetRowCommand(int row)
return;
unsigned char cmd = SET_ROW;
row = htonl(row);
send((char *)&cmd, 1, 0);
send((char *)&row, sizeof(int), 0);
row = qToBigEndian((quint32)row);
send((char *)&cmd, 1, false);
send((char *)&row, sizeof(int), true);
}
void ClientSocket::sendPauseCommand(bool pause)
@ -61,9 +191,8 @@ void ClientSocket::sendPauseCommand(bool pause)
return;
unsigned char cmd = PAUSE, flag = pause;
send((char *)&cmd, 1, 0);
send((char *)&flag, 1, 0);
clientPaused = pause;
send((char *)&cmd, 1, false);
send((char *)&flag, 1, true);
}
void ClientSocket::sendSaveCommand()
@ -72,5 +201,5 @@ void ClientSocket::sendSaveCommand()
return;
unsigned char cmd = SAVE_TRACKS;
send((char *)&cmd, 1, 0);
send((char *)&cmd, 1, true);
}

View File

@ -1,63 +1,178 @@
#include "../sync/base.h"
#include <map>
#ifndef CLIENTSOCKET_H
#define CLIENTSOCKET_H
class ClientSocket {
#include <QTcpSocket>
#include <QByteArray>
#include <QObject>
#include "synctrack.h"
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"
enum {
SET_KEY = 0,
DELETE_KEY = 1,
GET_TRACK = 2,
SET_ROW = 3,
PAUSE = 4,
SAVE_TRACKS = 5
};
class TcpSocket {
public:
ClientSocket() : socket(INVALID_SOCKET) {}
explicit ClientSocket(SOCKET socket) : socket(socket), clientPaused(true) {}
explicit TcpSocket(QAbstractSocket *socket) : socket(socket) {}
bool connected() const
{
return INVALID_SOCKET != socket;
return socket != NULL;
}
virtual void disconnect()
{
if (connected())
socket->close();
socket = NULL;
}
virtual bool recv(char *buffer, int length)
{
if (!connected())
return false;
// wait for enough data to arrive
while (socket->bytesAvailable() < int(length)) {
if (!socket->waitForReadyRead(-1))
break;
}
qint64 ret = socket->read(buffer, length);
if (ret != int(length)) {
TcpSocket::disconnect();
return false;
}
return true;
}
virtual bool send(const char *buffer, size_t length, bool endOfMessage)
{
(void)endOfMessage;
if (!connected())
return false;
int ret = socket->write(buffer, length);
if (ret != int(length)) {
TcpSocket::disconnect();
return false;
}
return true;
}
virtual bool pollRead()
{
if (!connected())
return false;
return socket->bytesAvailable() > 0;
}
QAbstractSocket *socket;
};
class WebSocket : public TcpSocket {
public:
explicit WebSocket(QTcpSocket *socket) : TcpSocket(socket), firstFrame(true) {}
bool recv(char *buffer, int length);
bool send(const char *buffer, size_t length, bool endOfMessage)
{
return sendFrame(firstFrame ? 2 : 0, buffer, length, endOfMessage);
}
virtual void disconnect()
{
sendFrame(8, NULL, 0, true);
TcpSocket::disconnect();
}
bool pollRead()
{
if (buf.length() > 0)
return true;
return TcpSocket::pollRead();
}
// helpers
bool readFrame(QByteArray &buf);
bool sendFrame(int opcode, const char *payloadData, size_t payloadLength, bool endOfMessage);
static WebSocket *upgradeFromHttp(QTcpSocket *socket);
private:
bool firstFrame;
QByteArray buf;
};
class ClientSocket : public QObject {
Q_OBJECT
public:
ClientSocket() : socket(NULL) {}
bool connected() const
{
if (!socket)
return false;
return socket->connected();
}
void disconnect()
{
closesocket(socket);
socket = INVALID_SOCKET;
if (socket)
socket->disconnect();
clientTracks.clear();
}
bool recv(char *buffer, size_t length, int flags)
bool recv(char *buffer, int length)
{
if (!connected())
if (!socket)
return false;
int ret = ::recv(socket, buffer, int(length), flags);
if (ret != int(length)) {
disconnect();
return false;
}
return true;
return socket->recv(buffer, length);
}
bool send(const char *buffer, size_t length, int flags)
bool send(const char *buffer, size_t length, bool endOfMessage)
{
if (!connected())
if (!socket)
return false;
int ret = ::send(socket, buffer, int(length), flags);
if (ret != int(length)) {
disconnect();
return false;
}
return true;
return socket->send(buffer, length, endOfMessage);
}
bool pollRead()
{
if (!connected())
return false;
return !!socket_poll(socket);
return socket->pollRead();
}
void sendSetKeyCommand(const std::string &trackName, const struct track_key &key);
void sendDeleteKeyCommand(const std::string &trackName, int row);
void sendSetKeyCommand(const QString &trackName, const SyncTrack::TrackKey &key);
void sendDeleteKeyCommand(const QString &trackName, int row);
void sendSetRowCommand(int row);
void sendPauseCommand(bool pause);
void sendSaveCommand();
bool clientPaused;
std::map<const std::string, size_t> clientTracks;
QMap<QString, size_t> clientTracks;
TcpSocket *socket;
private:
SOCKET socket;
public slots:
void onPauseChanged(bool paused)
{
sendPauseCommand(paused);
}
void onKeyFrameChanged(const SyncTrack &track, int row)
{
if (track.isKeyFrame(row))
sendSetKeyCommand(track.name, track.getKeyFrame(row));
else
sendDeleteKeyCommand(track.name, row);
}
};
#endif // !defined(CLIENTSOCKET_H)

Binary file not shown.

View File

@ -1,765 +1,34 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#include <QApplication>
#include <QMessageBox>
#include <QTcpServer>
#include "mainwindow.h"
#include "../sync/base.h"
#include "afxres.h"
#include "resource.h"
#include <commctrl.h>
#include <objbase.h>
#include <commdlg.h>
#include <shellapi.h>
#include <stdio.h>
#include <stdarg.h>
// Windows XP look and feel. Seems to enable Vista look as well.
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' " \
"name='Microsoft.Windows.Common-Controls' " \
"version='6.0.0.0' " \
"processorArchitecture='*' " \
"publicKeyToken='6595b64144ccf1df' " \
"language='*'\"")
#include "trackview.h"
#include "recentfiles.h"
#include <vector>
static const wchar_t *mainWindowClassName = L"MainWindow";
static const char *mainWindowTitle = "GNU Rocket System";
static const wchar_t *mainWindowTitleW = L"GNU Rocket System";
static const char *keyName = "SOFTWARE\\GNU Rocket";
static void verror(const char *fmt, va_list va)
int main(int argc, char *argv[])
{
char temp[4096];
vsnprintf(temp, sizeof(temp), fmt, va);
MessageBox(NULL, temp, mainWindowTitle, MB_OK | MB_ICONERROR);
}
QApplication app(argc, argv);
app.setOrganizationName("GNU Rocket Foundation");
app.setApplicationName("GNU Rocket Editor");
app.setWindowIcon(QIcon(":appicon.ico"));
static void error(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
verror(fmt, va);
va_end(va);
}
static void die(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
verror(fmt, va);
va_end(va);
exit(EXIT_FAILURE);
}
static HINSTANCE hInst;
static HWND hwnd = NULL;
static TrackView *trackView = NULL;
static HWND trackViewWin = NULL;
static HWND statusBarWin = NULL;
static HKEY regConfigKey = NULL;
static RecentFiles mruFileList(NULL);
#define WM_SETROWS (WM_USER+1)
#define WM_BIASSELECTION (WM_USER+2)
#include "../sync/sync.h"
static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
size_t *rows = (size_t *)lParam;
SetDlgItemInt(hDlg, IDC_SETROWS_EDIT, *rows, FALSE);
return TRUE;
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
/* get value */
size_t result = GetDlgItemInt(hDlg, IDC_SETROWS_EDIT, NULL, FALSE);
/* update editor */
SendMessage(GetParent(hDlg), WM_SETROWS, 0, result);
/* end dialog */
return EndDialog(hDlg, LOWORD(wParam));
} else if(LOWORD(wParam) == IDCANCEL)
return EndDialog( hDlg, LOWORD(wParam));
break;
case WM_CLOSE:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
return FALSE;
}
static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
int *intialBias = (int*)lParam;
SetDlgItemInt(hDlg, IDC_BIASSELECTION_EDIT, *intialBias, TRUE);
return TRUE;
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
/* get value */
int bias = GetDlgItemInt(hDlg, IDC_BIASSELECTION_EDIT, NULL, FALSE);
/* update editor */
SendMessage(GetParent(hDlg), WM_BIASSELECTION, 0, LPARAM(bias));
/* end dialog */
return EndDialog(hDlg, LOWORD(wParam));
} else if(LOWORD(wParam) == IDCANCEL)
return EndDialog( hDlg, LOWORD(wParam));
break;
case WM_CLOSE:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
return FALSE;
}
static void setWindowFileName(std::wstring fileName)
{
wchar_t drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
_wsplitpath(fileName.c_str(), drive, dir, fname, ext);
std::wstring windowTitle = std::wstring(fname) + std::wstring(L" - ") + std::wstring(mainWindowTitleW);
SetWindowTextW(hwnd, windowTitle.c_str());
}
static HMENU findSubMenuContaining(HMENU menu, UINT id)
{
for (int i = 0; i < GetMenuItemCount(menu); ++i)
{
if (GetMenuItemID(menu, i) == id) return menu;
else
{
HMENU subMenu = GetSubMenu(menu, i);
if ((HMENU)0 != subMenu)
{
HMENU ret = findSubMenuContaining(subMenu, id);
if ((HMENU)0 != ret) return ret;
}
}
}
return (HMENU)0;
}
static void setDocument(SyncDocument *newDoc)
{
SyncDocument *oldDoc = trackView->getDocument();
if (oldDoc && oldDoc->clientSocket.connected()) {
// delete old key-frames
for (size_t i = 0; i < oldDoc->num_tracks; ++i) {
sync_track *t = oldDoc->tracks[i];
for (int j = 0; j < t->num_keys; ++j)
oldDoc->clientSocket.sendDeleteKeyCommand(t->name, t->keys[j].row);
}
if (newDoc) {
// add back missing client-tracks
std::map<const std::string, size_t>::const_iterator it;
for (it = oldDoc->clientSocket.clientTracks.begin(); it != oldDoc->clientSocket.clientTracks.end(); ++it) {
int trackIndex = sync_find_track(newDoc, it->first.c_str());
if (0 > trackIndex)
trackIndex = int(newDoc->createTrack(it->first.c_str()));
}
// copy socket and update client
newDoc->clientSocket = oldDoc->clientSocket;
for (size_t i = 0; i < newDoc->num_tracks; ++i) {
sync_track *t = newDoc->tracks[i];
for (int j = 0; j < t->num_keys; ++j)
newDoc->clientSocket.sendSetKeyCommand(t->name, t->keys[j]);
}
}
QTcpServer serverSocket;
if (!serverSocket.listen(QHostAddress::Any, 1338)) {
QMessageBox::critical(NULL, NULL, QString("Could not start server:\n%1").arg(serverSocket.errorString()), QMessageBox::Ok);
exit(EXIT_FAILURE);
}
trackView->setDocument(newDoc);
SendMessage(hwnd, WM_CURRVALDIRTY, 0, 0);
InvalidateRect(trackViewWin, NULL, FALSE);
MainWindow mainWindow(&serverSocket);
if (oldDoc)
delete oldDoc;
}
static void fileNew()
{
setDocument(new SyncDocument);
setWindowFileName(L"Untitled");
}
static void loadDocument(const std::wstring &_fileName)
{
SyncDocument *newDoc = SyncDocument::load(_fileName);
if (newDoc) {
// update MRU list
mruFileList.insert(_fileName);
mruFileList.update();
DrawMenuBar(hwnd);
// set new document
setDocument(newDoc);
setWindowFileName(_fileName.c_str());
}
else
error("failed to open file");
}
static void fileOpen()
{
wchar_t temp[_MAX_FNAME + 1];
temp[0] = L'\0'; // clear string
OPENFILENAMEW ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = temp;
ofn.nMaxFile = _MAX_FNAME;
ofn.lpstrDefExt = L"rocket";
ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
ofn.Flags = OFN_SHOWHELP | OFN_FILEMUSTEXIST;
if (GetOpenFileNameW(&ofn))
{
loadDocument(temp);
}
}
static bool fileSaveAs()
{
wchar_t temp[_MAX_FNAME + 1];
temp[0] = '\0';
OPENFILENAMEW ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = temp;
ofn.nMaxFile = _MAX_FNAME;
ofn.lpstrDefExt = L"rocket";
ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
if (GetSaveFileNameW(&ofn)) {
SyncDocument *doc = trackView->getDocument();
if (doc->save(temp)) {
doc->clientSocket.sendSaveCommand();
setWindowFileName(temp);
doc->fileName = temp;
mruFileList.insert(temp);
mruFileList.update();
DrawMenuBar(hwnd);
return true;
} else
error("Failed to save file");
}
return false;
}
static bool fileSave()
{
SyncDocument *doc = trackView->getDocument();
if (doc->fileName.empty())
return fileSaveAs();
if (!doc->save(doc->fileName)) {
doc->clientSocket.sendSaveCommand();
error("Failed to save file");
return false;
}
return true;
}
static void attemptQuit()
{
SyncDocument *doc = trackView->getDocument();
if (doc->modified()) {
UINT res = MessageBox(hwnd, "Save before exit?", mainWindowTitle, MB_YESNOCANCEL | MB_ICONQUESTION);
if ((IDYES == res && fileSave()) || (IDNO == res))
DestroyWindow(hwnd);
}
else DestroyWindow(hwnd);
}
static HWND createStatusBar(HINSTANCE hInstance, HWND hpwnd)
{
HWND hwnd = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // status bar
(LPCTSTR)NULL, // no text
SBARS_SIZEGRIP | WS_VISIBLE | WS_CHILD, // styles
0, 0, 0, 0, // x, y, cx, cy
hpwnd, // parent window
NULL, // menu
hInstance, // instance
NULL // window data
);
int statwidths[] = { 150, 150 + 32, 150 + 32 * 2, 150 + 32 * 4, 150 + 32 * 6};
SendMessage(hwnd, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);
SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"Not connected");
SendMessage(hwnd, SB_SETTEXT, 1, (LPARAM)"0");
SendMessage(hwnd, SB_SETTEXT, 2, (LPARAM)"0");
SendMessage(hwnd, SB_SETTEXT, 3, (LPARAM)"---");
return hwnd;
}
static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
SyncDocument *doc = trackView ? trackView->getDocument() : NULL;
switch(msg)
{
case WM_CREATE:
{
trackViewWin = trackView->create(hInst, hwnd);
InitCommonControls();
statusBarWin = createStatusBar(hInst, hwnd);
if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, keyName, &regConfigKey))
{
if (ERROR_SUCCESS != RegCreateKey(HKEY_CURRENT_USER, keyName, &regConfigKey))
die("failed to create registry key");
}
/* Recent Files menu */
mruFileList = RecentFiles(findSubMenuContaining(GetMenu(hwnd), ID_RECENTFILES_NORECENTFILES));
mruFileList.load(regConfigKey);
if (app.arguments().size() > 1) {
if (app.arguments().size() > 2) {
QMessageBox::critical(&mainWindow, NULL, QString("usage: %1 [filename.rocket]").arg(argv[0]), QMessageBox::Ok);
exit(EXIT_FAILURE);
}
break;
mainWindow.loadDocument(app.arguments()[1]);
} else
mainWindow.fileNew();
case WM_CLOSE:
attemptQuit();
break;
case WM_DESTROY:
mruFileList.save(regConfigKey);
RegCloseKey(regConfigKey);
regConfigKey = NULL;
PostQuitMessage(0);
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
RECT statusBarRect;
GetClientRect(statusBarWin, &statusBarRect);
int statusBarHeight = statusBarRect.bottom - statusBarRect.top;
MoveWindow(trackViewWin, 0, 0, width, height - statusBarHeight, TRUE);
MoveWindow(statusBarWin, 0, height - statusBarHeight, width, statusBarHeight, TRUE);
}
break;
case WM_SETFOCUS:
SetFocus(trackViewWin); // needed to forward keyboard input
break;
case WM_SETROWS:
trackView->setRows(int(lParam));
break;
case WM_BIASSELECTION:
trackView->editBiasValue(float(lParam));
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_FILE_NEW:
fileNew();
InvalidateRect(trackViewWin, NULL, FALSE);
break;
case ID_FILE_OPEN:
fileOpen();
break;
case ID_FILE_SAVE_AS:
fileSaveAs();
break;
case ID_FILE_SAVE:
fileSave();
break;
case ID_EDIT_SELECTALL:
trackView->selectAll();
break;
case ID_EDIT_SELECTTRACK:
trackView->selectTrack(trackView->getEditTrack());
break;
case ID_EDIT_SELECTROW:
trackView->selectRow(trackView->getEditRow());
break;
case ID_FILE_REMOTEEXPORT:
doc->clientSocket.sendSaveCommand();
break;
case ID_RECENTFILES_FILE1:
case ID_RECENTFILES_FILE2:
case ID_RECENTFILES_FILE3:
case ID_RECENTFILES_FILE4:
case ID_RECENTFILES_FILE5:
{
int index = LOWORD(wParam) - ID_RECENTFILES_FILE1;
std::wstring fileName;
if (mruFileList.getEntry(index, fileName))
{
loadDocument(fileName);
}
}
break;
case ID_FILE_EXIT:
attemptQuit();
break;
case ID_EDIT_UNDO: SendMessage(trackViewWin, WM_UNDO, 0, 0); break;
case ID_EDIT_REDO: SendMessage(trackViewWin, WM_REDO, 0, 0); break;
case ID_EDIT_COPY: SendMessage(trackViewWin, WM_COPY, 0, 0); break;
case ID_EDIT_CUT: SendMessage(trackViewWin, WM_CUT, 0, 0); break;
case ID_EDIT_PASTE: SendMessage(trackViewWin, WM_PASTE, 0, 0); break;
mainWindow.show();
app.exec();
case ID_EDIT_BOOKMARK_PREV:
{
int row = doc->prevRowBookmark(trackView->getEditRow());
if (row >= 0)
trackView->setEditRow(row);
}
break;
case ID_EDIT_BOOKMARK_NEXT:
{
int row = doc->nextRowBookmark(trackView->getEditRow());
if (row >= 0)
trackView->setEditRow(row);
}
break;
case ID_EDIT_SETROWS:
{
size_t rows = trackView->getRows();
INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
if (FAILED(result))
error("unable to create dialog box");
}
break;
case ID_EDIT_BIAS:
{
int initialBias = 0;
INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias);
if (FAILED(result))
error("unable to create dialog box");
}
break;
}
break;
case WM_ROWCHANGED:
{
char temp[256];
snprintf(temp, 256, "%d", lParam );
SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)temp);
}
break;
case WM_TRACKCHANGED:
{
char temp[256];
snprintf(temp, 256, "%d", lParam);
SendMessage(statusBarWin, SB_SETTEXT, 2, (LPARAM)temp);
}
break;
case WM_CURRVALDIRTY:
{
char temp[256];
if (doc->num_tracks > 0) {
const sync_track *t = doc->tracks[doc->getTrackIndexFromPos(trackView->getEditTrack())];
int row = trackView->getEditRow();
int idx = key_idx_floor(t, row);
snprintf(temp, 256, "%f", sync_get_val(t, row));
const char *str = "---";
if (idx >= 0) {
switch (t->keys[idx].type) {
case KEY_STEP: str = "step"; break;
case KEY_LINEAR: str = "linear"; break;
case KEY_SMOOTH: str = "smooth"; break;
case KEY_RAMP: str = "ramp"; break;
}
}
SendMessage(statusBarWin, SB_SETTEXT, 4, (LPARAM)str);
} else
snprintf(temp, 256, "---");
SendMessage(statusBarWin, SB_SETTEXT, 3, (LPARAM)temp);
}
break;
default:
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
return 0;
}
static ATOM registerMainWindowClass(HINSTANCE hInstance)
{
WNDCLASSEXW wc;
wc.cbSize = sizeof(wc);
wc.style = 0;
wc.lpfnWndProc = mainWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)0;
wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MENU);
wc.lpszClassName = mainWindowClassName;
wc.hIconSm = wc.hIcon;
return RegisterClassExW(&wc);
}
static SOCKET clientConnect(SOCKET serverSocket, sockaddr_in *host)
{
sockaddr_in hostTemp;
int hostSize = sizeof(sockaddr_in);
SOCKET clientSocket = accept(serverSocket, (sockaddr*)&hostTemp, &hostSize);
if (INVALID_SOCKET == clientSocket) return INVALID_SOCKET;
const char *expectedGreeting = CLIENT_GREET;
char recievedGreeting[128];
recv(clientSocket, recievedGreeting, int(strlen(expectedGreeting)), 0);
if (strncmp(expectedGreeting, recievedGreeting, strlen(expectedGreeting)) != 0)
{
closesocket(clientSocket);
return INVALID_SOCKET;
}
const char *greeting = SERVER_GREET;
send(clientSocket, greeting, int(strlen(greeting)), 0);
if (NULL != host) *host = hostTemp;
return clientSocket;
}
static size_t clientIndex;
static void processCommand(ClientSocket &sock)
{
SyncDocument *doc = trackView->getDocument();
int strLen, serverIndex, newRow;
std::string trackName;
const sync_track *t;
unsigned char cmd = 0;
if (sock.recv((char*)&cmd, 1, 0)) {
switch (cmd) {
case GET_TRACK:
// read data
sock.recv((char *)&strLen, sizeof(int), 0);
strLen = ntohl(strLen);
if (!sock.connected())
return;
trackName.resize(strLen);
if (!sock.recv(&trackName[0], strLen, 0))
return;
// find track
serverIndex = sync_find_track(doc,
trackName.c_str());
if (0 > serverIndex)
serverIndex =
int(doc->createTrack(trackName));
// setup remap
doc->clientSocket.clientTracks[trackName] = clientIndex++;
// send key-frames
t = doc->tracks[serverIndex];
for (int i = 0; i < (int)t->num_keys; ++i)
doc->clientSocket.sendSetKeyCommand(trackName,
t->keys[i]);
InvalidateRect(trackViewWin, NULL, FALSE);
break;
case SET_ROW:
sock.recv((char*)&newRow, sizeof(int), 0);
trackView->setEditRow(ntohl(newRow));
break;
}
}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
/* _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); */
// _CrtSetBreakAlloc(254);
#endif
hInst = hInstance;
CoInitialize(NULL);
WSADATA wsa;
if (0 != WSAStartup(MAKEWORD(2, 0), &wsa))
die("Failed to init network");
SOCKET serverSocket = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sin;
memset(&sin, 0, sizeof sin);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(1338);
if (SOCKET_ERROR == bind(serverSocket, (struct sockaddr *)&sin,
sizeof(sin)))
die("Could not start server");
while (listen(serverSocket, SOMAXCONN) == SOCKET_ERROR)
; /* nothing */
ATOM mainClass = registerMainWindowClass(hInstance);
ATOM trackViewClass = registerTrackViewWindowClass(hInstance);
if (!mainClass || !trackViewClass)
die("Window Registration Failed!");
trackView = new TrackView();
hwnd = CreateWindowExW(
0,
mainWindowClassName,
mainWindowTitleW,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
NULL, NULL, hInstance, NULL
);
if (NULL == hwnd)
die("Window Creation Failed!");
int argc;
LPWSTR *argv = argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv && argc > 1) {
if (argc > 2) {
char prog[MAX_PATH];
GetModuleFileNameA(NULL, prog, sizeof(prog));
die("usage: %s [filename.rocket]", prog);
}
loadDocument(argv[1]);
} else
fileNew();
HACCEL accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));
ShowWindow(hwnd, TRUE);
UpdateWindow(hwnd);
bool done = false;
MSG msg;
bool guiConnected = false;
while (!done) {
SyncDocument *doc = trackView->getDocument();
if (!doc->clientSocket.connected()) {
SOCKET clientSocket = INVALID_SOCKET;
fd_set fds;
FD_ZERO(&fds);
#pragma warning(suppress: 4127)
FD_SET(serverSocket, &fds);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
// look for new clients
if (select(0, &fds, NULL, NULL, &timeout) > 0)
{
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Accepting...");
sockaddr_in client;
clientSocket = clientConnect(serverSocket, &client);
if (INVALID_SOCKET != clientSocket)
{
char temp[256];
snprintf(temp, 256, "Connected to %s", inet_ntoa(client.sin_addr));
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)temp);
doc->clientSocket = ClientSocket(clientSocket);
clientIndex = 0;
doc->clientSocket.sendPauseCommand(true);
doc->clientSocket.sendSetRowCommand(trackView->getEditRow());
guiConnected = true;
}
else SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Not Connected.");
}
}
if (doc->clientSocket.connected()) {
ClientSocket &clientSocket = doc->clientSocket;
// look for new commands
while (clientSocket.pollRead())
processCommand(clientSocket);
}
if (!doc->clientSocket.connected() && guiConnected) {
doc->clientSocket.clientPaused = true;
InvalidateRect(trackViewWin, NULL, FALSE);
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Not Connected.");
guiConnected = false;
}
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!TranslateAccelerator(hwnd, accel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (WM_QUIT == msg.message) done = true;
}
}
Sleep(1);
}
closesocket(serverSocket);
WSACleanup();
delete trackView;
trackView = NULL;
UnregisterClassW(mainWindowClassName, hInstance);
return int(msg.wParam);
}

28
editor/editor.pro Normal file
View File

@ -0,0 +1,28 @@
TEMPLATE = app
TARGET = editor
DEPENDPATH += .
INCLUDEPATH += .
QT = core gui xml network
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets
}
# Input
HEADERS += clientsocket.h \
mainwindow.h \
syncdocument.h \
synctrack.h \
trackview.h
SOURCES += clientsocket.cpp \
editor.cpp \
mainwindow.cpp \
syncdocument.cpp \
trackview.cpp
RESOURCES += editor.qrc
RC_FILE = editor.rc
ICON = appicon.icns

5
editor/editor.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource>
<file>appicon.ico</file>
</qresource>
</RCC>

View File

@ -1,194 +1 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Norwegian (Bokmal) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NOR)
#ifdef _WIN32
LANGUAGE LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_ACCELERATOR ACCELERATORS
BEGIN
"B", ID_EDIT_BIAS, VIRTKEY, CONTROL, NOINVERT
"C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
"X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
"Z", ID_EDIT_REDO, VIRTKEY, SHIFT, CONTROL, NOINVERT
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
"N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT
"O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
"E", ID_FILE_REMOTEEXPORT, VIRTKEY, CONTROL, NOINVERT
"A", ID_EDIT_SELECT_ALL, VIRTKEY, CONTROL, NOINVERT
"T", ID_EDIT_SELECTTRACK, VIRTKEY, CONTROL, NOINVERT
"R", ID_EDIT_SETROWS, VIRTKEY, CONTROL, NOINVERT
VK_PRIOR, ID_EDIT_BOOKMARK_PREV, VIRTKEY, ALT, NOINVERT
VK_NEXT, ID_EDIT_BOOKMARK_NEXT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
MENUITEM "Save &As", ID_FILE_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "Remote &Export\tCtrl+E", ID_FILE_REMOTEEXPORT
POPUP "Recent &Files"
BEGIN
MENUITEM "No recent files", ID_RECENTFILES_NORECENTFILES, GRAYED
END
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "Undo\tCtrl+Z", ID_EDIT_UNDO
MENUITEM "Redo\tCtrl+Shift+Z", ID_EDIT_REDO
MENUITEM SEPARATOR
MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
MENUITEM "Clear\tDel", ID_EDIT_CLEAR
MENUITEM SEPARATOR
MENUITEM "Select All\tCtrl+A", ID_EDIT_SELECTALL
MENUITEM "Select Track\tCtrl+T", ID_EDIT_SELECTTRACK
MENUITEM "Select Row", ID_EDIT_SELECTROW
MENUITEM SEPARATOR
MENUITEM "&Bias Selection\tCtrl+B", ID_EDIT_BIAS
MENUITEM SEPARATOR
MENUITEM "Set Rows\tCtrl+R", ID_EDIT_SETROWS
MENUITEM SEPARATOR
MENUITEM "Previous Bookmark\tAlt+PgDn", ID_EDIT_BOOKMARK_PREV
MENUITEM "Next Bookmark\tAlt+PgUp", ID_EDIT_BOOKMARK_NEXT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_SETROWS DIALOGEX 0, 0, 129, 27
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Set Rows"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_SETROWS_EDIT,7,6,59,12,ES_AUTOHSCROLL | ES_NUMBER
DEFPUSHBUTTON "OK",IDOK,72,6,50,14
END
IDD_BIASSELECTION DIALOGEX 0, 0, 129, 27
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Bias Selection"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_BIASSELECTION_EDIT,7,6,59,12,ES_AUTOHSCROLL | ES_NUMBER
DEFPUSHBUTTON "OK",IDOK,72,6,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_SETROWS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 20
END
IDD_BIASSELECTION, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 20
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_APPLICATION ICON "appicon.ico"
#endif // Norwegian (Bokmal) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -1,269 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="sync_editor"
ProjectGUID="{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
RootNamespace="sync_editor"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib comctl32.lib comsupp.lib comsuppwd.lib"
LinkIncremental="2"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib comctl32.lib "
LinkIncremental="1"
GenerateManifest="false"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
EmbedManifest="false"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\clientsocket.cpp"
>
</File>
<File
RelativePath="..\sync\data.c"
>
</File>
<File
RelativePath=".\editor.cpp"
>
</File>
<File
RelativePath=".\recentfiles.cpp"
>
</File>
<File
RelativePath=".\syncdocument.cpp"
>
</File>
<File
RelativePath="..\sync\track.c"
>
</File>
<File
RelativePath=".\trackview.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\clientsocket.h"
>
</File>
<File
RelativePath="..\sync\data.h"
>
</File>
<File
RelativePath="..\sync\device.h"
>
</File>
<File
RelativePath=".\recentfiles.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath="..\sync\sync.h"
>
</File>
<File
RelativePath=".\syncdocument.h"
>
</File>
<File
RelativePath="..\sync\track.h"
>
</File>
<File
RelativePath=".\trackview.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\appicon.ico"
>
</File>
<File
RelativePath=".\editor.rc"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

578
editor/mainwindow.cpp Normal file
View File

@ -0,0 +1,578 @@
#include "mainwindow.h"
#include "trackview.h"
#include "syncdocument.h"
#include <QApplication>
#include <QMenuBar>
#include <QStatusBar>
#include <QLabel>
#include <QFileInfo>
#include <QSettings>
#include <QMessageBox>
#include <QFileDialog>
#include <QInputDialog>
#include <QTcpServer>
#include <QtEndian>
MainWindow::MainWindow(QTcpServer *serverSocket) :
QMainWindow(),
serverSocket(serverSocket),
clientIndex(0)
{
trackView = new TrackView(this);
setCentralWidget(trackView);
connect(trackView, SIGNAL(posChanged(int, int)),
this, SLOT(onPosChanged(int, int)));
connect(trackView, SIGNAL(pauseChanged(bool)),
&clientSocket, SLOT(onPauseChanged(bool)));
connect(trackView, SIGNAL(currValDirty()),
this, SLOT(onCurrValDirty()));
createMenuBar();
createStatusBar();
connect(serverSocket, SIGNAL(newConnection()),
this, SLOT(onNewConnection()));
}
void MainWindow::showEvent(QShowEvent *event)
{
QMainWindow::showEvent(event);
// workaround for QTBUG-16507
QString filePath = windowFilePath();
setWindowFilePath(filePath + "foo");
setWindowFilePath(filePath);
}
void MainWindow::createMenuBar()
{
fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction(QIcon::fromTheme("document-new"), "New", this, SLOT(fileNew()), QKeySequence::New);
fileMenu->addAction(QIcon::fromTheme("document-open"), "&Open", this, SLOT(fileOpen()), QKeySequence::Open);
fileMenu->addAction(QIcon::fromTheme("document-save"), "&Save", this, SLOT(fileSave()), QKeySequence::Save);
fileMenu->addAction(QIcon::fromTheme("document-save-as"),"Save &As", this, SLOT(fileSaveAs()), QKeySequence::SaveAs);
fileMenu->addSeparator();
fileMenu->addAction("Remote &Export", this, SLOT(fileRemoteExport()), Qt::CTRL + Qt::Key_E);
recentFilesMenu = fileMenu->addMenu(QIcon::fromTheme("document-open-recent"), "Recent &Files");
for (int i = 0; i < 5; ++i) {
recentFileActions[i] = recentFilesMenu->addAction(QIcon::fromTheme("document-open-recent"), "");
recentFileActions[i]->setVisible(false);
connect(recentFileActions[i], SIGNAL(triggered()),
this, SLOT(openRecentFile()));
}
updateRecentFiles();
fileMenu->addSeparator();
fileMenu->addAction(QIcon::fromTheme("application-exit"), "E&xit", this, SLOT(fileQuit()), QKeySequence::Quit);
editMenu = menuBar()->addMenu("&Edit");
editMenu->addAction(QIcon::fromTheme("edit-undo"), "Undo", trackView, SLOT(editUndo()), QKeySequence::Undo);
editMenu->addAction(QIcon::fromTheme("edit-redo"), "Redo", trackView, SLOT(editRedo()), QKeySequence::Redo);
editMenu->addSeparator();
editMenu->addAction(QIcon::fromTheme("edit-copy"), "&Copy", trackView, SLOT(editCopy()), QKeySequence::Copy);
editMenu->addAction(QIcon::fromTheme("edit-cut"), "Cu&t", trackView, SLOT(editCut()), QKeySequence::Cut);
editMenu->addAction(QIcon::fromTheme("edit-paste"), "&Paste", trackView, SLOT(editPaste()), QKeySequence::Paste);
editMenu->addAction(QIcon::fromTheme("edit-clear"), "Clear", trackView, SLOT(editClear()), QKeySequence::Delete);
editMenu->addSeparator();
editMenu->addAction(QIcon::fromTheme("edit-select-all"), "Select All", trackView, SLOT(selectAll()), QKeySequence::SelectAll);
editMenu->addAction("Select Track", trackView, SLOT(selectTrack()), Qt::CTRL + Qt::Key_T);
editMenu->addAction("Select Row", trackView, SLOT(selectRow()));
editMenu->addSeparator();
editMenu->addAction("Bias Selection", this, SLOT(editBiasSelection()), Qt::CTRL + Qt::Key_B);
editMenu->addSeparator();
editMenu->addAction("Set Rows", this, SLOT(editSetRows()), Qt::CTRL + Qt::Key_R);
editMenu->addSeparator();
editMenu->addAction("Previous Bookmark", this, SLOT(editPreviousBookmark()), Qt::ALT + Qt::Key_PageUp);
editMenu->addAction("Next Bookmark", this, SLOT(editNextBookmark()), Qt::ALT + Qt::Key_PageDown);
}
void MainWindow::createStatusBar()
{
statusPos = new QLabel;
statusValue = new QLabel;
statusKeyType = new QLabel;
statusBar()->addPermanentWidget(statusPos);
statusBar()->addPermanentWidget(statusValue);
statusBar()->addPermanentWidget(statusKeyType);
statusBar()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
setStatusText("Not connected");
setStatusPosition(0, 0);
setStatusValue(0.0f, false);
setStatusKeyType(SyncTrack::TrackKey::STEP, false);
}
static QStringList getRecentFiles()
{
#ifdef Q_OS_WIN32
QSettings settings("HKEY_CURRENT_USER\\Software\\GNU Rocket",
QSettings::NativeFormat);
#else
QSettings settings;
#endif
QStringList list;
for (int i = 0; i < 5; ++i) {
QVariant string = settings.value(QString("RecentFile%1").arg(i));
if (string.isValid())
list.push_back(string.toString());
}
return list;
}
static void setRecentFiles(const QStringList &files)
{
#ifdef Q_OS_WIN32
QSettings settings("HKEY_CURRENT_USER\\Software\\GNU Rocket",
QSettings::NativeFormat);
#else
QSettings settings;
#endif
for (int i = 0; i < files.size(); ++i)
settings.setValue(QString("RecentFile%1").arg(i), files[i]);
// remove keys not in the list
for (int i = files.size(); ;++i) {
QString key = QString("RecentFile%1").arg(i);
if (!settings.contains(key))
break;
settings.remove(key);
}
}
void MainWindow::updateRecentFiles()
{
QStringList files = getRecentFiles();
if (!files.size()) {
recentFilesMenu->setEnabled(false);
return;
}
Q_ASSERT(files.size() <= 5);
for (int i = 0; i < files.size(); ++i) {
QFileInfo info(files[i]);
QString text = QString("&%1 %2").arg(i + 1).arg(info.fileName());
recentFileActions[i]->setText(text);
recentFileActions[i]->setData(info.absoluteFilePath());
recentFileActions[i]->setVisible(true);
}
for (int i = files.size(); i < 5; ++i)
recentFileActions[i]->setVisible(false);
recentFilesMenu->setEnabled(true);
}
void MainWindow::setCurrentFileName(const QString &fileName)
{
QFileInfo info(fileName);
QStringList files = getRecentFiles();
files.removeAll(info.absoluteFilePath());
files.prepend(info.absoluteFilePath());
while (files.size() > 5)
files.removeLast();
setRecentFiles(files);
updateRecentFiles();
setWindowFilePath(fileName);
}
void MainWindow::setStatusText(const QString &text)
{
statusBar()->showMessage(text);
}
void MainWindow::setStatusPosition(int col, int row)
{
statusPos->setText(QString("Row %1, Col %2").arg(row).arg(col));
}
void MainWindow::setStatusValue(double val, bool valid)
{
if (valid)
statusValue->setText(QString::number(val, 'f', 3));
else
statusValue->setText("---");
}
void MainWindow::setStatusKeyType(SyncTrack::TrackKey::KeyType keyType, bool valid)
{
if (!valid) {
statusKeyType->setText("---");
return;
}
switch (keyType) {
case SyncTrack::TrackKey::STEP: statusKeyType->setText("step"); break;
case SyncTrack::TrackKey::LINEAR: statusKeyType->setText("linear"); break;
case SyncTrack::TrackKey::SMOOTH: statusKeyType->setText("smooth"); break;
case SyncTrack::TrackKey::RAMP: statusKeyType->setText("ramp"); break;
default: Q_ASSERT(false);
}
}
void MainWindow::setDocument(SyncDocument *newDoc)
{
SyncDocument *oldDoc = trackView->getDocument();
if (oldDoc)
QObject::disconnect(oldDoc, SIGNAL(modifiedChanged(bool)),
this, SLOT(setWindowModified(bool)));
if (oldDoc && clientSocket.connected()) {
// delete old key frames
for (int i = 0; i < oldDoc->getTrackCount(); ++i) {
SyncTrack *t = oldDoc->getTrack(i);
QMap<int, SyncTrack::TrackKey> keyMap = t->getKeyMap();
QMap<int, SyncTrack::TrackKey>::const_iterator it;
for (it = keyMap.constBegin(); it != keyMap.constEnd(); ++it)
t->removeKey(it.key());
QObject::disconnect(t, SIGNAL(keyFrameChanged(const SyncTrack &, int)),
&clientSocket, SLOT(onKeyFrameChanged(const SyncTrack &, int)));
}
if (newDoc) {
// add back missing client-tracks
QMap<QString, size_t>::const_iterator it;
for (it = clientSocket.clientTracks.begin(); it != clientSocket.clientTracks.end(); ++it) {
SyncTrack *t = newDoc->findTrack(it.key());
if (!t)
newDoc->createTrack(it.key());
}
for (int i = 0; i < newDoc->getTrackCount(); ++i) {
SyncTrack *t = newDoc->getTrack(i);
QMap<int, SyncTrack::TrackKey> keyMap = t->getKeyMap();
QMap<int, SyncTrack::TrackKey>::const_iterator it;
for (it = keyMap.constBegin(); it != keyMap.constEnd(); ++it)
clientSocket.sendSetKeyCommand(t->name.toUtf8().constData(), *it);
QObject::connect(t, SIGNAL(keyFrameChanged(const SyncTrack &, int)),
&clientSocket, SLOT(onKeyFrameChanged(const SyncTrack &, int)));
}
}
}
trackView->setDocument(newDoc);
trackView->dirtyCurrentValue();
trackView->viewport()->update();
QObject::connect(newDoc, SIGNAL(modifiedChanged(bool)),
this, SLOT(setWindowModified(bool)));
if (oldDoc)
delete oldDoc;
}
void MainWindow::fileNew()
{
setDocument(new SyncDocument);
setWindowFilePath("Untitled");
}
bool MainWindow::loadDocument(const QString &path)
{
SyncDocument *newDoc = SyncDocument::load(path);
if (newDoc) {
// set new document
setDocument(newDoc);
setCurrentFileName(path);
return true;
}
return false;
}
void MainWindow::fileOpen()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "", "ROCKET File (*.rocket);;All Files (*.*)");
if (fileName.length()) {
loadDocument(fileName);
}
}
void MainWindow::fileSaveAs()
{
QString fileName = QFileDialog::getSaveFileName(this, "Save File", "", "ROCKET File (*.rocket);;All Files (*.*)");
if (fileName.length()) {
SyncDocument *doc = trackView->getDocument();
if (doc->save(fileName)) {
clientSocket.sendSaveCommand();
setCurrentFileName(fileName);
doc->fileName = fileName;
}
}
}
void MainWindow::fileSave()
{
SyncDocument *doc = trackView->getDocument();
if (doc->fileName.isEmpty())
return fileSaveAs();
if (!doc->save(doc->fileName))
clientSocket.sendSaveCommand();
}
void MainWindow::fileRemoteExport()
{
clientSocket.sendSaveCommand();
}
void MainWindow::openRecentFile()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
QString fileName = action->data().toString();
if (!loadDocument(fileName)) {
QStringList files = getRecentFiles();
files.removeAll(fileName);
setRecentFiles(files);
updateRecentFiles();
}
}
}
void MainWindow::fileQuit()
{
SyncDocument *doc = trackView->getDocument();
if (doc->isModified()) {
QMessageBox::StandardButton res = QMessageBox::question(
this, "GNU Rocket", "Save before exit?",
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (res == QMessageBox::Yes) {
fileSave();
QApplication::quit();
} else if (res == QMessageBox::No)
QApplication::quit();
}
else QApplication::quit();
}
void MainWindow::editBiasSelection()
{
bool ok = false;
float bias = QInputDialog::getDouble(this, "Bias Selection", "", 0, INT_MIN, INT_MAX, 1, &ok);
if (ok)
trackView->editBiasValue(bias);
}
void MainWindow::editSetRows()
{
bool ok = false;
int rows = QInputDialog::getInt(this, "Set Rows", "", trackView->getRows(), 0, INT_MAX, 1, &ok);
if (ok)
trackView->setRows(rows);
}
void MainWindow::editPreviousBookmark()
{
int row = trackView->getDocument()->prevRowBookmark(trackView->getEditRow());
if (row >= 0)
trackView->setEditRow(row);
}
void MainWindow::editNextBookmark()
{
int row = trackView->getDocument()->nextRowBookmark(trackView->getEditRow());
if (row >= 0)
trackView->setEditRow(row);
}
void MainWindow::onPosChanged(int col, int row)
{
setStatusPosition(col, row);
if (trackView->paused && clientSocket.connected())
clientSocket.sendSetRowCommand(row);
}
void MainWindow::onCurrValDirty()
{
SyncDocument *doc = trackView->getDocument();
if (doc && doc->getTrackCount() > 0) {
const SyncTrack *t = doc->getTrack(doc->getTrackIndexFromPos(trackView->getEditTrack()));
int row = trackView->getEditRow();
setStatusValue(t->getValue(row), true);
const SyncTrack::TrackKey *k = t->getPrevKeyFrame(row);
if (k)
setStatusKeyType(k->type, true);
else
setStatusKeyType(SyncTrack::TrackKey::STEP, false);
} else {
setStatusValue(0.0f, false);
setStatusKeyType(SyncTrack::TrackKey::STEP, false);
}
}
void MainWindow::processCommand(ClientSocket &sock)
{
unsigned char cmd = 0;
if (sock.recv((char*)&cmd, 1)) {
switch (cmd) {
case GET_TRACK:
processGetTrack(sock);
break;
case SET_ROW:
processSetRow(sock);
break;
}
}
}
void MainWindow::processGetTrack(ClientSocket &sock)
{
SyncDocument *doc = trackView->getDocument();
// read data
int strLen;
sock.recv((char *)&strLen, sizeof(int));
strLen = qFromBigEndian((quint32)strLen);
if (!sock.connected())
return;
if (!strLen) {
sock.disconnect();
trackView->update();
return;
}
QByteArray trackNameBuffer;
trackNameBuffer.resize(strLen);
if (!sock.recv(trackNameBuffer.data(), strLen))
return;
if (trackNameBuffer.contains('\0')) {
sock.disconnect();
trackView->update();
return;
}
QString trackName = QString::fromUtf8(trackNameBuffer);
// find track
const SyncTrack *t = doc->findTrack(trackName.toUtf8());
if (!t)
t = doc->createTrack(trackName);
// hook up signals to slots
QObject::connect(t, SIGNAL(keyFrameChanged(const SyncTrack &, int)),
&clientSocket, SLOT(onKeyFrameChanged(const SyncTrack &, int)));
// setup remap
clientSocket.clientTracks[trackName] = clientIndex++;
// send key frames
QMap<int, SyncTrack::TrackKey> keyMap = t->getKeyMap();
QMap<int, SyncTrack::TrackKey>::const_iterator it;
for (it = keyMap.constBegin(); it != keyMap.constEnd(); ++it)
clientSocket.sendSetKeyCommand(t->name.toUtf8().constData(), *it);
trackView->update();
}
void MainWindow::processSetRow(ClientSocket &sock)
{
int newRow;
sock.recv((char*)&newRow, sizeof(int));
trackView->setEditRow(qToBigEndian((quint32)newRow));
}
static TcpSocket *clientConnect(QTcpServer *serverSocket, QHostAddress *host)
{
QTcpSocket *clientSocket = serverSocket->nextPendingConnection();
Q_ASSERT(clientSocket != NULL);
QByteArray line;
// Read greetings or WebSocket upgrade
// command from the socket
for (;;) {
char ch;
if (!clientSocket->getChar(&ch)) {
// Read failed; wait for data and try again
clientSocket->waitForReadyRead();
if(!clientSocket->getChar(&ch)) {
clientSocket->close();
return NULL;
}
}
if (ch == '\n')
break;
if (ch != '\r')
line.push_back(ch);
if (ch == '!')
break;
}
TcpSocket *ret = NULL;
if (line.startsWith("GET ")) {
ret = WebSocket::upgradeFromHttp(clientSocket);
line.resize(int(strlen(CLIENT_GREET)));
if (!ret || !ret->recv(line.data(), line.size())) {
clientSocket->close();
return NULL;
}
} else
ret = new TcpSocket(clientSocket);
if (!line.startsWith(CLIENT_GREET) ||
!ret->send(SERVER_GREET, strlen(SERVER_GREET), true)) {
ret->disconnect();
return NULL;
}
if (NULL != host)
*host = clientSocket->peerAddress();
return ret;
}
void MainWindow::onReadyRead()
{
while (clientSocket.pollRead())
processCommand(clientSocket);
}
void MainWindow::onNewConnection()
{
if (!clientSocket.connected()) {
setStatusText("Accepting...");
QHostAddress client;
TcpSocket *socket = clientConnect(serverSocket, &client);
if (socket) {
setStatusText(QString("Connected to %1").arg(client.toString()));
clientSocket.socket = socket;
connect(socket->socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(socket->socket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
clientIndex = 0;
clientSocket.sendPauseCommand(trackView->paused);
clientSocket.sendSetRowCommand(trackView->getEditRow());
trackView->connected = true;
} else
setStatusText(QString("Not Connected: %1").arg(serverSocket->errorString()));
}
}
void MainWindow::onDisconnected()
{
trackView->paused = true;
clientSocket.disconnect();
// disconnect track-signals
SyncDocument *doc = trackView->getDocument();
for (int i = 0; i < doc->getTrackCount(); ++i)
QObject::disconnect(doc->getTrack(i), SIGNAL(keyFrameChanged(const SyncTrack &, int)),
&clientSocket, SLOT(onKeyFrameChanged(const SyncTrack &, int)));
trackView->update();
setStatusText("Not Connected.");
trackView->connected = false;
}

73
editor/mainwindow.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "synctrack.h"
#include "clientsocket.h"
class QLabel;
class QAction;
class QTcpServer;
class SyncDocument;
class TrackView;
class ClientSocket;
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QTcpServer *serverSocket);
void showEvent(QShowEvent *event);
void createMenuBar();
void createStatusBar();
void updateRecentFiles();
void setCurrentFileName(const QString &fileName);
bool loadDocument(const QString &path);
void setDocument(SyncDocument *newDoc);
void processCommand(ClientSocket &sock);
void processGetTrack(ClientSocket &sock);
void processSetRow(ClientSocket &sock);
void setStatusPosition(int row, int col);
void setStatusText(const QString &text);
void setStatusValue(double val, bool valid);
void setStatusKeyType(SyncTrack::TrackKey::KeyType keyType, bool valid);
QTcpServer *serverSocket;
ClientSocket clientSocket;
size_t clientIndex;
TrackView *trackView;
QLabel *statusPos, *statusValue, *statusKeyType;
QMenu *fileMenu, *recentFilesMenu, *editMenu;
QAction *recentFileActions[5];
public slots:
void fileNew();
void fileOpen();
void fileSave();
void fileSaveAs();
void fileRemoteExport();
void openRecentFile();
void fileQuit();
void editBiasSelection();
void editSetRows();
void editPreviousBookmark();
void editNextBookmark();
void onPosChanged(int col, int row);
void onCurrValDirty();
private slots:
void onReadyRead();
void onNewConnection();
void onDisconnected();
};
#endif // MAINWINDOW_H

View File

@ -1,99 +0,0 @@
#include "../sync/base.h"
#include "recentfiles.h"
#include "resource.h"
#include <assert.h>
#define MAX_DIR_LEN 64
static bool setRegString(HKEY key, const std::wstring &name, const std::wstring &value)
{
return ERROR_SUCCESS == RegSetValueExW(key, name.c_str(), 0, REG_SZ, (BYTE *)value.c_str(), (DWORD)(value.size() + 1) * 2);
}
static bool getRegString(HKEY key, const std::wstring &name, std::wstring &out)
{
DWORD size = 0;
DWORD type = 0;
if (ERROR_SUCCESS != RegQueryValueExW(key, name.c_str(), 0, &type, (LPBYTE)NULL, &size)) return false;
if (REG_SZ != type) return false;
assert(!(size % 1));
out.resize(size / 2);
DWORD ret = RegQueryValueExW(key, name.c_str(), 0, &type, (LPBYTE)&out[0], &size);
while (out.size() > 0 && out[out.size() - 1] == L'\0') out.resize(out.size() - 1);
assert(ret == ERROR_SUCCESS);
assert(REG_SZ == type);
assert(size == (out.size() + 1) * 2);
return true;
}
void RecentFiles::load(HKEY key)
{
for (size_t i = 0; i < 5; ++i)
{
std::wstring fileName;
if (getRegString(key, getEntryName(i), fileName))
{
mruList.push_back(fileName);
}
}
if (mruList.size() > 0) update();
}
void RecentFiles::save(HKEY key)
{
std::list<std::wstring>::const_iterator it;
size_t i;
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
{
assert(i <= 5);
setRegString(key, getEntryName(i), *it);
}
}
void RecentFiles::insert(const std::wstring &fileName)
{
mruList.remove(fileName); // remove, if present
mruList.push_front(fileName); // add to front
while (mruList.size() > 5) mruList.pop_back(); // remove old entries
}
void RecentFiles::update()
{
while (0 != RemoveMenu(mruFileMenu, 0, MF_BYPOSITION));
std::list<std::wstring>::const_iterator it;
size_t i;
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
{
assert(i <= 5);
std::wstring menuEntry = std::wstring(L"&");
menuEntry += wchar_t(L'1' + i);
menuEntry += L" ";
wchar_t path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
_wsplitpath(it->c_str(), drive, dir, fname, ext);
if (wcslen(dir) > MAX_DIR_LEN) wcscpy(dir, L"\\...");
_wmakepath(path, drive, dir, fname, ext);
menuEntry += std::wstring(path);
AppendMenuW(mruFileMenu, MF_STRING, ID_RECENTFILES_FILE1 + i, menuEntry.c_str());
}
}
bool RecentFiles::getEntry(size_t index, std::wstring &out) const
{
std::list<std::wstring>::const_iterator it;
size_t i;
for (i = 0, it = mruList.begin(); it != mruList.end(); ++it, ++i)
{
if (i == index)
{
out = *it;
return true;
}
}
return false;
}

View File

@ -1,32 +0,0 @@
#pragma once
#include <string>
#include <list>
class RecentFiles
{
public:
RecentFiles(HMENU menu) : mruFileMenu(menu) { }
void load(HKEY key);
void save(HKEY key);
void insert(const std::wstring &fileName);
void update();
size_t getEntryCount() const
{
return mruList.size();
}
bool getEntry(size_t index, std::wstring &out) const;
private:
static std::wstring getEntryName(size_t i)
{
std::wstring temp = std::wstring(L"RecentFile");
temp += char(L'0' + i);
return temp;
}
std::list<std::wstring> mruList;
HMENU mruFileMenu;
};

View File

@ -1,40 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by editor.rc
//
#define IDR_ACCELERATOR 101
#define IDR_MENU 102
#define IDD_SETROWS 103
#define IDD_BIASSELECTION 104
#define IDC_EDIT 1002
#define IDC_SETROWS_EDIT 1002
#define IDC_BIASSELECTION_EDIT 1003
#define ID_FILE 40001
#define ID_FILE_EXIT 40002
#define ID_FILE_REMOTEEXPORT 40003
#define ID_FILE_RECENTFILES 40004
#define ID_RECENTFILES_NORECENTFILES 40010
#define ID_RECENTFILES_FILE1 40011
#define ID_RECENTFILES_FILE2 40012
#define ID_RECENTFILES_FILE3 40013
#define ID_RECENTFILES_FILE4 40014
#define ID_RECENTFILES_FILE5 40015
#define ID_EDIT 40020
#define ID_EDIT_SETROWS 40021
#define ID_EDIT_BIAS 40022
#define ID_EDIT_SELECTALL 40023
#define ID_EDIT_SELECTROW 40024
#define ID_EDIT_SELECTTRACK 40025
#define ID_EDIT_BOOKMARK_NEXT 40026
#define ID_EDIT_BOOKMARK_PREV 40027
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40028
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -1,167 +1,324 @@
#include "syncdocument.h"
#include <string>
#include <QFile>
#include <QMessageBox>
#include <QDomDocument>
#include <QTextStream>
SyncDocument::~SyncDocument()
{
sync_data_deinit(this);
clearUndoStack();
clearRedoStack();
for (int i = 0; i < tracks.size(); ++i)
delete tracks[i];
}
#import <msxml3.dll> named_guids
SyncDocument *SyncDocument::load(const std::wstring &fileName)
SyncDocument *SyncDocument::load(const QString &fileName)
{
SyncDocument *ret = new SyncDocument;
ret->fileName = fileName;
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
try {
doc->load(fileName.c_str());
MSXML2::IXMLDOMNamedNodeMapPtr attribs = doc->documentElement->Getattributes();
MSXML2::IXMLDOMNodePtr rowsParam = attribs->getNamedItem("rows");
if (rowsParam) {
std::string rowsString = rowsParam->Gettext();
ret->setRows(atoi(rowsString.c_str()));
}
MSXML2::IXMLDOMNodeListPtr trackNodes =
doc->documentElement->selectNodes("//track");
for (int i = 0; i < trackNodes->Getlength(); ++i) {
MSXML2::IXMLDOMNodePtr trackNode = trackNodes->Getitem(i);
MSXML2::IXMLDOMNamedNodeMapPtr attribs = trackNode->Getattributes();
std::string name = attribs->getNamedItem("name")->Gettext();
// look up track-name, create it if it doesn't exist
int trackIndex = sync_find_track(ret, name.c_str());
if (0 > trackIndex) trackIndex = int(ret->createTrack(name));
MSXML2::IXMLDOMNodeListPtr rowNodes = trackNode->GetchildNodes();
for (int i = 0; i < rowNodes->Getlength(); ++i) {
MSXML2::IXMLDOMNodePtr keyNode = rowNodes->Getitem(i);
std::string baseName = keyNode->GetbaseName();
if (baseName == "key") {
MSXML2::IXMLDOMNamedNodeMapPtr rowAttribs = keyNode->Getattributes();
std::string rowString = rowAttribs->getNamedItem("row")->Gettext();
std::string valueString = rowAttribs->getNamedItem("value")->Gettext();
std::string interpolationString = rowAttribs->getNamedItem("interpolation")->Gettext();
track_key k;
k.row = atoi(rowString.c_str());
k.value = float(atof(valueString.c_str()));
k.type = key_type(atoi(interpolationString.c_str()));
assert(!is_key_frame(ret->tracks[trackIndex], k.row));
if (sync_set_key(ret->tracks[trackIndex], &k))
throw std::bad_alloc("sync_set_key");
}
}
}
MSXML2::IXMLDOMNodeListPtr bookmarkNodes =
doc->documentElement->selectNodes(
"/sync/bookmarks/bookmark");
for (int i = 0; i < bookmarkNodes->Getlength(); ++i) {
MSXML2::IXMLDOMNodePtr bookmarkNode =
bookmarkNodes->Getitem(i);
MSXML2::IXMLDOMNamedNodeMapPtr bookmarkAttribs =
bookmarkNode->Getattributes();
std::string str =
bookmarkAttribs->getNamedItem("row")->Gettext();
int row = atoi(str.c_str());
ret->toggleRowBookmark(row);
}
}
catch(_com_error &e)
{
char temp[256];
_snprintf(temp, 256, "Error loading: %s\n", (const char*)_bstr_t(e.Description()));
MessageBox(NULL, temp, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(NULL, "Error", file.errorString());
return NULL;
}
QDomDocument doc;
QString err;
if (!doc.setContent(&file, &err)) {
file.close();
QMessageBox::critical(NULL, "Error", err);
return NULL;
}
file.close();
QDomNamedNodeMap attribs = doc.documentElement().attributes();
QDomNode rowsParam = attribs.namedItem("rows");
if (!rowsParam.isNull()) {
QString rowsString = rowsParam.nodeValue();
ret->setRows(rowsString.toInt());
}
QDomNodeList trackNodes =
doc.documentElement().elementsByTagName("track");
for (int i = 0; i < int(trackNodes.length()); ++i) {
QDomNode trackNode = trackNodes.item(i);
QDomNamedNodeMap attribs = trackNode.attributes();
QString name = attribs.namedItem("name").nodeValue();
// look up track-name, create it if it doesn't exist
SyncTrack *t = ret->findTrack(name.toUtf8());
if (!t)
t = ret->createTrack(name.toUtf8().constData());
QDomNodeList rowNodes = trackNode.childNodes();
for (int i = 0; i < int(rowNodes.length()); ++i) {
QDomNode keyNode = rowNodes.item(i);
QString baseName = keyNode.nodeName();
if (baseName == "key") {
QDomNamedNodeMap rowAttribs = keyNode.attributes();
QString rowString = rowAttribs.namedItem("row").nodeValue();
QString valueString = rowAttribs.namedItem("value").nodeValue();
QString interpolationString = rowAttribs.namedItem("interpolation").nodeValue();
SyncTrack::TrackKey k;
k.row = rowString.toInt();
k.value = valueString.toFloat();
k.type = SyncTrack::TrackKey::KeyType(interpolationString.toInt());
Q_ASSERT(!t->isKeyFrame(k.row));
t->setKey(k);
}
}
}
// YUCK: gathers from entire document
QDomNodeList bookmarkNodes =
doc.documentElement().elementsByTagName("bookmark");
for (int i = 0; i < int(bookmarkNodes.length()); ++i) {
QDomNode bookmarkNode =
bookmarkNodes.item(i);
QDomNamedNodeMap bookmarkAttribs =
bookmarkNode.attributes();
QString str =
bookmarkAttribs.namedItem("row").nodeValue();
int row = str.toInt();
ret->toggleRowBookmark(row);
}
return ret;
}
bool SyncDocument::save(const std::wstring &fileName)
bool SyncDocument::save(const QString &fileName)
{
MSXML2::IXMLDOMDocumentPtr doc(MSXML2::CLSID_DOMDocument);
try {
MSXML2::IXMLDOMElementPtr rootNode = doc->createElement("sync");
rootNode->setAttribute("rows", getRows());
doc->appendChild(rootNode);
rootNode->appendChild(doc->createTextNode("\n\t"));
QDomDocument doc;
QDomElement rootNode = doc.createElement("sync");
rootNode.setAttribute("rows", int(getRows()));
doc.appendChild(rootNode);
MSXML2::IXMLDOMElementPtr tracksNode =
doc->createElement("tracks");
for (size_t i = 0; i < num_tracks; ++i) {
const sync_track *t = tracks[trackOrder[i]];
rootNode.appendChild(doc.createTextNode("\n\t"));
QDomElement tracksNode =
doc.createElement("tracks");
for (int i = 0; i < getTrackCount(); ++i) {
const SyncTrack *t = getTrack(trackOrder[i]);
MSXML2::IXMLDOMElementPtr trackElem =
doc->createElement("track");
trackElem->setAttribute("name", t->name);
QDomElement trackElem =
doc.createElement("track");
trackElem.setAttribute("name", t->name);
for (int i = 0; i < (int)t->num_keys; ++i) {
size_t row = t->keys[i].row;
float value = t->keys[i].value;
char interpolationType = char(t->keys[i].type);
QMap<int, SyncTrack::TrackKey> keyMap = t->getKeyMap();
QMap<int, SyncTrack::TrackKey>::const_iterator it;
for (it = keyMap.constBegin(); it != keyMap.constEnd(); ++it) {
int row = it.key();
float value = it->value;
char interpolationType = char(it->type);
MSXML2::IXMLDOMElementPtr keyElem =
doc->createElement("key");
QDomElement keyElem =
doc.createElement("key");
keyElem->setAttribute("row", row);
keyElem->setAttribute("value", value);
keyElem->setAttribute("interpolation",
(int)interpolationType);
keyElem.setAttribute("row", row);
keyElem.setAttribute("value", value);
keyElem.setAttribute("interpolation",
(int)interpolationType);
trackElem->appendChild(
doc->createTextNode("\n\t\t\t"));
trackElem->appendChild(keyElem);
}
if (t->num_keys)
trackElem->appendChild(
doc->createTextNode("\n\t\t"));
tracksNode->appendChild(doc->createTextNode("\n\t\t"));
tracksNode->appendChild(trackElem);
trackElem.appendChild(
doc.createTextNode("\n\t\t\t"));
trackElem.appendChild(keyElem);
}
if (0 != num_tracks)
tracksNode->appendChild(doc->createTextNode("\n\t"));
rootNode->appendChild(tracksNode);
rootNode->appendChild(doc->createTextNode("\n\t"));
if (keyMap.size())
trackElem.appendChild(
doc.createTextNode("\n\t\t"));
MSXML2::IXMLDOMElementPtr bookmarksNode =
doc->createElement("bookmarks");
std::set<int>::const_iterator it;
for (it = rowBookmarks.begin(); it != rowBookmarks.end(); ++it) {
MSXML2::IXMLDOMElementPtr bookmarkElem =
doc->createElement("bookmark");
bookmarkElem->setAttribute("row", *it);
bookmarksNode->appendChild(
doc->createTextNode("\n\t\t"));
bookmarksNode->appendChild(bookmarkElem);
}
if (0 != rowBookmarks.size())
bookmarksNode->appendChild(
doc->createTextNode("\n\t"));
rootNode->appendChild(bookmarksNode);
rootNode->appendChild(doc->createTextNode("\n"));
doc->save(fileName.c_str());
savePointDelta = 0;
savePointUnreachable = false;
tracksNode.appendChild(doc.createTextNode("\n\t\t"));
tracksNode.appendChild(trackElem);
}
catch(_com_error &e)
{
char temp[256];
_snprintf(temp, 256, "Error saving: %s\n", (const char*)_bstr_t(e.Description()));
MessageBox(NULL, temp, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
if (getTrackCount())
tracksNode.appendChild(doc.createTextNode("\n\t"));
rootNode.appendChild(tracksNode);
rootNode.appendChild(doc.createTextNode("\n\t"));
QDomElement bookmarksNode =
doc.createElement("bookmarks");
QList<int>::const_iterator it;
for (it = rowBookmarks.begin(); it != rowBookmarks.end(); ++it) {
QDomElement bookmarkElem =
doc.createElement("bookmark");
bookmarkElem.setAttribute("row", *it);
bookmarksNode.appendChild(
doc.createTextNode("\n\t\t"));
bookmarksNode.appendChild(bookmarkElem);
}
if (0 != rowBookmarks.size())
bookmarksNode.appendChild(
doc.createTextNode("\n\t"));
rootNode.appendChild(bookmarksNode);
rootNode.appendChild(doc.createTextNode("\n"));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::critical(NULL, "Error", file.errorString());
return false;
}
QTextStream streamFileOut(&file);
streamFileOut.setCodec("UTF-8");
streamFileOut << doc.toString();
streamFileOut.flush();
file.close();
undoStack.setClean();
return true;
}
int SyncDocument::getTrackIndexFromPos(int track) const
{
Q_ASSERT(track < trackOrder.size());
return trackOrder[track];
}
void SyncDocument::swapTrackOrder(int t1, int t2)
{
Q_ASSERT(t1 < trackOrder.size());
Q_ASSERT(t2 < trackOrder.size());
std::swap(trackOrder[t1], trackOrder[t2]);
}
bool SyncDocument::isRowBookmark(int row) const
{
QList<int>::const_iterator it = qLowerBound(rowBookmarks.begin(), rowBookmarks.end(), row);
return it != rowBookmarks.end() && *it == row;
}
void SyncDocument::toggleRowBookmark(int row)
{
QList<int>::iterator it = qLowerBound(rowBookmarks.begin(), rowBookmarks.end(), row);
if (it == rowBookmarks.end() || *it != row)
rowBookmarks.insert(it, row);
else
rowBookmarks.erase(it);
}
int SyncDocument::nextRowBookmark(int row) const
{
QList<int>::const_iterator it = qLowerBound(rowBookmarks.begin(), rowBookmarks.end(), row);
if (it == rowBookmarks.end())
return -1;
return *it;
}
int SyncDocument::prevRowBookmark(int row) const
{
QList<int>::const_iterator it = qLowerBound(rowBookmarks.begin(), rowBookmarks.end(), row);
if (it == rowBookmarks.end()) {
// this can only really happen if the list is empty
if (it == rowBookmarks.begin())
return -1;
// reached the end, pick the last bookmark if it's after the current row
it--;
return *it < row ? *it : -1;
}
// pick the previous key (if any)
return it != rowBookmarks.begin() ? *(--it) : -1;
}
class InsertCommand : public QUndoCommand
{
public:
InsertCommand(SyncTrack *track, const SyncTrack::TrackKey &key, QUndoCommand *parent = 0) :
QUndoCommand("insert", parent),
track(track),
key(key)
{}
void redo()
{
Q_ASSERT(!track->isKeyFrame(key.row));
track->setKey(key);
}
void undo()
{
Q_ASSERT(track->isKeyFrame(key.row));
track->removeKey(key.row);
}
private:
SyncTrack *track;
SyncTrack::TrackKey key;
};
class DeleteCommand : public QUndoCommand
{
public:
DeleteCommand(SyncTrack *track, int row, QUndoCommand *parent = 0) :
QUndoCommand("delete", parent),
track(track),
row(row)
{}
void redo()
{
Q_ASSERT(track->isKeyFrame(row));
oldKey = track->getKeyFrame(row);
Q_ASSERT(oldKey.row == row);
track->removeKey(row);
}
void undo()
{
Q_ASSERT(!track->isKeyFrame(row));
Q_ASSERT(oldKey.row == row);
track->setKey(oldKey);
}
private:
SyncTrack *track;
int row;
SyncTrack::TrackKey oldKey;
};
class EditCommand : public QUndoCommand
{
public:
EditCommand(SyncTrack *track, const SyncTrack::TrackKey &key, QUndoCommand *parent = 0) :
QUndoCommand("edit", parent),
track(track),
key(key)
{}
void redo()
{
Q_ASSERT(track->isKeyFrame(key.row));
oldKey = track->getKeyFrame(key.row);
Q_ASSERT(key.row == oldKey.row);
track->setKey(key);
}
void undo()
{
Q_ASSERT(track->isKeyFrame(oldKey.row));
Q_ASSERT(key.row == oldKey.row);
track->setKey(oldKey);
}
private:
SyncTrack *track;
SyncTrack::TrackKey oldKey, key;
};
void SyncDocument::setKeyFrame(SyncTrack *track, const SyncTrack::TrackKey &key)
{
if (track->isKeyFrame(key.row))
undoStack.push(new EditCommand(track, key));
else
undoStack.push(new InsertCommand(track, key));
}
void SyncDocument::deleteKeyFrame(SyncTrack *track, int row)
{
undoStack.push(new DeleteCommand(track, row));
}

View File

@ -1,324 +1,106 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef SYNCDOCUMENT_H
#define SYNCDOCUMENT_H
#pragma once
extern "C" {
#include "../sync/data.h"
}
#include <stack>
#include <list>
#include <vector>
#include <set>
#include <string>
#include <cassert>
#include <QStack>
#include <QList>
#include <QVector>
#include <QString>
#include <QUndoCommand>
#include <QUndoStack>
#include "clientsocket.h"
#include "synctrack.h"
class SyncDocument : public sync_data {
class SyncDocument : public QObject {
Q_OBJECT
public:
SyncDocument() :
rows(128), savePointDelta(0), savePointUnreachable(false)
rows(128)
{
this->tracks = NULL;
this->num_tracks = 0;
QObject::connect(&undoStack, SIGNAL(cleanChanged(bool)),
this, SLOT(cleanChanged(bool)));
}
~SyncDocument();
size_t createTrack(const std::string &name)
SyncTrack *createTrack(const QString &name)
{
size_t index = sync_create_track(this, name.c_str());
SyncTrack *t = new SyncTrack(name);
tracks.append(t);
int index = tracks.size() - 1;
trackOrder.push_back(index);
return index;
Q_ASSERT(trackOrder.size() == tracks.size());
return t;
}
class Command
SyncTrack *getTrack(int index)
{
public:
virtual ~Command() {}
virtual void exec(SyncDocument *data) = 0;
virtual void undo(SyncDocument *data) = 0;
};
class InsertCommand : public Command
{
public:
InsertCommand(int track, const track_key &key) : track(track), key(key) {}
~InsertCommand() {}
void exec(SyncDocument *data)
{
sync_track *t = data->tracks[track];
assert(!is_key_frame(t, key.row));
if (sync_set_key(t, &key))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(t->name, key); // update clients
}
void undo(SyncDocument *data)
{
sync_track *t = data->tracks[track];
assert(is_key_frame(t, key.row));
if (sync_del_key(t, key.row))
throw std::bad_alloc("sync_del_key");
data->clientSocket.sendDeleteKeyCommand(t->name, key.row); // update clients
}
private:
int track;
track_key key;
};
class DeleteCommand : public Command
{
public:
DeleteCommand(int track, int row) : track(track), row(row) {}
~DeleteCommand() {}
void exec(SyncDocument *data)
{
sync_track *t = data->tracks[track];
int idx = sync_find_key(t, row);
assert(idx >= 0);
oldKey = t->keys[idx];
if (sync_del_key(t, row))
throw std::bad_alloc("sync_del_key");
data->clientSocket.sendDeleteKeyCommand(t->name, row); // update clients
}
void undo(SyncDocument *data)
{
sync_track *t = data->tracks[track];
assert(!is_key_frame(t, row));
if (sync_set_key(t, &oldKey))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(t->name, oldKey); // update clients
}
private:
int track, row;
struct track_key oldKey;
};
class EditCommand : public Command
{
public:
EditCommand(int track, const track_key &key) : track(track), key(key) {}
~EditCommand() {}
void exec(SyncDocument *data)
{
sync_track *t = data->tracks[track];
int idx = sync_find_key(t, key.row);
assert(idx >= 0);
oldKey = t->keys[idx];
if (sync_set_key(t, &key))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(t->name, key); // update clients
}
void undo(SyncDocument *data)
{
sync_track *t = data->tracks[track];
assert(is_key_frame(t, key.row));
if (sync_set_key(t, &oldKey))
throw std::bad_alloc("sync_set_key");
data->clientSocket.sendSetKeyCommand(t->name, oldKey); // update clients
}
private:
int track;
track_key oldKey, key;
};
class MultiCommand : public Command
{
public:
~MultiCommand()
{
std::list<Command*>::iterator it;
for (it = commands.begin(); it != commands.end(); ++it)
{
delete *it;
}
commands.clear();
}
void addCommand(Command *cmd)
{
commands.push_back(cmd);
}
size_t getSize() const { return commands.size(); }
void exec(SyncDocument *data)
{
std::list<Command*>::iterator it;
for (it = commands.begin(); it != commands.end(); ++it) (*it)->exec(data);
}
void undo(SyncDocument *data)
{
std::list<Command*>::reverse_iterator it;
for (it = commands.rbegin(); it != commands.rend(); ++it) (*it)->undo(data);
}
private:
std::list<Command*> commands;
};
void exec(Command *cmd)
{
undoStack.push(cmd);
cmd->exec(this);
clearRedoStack();
if (savePointDelta < 0) savePointUnreachable = true;
savePointDelta++;
}
bool undo()
{
if (undoStack.size() == 0) return false;
Command *cmd = undoStack.top();
undoStack.pop();
redoStack.push(cmd);
cmd->undo(this);
savePointDelta--;
return true;
}
bool redo()
{
if (redoStack.size() == 0) return false;
Command *cmd = redoStack.top();
redoStack.pop();
undoStack.push(cmd);
cmd->exec(this);
savePointDelta++;
return true;
}
void clearUndoStack()
{
while (!undoStack.empty())
{
Command *cmd = undoStack.top();
undoStack.pop();
delete cmd;
}
}
void clearRedoStack()
{
while (!redoStack.empty())
{
Command *cmd = redoStack.top();
redoStack.pop();
delete cmd;
}
}
Command *getSetKeyFrameCommand(int track, const track_key &key)
{
sync_track *t = tracks[track];
SyncDocument::Command *cmd;
if (is_key_frame(t, key.row)) cmd = new EditCommand(track, key);
else cmd = new InsertCommand(track, key);
return cmd;
Q_ASSERT(index >= 0 && index < tracks.size());
return tracks[index];
}
size_t getTrackOrderCount() const
const SyncTrack *getTrack(int index) const
{
return trackOrder.size();
}
size_t getTrackIndexFromPos(size_t track) const
{
assert(track < trackOrder.size());
return trackOrder[track];
Q_ASSERT(index >= 0 && index < tracks.size());
return tracks[index];
}
void swapTrackOrder(size_t t1, size_t t2)
SyncTrack *findTrack(const QString &name)
{
assert(t1 < trackOrder.size());
assert(t2 < trackOrder.size());
std::swap(trackOrder[t1], trackOrder[t2]);
for (int i = 0; i < tracks.size(); ++i)
if (name == tracks[i]->name)
return tracks[i];
return NULL;
}
static SyncDocument *load(const std::wstring &fileName);
bool save(const std::wstring &fileName);
bool modified() const
int getTrackCount() const
{
if (savePointUnreachable) return true;
return 0 != savePointDelta;
Q_ASSERT(trackOrder.size() == tracks.size());
return tracks.size();
}
bool isRowBookmark(int row) const
{
return !!rowBookmarks.count(row);
}
void undo() { undoStack.undo(); }
void redo() { undoStack.redo(); }
bool isModified() const { return !undoStack.isClean(); }
bool canUndo () const { return undoStack.canUndo(); }
bool canRedo () const { return undoStack.canRedo(); }
void toggleRowBookmark(int row)
{
if (isRowBookmark(row))
rowBookmarks.erase(row);
else
rowBookmarks.insert(row);
}
void beginMacro(const QString &text) { undoStack.beginMacro(text); }
void setKeyFrame(SyncTrack *track, const SyncTrack::TrackKey &key);
void deleteKeyFrame(SyncTrack *track, int row);
void endMacro() { undoStack.endMacro(); }
ClientSocket clientSocket;
int getTrackIndexFromPos(int track) const;
void swapTrackOrder(int t1, int t2);
size_t getRows() const { return rows; }
void setRows(size_t rows) { this->rows = rows; }
static SyncDocument *load(const QString &fileName);
bool save(const QString &fileName);
std::wstring fileName;
bool isRowBookmark(int row) const;
void toggleRowBookmark(int row);
int nextRowBookmark(int row) const
{
std::set<int>::const_iterator it = rowBookmarks.upper_bound(row);
if (it == rowBookmarks.end())
return -1;
return *it;
}
int getRows() const { return rows; }
void setRows(int rows) { this->rows = rows; }
int prevRowBookmark(int row) const
{
std::set<int>::const_iterator it = rowBookmarks.lower_bound(row);
if (it == rowBookmarks.end()) {
std::set<int>::const_reverse_iterator it = rowBookmarks.rbegin();
if (it == rowBookmarks.rend())
return -1;
return *it;
} else
it--;
if (it == rowBookmarks.end())
return -1;
return *it;
}
QString fileName;
int nextRowBookmark(int row) const;
int prevRowBookmark(int row) const;
private:
std::set<int> rowBookmarks;
std::vector<size_t> trackOrder;
size_t rows;
QList<SyncTrack*> tracks;
QList<int> rowBookmarks;
QVector<int> trackOrder;
int rows;
// undo / redo functionality
std::stack<Command*> undoStack;
std::stack<Command*> redoStack;
int savePointDelta; // how many undos must be done to get to the last saved state
bool savePointUnreachable; // is the save-point reachable?
QUndoStack undoStack;
signals:
void modifiedChanged(bool modified);
private slots:
void cleanChanged(bool clean) { emit modifiedChanged(!clean); }
};
#endif // !defined(SYNCDOCUMENT_H)

152
editor/synctrack.h Normal file
View File

@ -0,0 +1,152 @@
#ifndef SYNCTRACK_H
#define SYNCTRACK_H
#include <QObject>
#include <QMap>
class SyncTrack : public QObject {
Q_OBJECT
public:
SyncTrack(const QString &name) :
name(name)
{
}
struct TrackKey {
int row;
float value;
enum KeyType {
STEP, /* stay constant */
LINEAR, /* lerp to the next value */
SMOOTH, /* smooth curve to the next value */
RAMP, /* ramp up */
KEY_TYPE_COUNT
} type;
};
void setKey(const TrackKey &key)
{
keys[key.row] = key;
emit keyFrameChanged(*this, key.row);
}
void removeKey(int row)
{
Q_ASSERT(keys.find(row) != keys.end());
keys.remove(row);
emit keyFrameChanged(*this, row);
}
bool isKeyFrame(int row) const
{
QMap<int, TrackKey>::const_iterator it = keys.lowerBound(row);
return it != keys.end() && it.key() == row;
}
TrackKey getKeyFrame(int row) const
{
Q_ASSERT(isKeyFrame(row));
QMap<int, TrackKey>::const_iterator it = keys.lowerBound(row);
return it.value();
}
const TrackKey *getPrevKeyFrame(int row) const
{
QMap<int, TrackKey>::const_iterator it = keys.lowerBound(row);
if (it != keys.constBegin() && (it == keys.constEnd() || it.key() != row))
--it;
if (it == keys.constEnd() || it.key() > row)
return NULL;
return &it.value();
}
const TrackKey *getNextKeyFrame(int row) const
{
QMap<int, TrackKey>::const_iterator it = keys.lowerBound(row);
if (it == keys.constEnd() || it.key() < row)
return NULL;
return &it.value();
}
static void getPolynomial(float coeffs[4], const TrackKey *key)
{
coeffs[0] = key->value;
switch (key->type) {
case TrackKey::STEP:
coeffs[1] = coeffs[2] = coeffs[3] = 0.0f;
break;
case TrackKey::LINEAR:
coeffs[1] = 1.0f;
coeffs[2] = coeffs[3] = 0.0f;
break;
case TrackKey::SMOOTH:
coeffs[1] = 0.0f;
coeffs[2] = 3.0f;
coeffs[3] = -2.0f;
break;
case TrackKey::RAMP:
coeffs[1] = coeffs[3] = 0.0f;
coeffs[2] = 1.0f;
break;
default:
Q_ASSERT(0);
coeffs[0] = 0.0f;
coeffs[1] = 0.0f;
coeffs[2] = 0.0f;
coeffs[3] = 0.0f;
}
}
double getValue(int row) const
{
if (!keys.size())
return 0.0;
const TrackKey *prevKey = getPrevKeyFrame(row);
const TrackKey *nextKey = getNextKeyFrame(row);
Q_ASSERT(prevKey != NULL || nextKey != NULL);
if (!prevKey)
return nextKey->value;
if (!nextKey)
return prevKey->value;
if (prevKey == nextKey)
return prevKey->value;
float coeffs[4];
getPolynomial(coeffs, prevKey);
float x = double(row - prevKey->row) /
double(nextKey->row - prevKey->row);
float mag = nextKey->value - prevKey->value;
return coeffs[0] + (coeffs[1] + (coeffs[2] + coeffs[3] * x) * x) * x * mag;
}
const QMap<int, TrackKey> getKeyMap() const
{
return keys;
}
bool isActive() const
{
return receivers(SIGNAL(keyFrameChanged(const SyncTrack &, int))) > 0;
}
QString name;
private:
QMap<int, TrackKey> keys;
signals:
void keyFrameChanged(const SyncTrack &track, int row);
};
#endif // !defined(SYNCTRACK_H)

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,20 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef TRACKVIEW_H
#define TRACKVIEW_H
#pragma once
#include <QAbstractScrollArea>
#include <QPaintEvent>
#include <QKeyEvent>
#include <QPainter>
#include "syncdocument.h"
#include <string>
class QLineEdit;
class SyncDocument;
// custom messages
#define WM_REDO (WM_USER + 0x40 + 3)
#define WM_ROWCHANGED (WM_USER + 0x40 + 4)
#define WM_TRACKCHANGED (WM_USER + 0x40 + 5)
#define WM_CURRVALDIRTY (WM_USER + 0x40 + 6)
class TrackView
class TrackView : public QAbstractScrollArea
{
Q_OBJECT
public:
TrackView();
TrackView(QWidget *parent);
~TrackView();
HWND create(HINSTANCE hInstance, HWND hwndParent);
HWND getWin() const { return hwnd; }
void setDocument(SyncDocument *document)
{
@ -30,184 +24,157 @@ public:
const SyncDocument *getDocument() const { return document; }
SyncDocument *getDocument() { return document; }
void setRows(size_t rows);
size_t getRows() const
{
const SyncDocument *doc = getDocument();
if (!doc)
return 0;
return doc->getRows();
}
void setFont(HFONT font);
void setRows(int rows);
int getRows() const;
void editEnterValue();
void editDelete();
void editCopy();
void editCut();
void editPaste();
void editBiasValue(float amount);
void editToggleInterpolationType();
void setEditRow(int newEditRow);
void setEditRow(int newEditRow, bool selecting = false);
int getEditRow() const { return editRow; }
void setEditTrack(int newEditTrack, bool autoscroll = true);
void setEditTrack(int newEditTrack, bool autoscroll = true, bool selecting = false);
int getEditTrack() const { return editTrack; }
void selectAll()
{
selectStartTrack = int(this->getTrackCount()) - 1;
selectStopTrack = editTrack = 0;
selectStartRow = int(this->getRows()) - 1;
selectStopRow = editRow = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectTrack(int track)
{
selectStartTrack = selectStopTrack = editTrack = track;
selectStartRow = int(this->getRows()) - 1;
selectStopRow = editRow = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectRow(int row)
{
selectStartTrack = int(this->getTrackCount()) - 1;
selectStopTrack = editTrack = 0;
selectStartRow = selectStopRow = editRow = row;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectNone()
{
selectStartTrack = selectStopTrack = editTrack;
selectStartRow = selectStopRow = editRow;
InvalidateRect(hwnd, NULL, FALSE);
update();
}
private:
// some nasty hackery to forward the window messages
friend LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// events
LRESULT onCreate();
LRESULT onPaint();
LRESULT onVScroll(UINT sbCode, int newPos);
LRESULT onHScroll(UINT sbCode, int newPos);
LRESULT onSize(int width, int height);
LRESULT onKeyDown(UINT keyCode, UINT flags);
LRESULT onChar(UINT keyCode, UINT flags);
LRESULT onSetCursor(HWND win, UINT hitTest, UINT message);
LRESULT onLButtonDown(UINT flags, POINTS pos);
LRESULT onLButtonUp(UINT flags, POINTS pos);
LRESULT onMouseMove(UINT flags, POINTS pos);
void paintTracks(HDC hdc, RECT rcTracks);
void paintTopMargin(HDC hdc, RECT rcTracks);
void dirtyCurrentValue()
{
emit currValDirty();
}
void dirtyPosition()
{
emit posChanged(editTrack, editRow);
}
bool paused, connected;
signals:
void posChanged(int col, int row);
void pauseChanged(bool paused);
void currValDirty();
private slots:
void onHScroll(int value);
void onVScroll(int value);
void onEditingFinished();
public slots:
void editUndo();
void editRedo();
void editCopy();
void editCut();
void editPaste();
void editClear();
void selectAll();
void selectTrack();
void selectRow();
private:
/* paint helpers */
void paintTopMargin(QPainter &painter, const QRect &rcTracks);
void paintLeftMargin(QPainter &painter, const QRect &rcTracks);
void paintTracks(QPainter &painter, const QRect &rcTracks);
void paintTrack(QPainter &painter, const QRect &rcTracks, int track);
void paintEvent(QPaintEvent *);
void keyPressEvent(QKeyEvent *);
void resizeEvent(QResizeEvent *);
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void changeEvent(QEvent *);
void setupScrollBars();
void setScrollPos(int newScrollPosX, int newScrollPosY);
void scrollWindow(int newScrollPosX, int newScrollPosY);
void invalidateRange(int startTrack, int stopTrack, int startRow, int stopRow)
{
RECT rect;
rect.left = getScreenX(std::min(startTrack, stopTrack));
rect.right = getScreenX(std::max(startTrack, stopTrack) + 1);
rect.top = getScreenY(std::min(startRow, stopRow));
rect.bottom = getScreenY(std::max(startRow, stopRow) + 1);
InvalidateRect(hwnd, &rect, FALSE);
QRect rect(QPoint(getPhysicalX(qMin(startTrack, stopTrack)),
getPhysicalY(qMin(startRow, stopRow))),
QPoint(getPhysicalX(qMax(startTrack, stopTrack) + 1) - 1,
getPhysicalY(qMax(startRow, stopRow) + 1) - 1));
viewport()->update(rect);
}
void invalidatePos(int track, int row)
{
RECT rect;
rect.left = getScreenX(track);
rect.right = getScreenX(track + 1);
rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, FALSE);
invalidateRange(track, track, row, row);
}
void invalidateRow(int row)
{
RECT clientRect;
GetClientRect(hwnd, &clientRect);
RECT rect;
rect.left = clientRect.left;
rect.right = clientRect.right;
rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, FALSE);
invalidateRange(0, getTrackCount(), row, row);
}
void invalidateTrack(int track)
{
RECT clientRect;
GetClientRect(hwnd, &clientRect);
RECT rect;
rect.left = getScreenX(track);
rect.right = getScreenX(track + 1);
rect.top = clientRect.top;
rect.bottom = clientRect.bottom;
InvalidateRect(hwnd, &rect, FALSE);
invalidateRange(track, track, 0, getRows());
}
int getScreenY(int row) const;
int getScreenX(size_t track) const;
int getTrackFromX(int x) const;
size_t getTrackCount() const
void invalidateAll()
{
const SyncDocument *doc = getDocument();
if (NULL == doc) return 0;
return int(doc->getTrackOrderCount());
};
invalidateRange(0, getTrackCount(), 0, getRows());
}
QRect getSelection() const
{
return QRect(QPoint(qMin(selectStartTrack, selectStopTrack),
qMin(selectStartRow, selectStopRow)),
QPoint(qMax(selectStartTrack, selectStopTrack),
qMax(selectStartRow, selectStopRow)));
}
int getLogicalX(int track) const;
int getLogicalY(int row) const;
int getPhysicalX(int track) const;
int getPhysicalY(int row) const;
int getTrackFromLogicalX(int x) const;
int getTrackFromPhysicalX(int x) const;
int getTrackCount() const;
int selectStartTrack, selectStopTrack;
int selectStartRow, selectStopRow;
HFONT font;
int rowHeight;
int fontWidth;
int trackWidth;
int topMarginHeight;
int leftMarginWidth;
void updateFont();
QBrush bgBaseBrush, bgDarkBrush;
QBrush selectBaseBrush, selectDarkBrush;
QPen rowPen, rowSelectPen;
QBrush editBrush, bookmarkBrush;
QPen lerpPen, cosinePen, rampPen;
QCursor handCursor;
void updatePalette();
HBRUSH bgBaseBrush, bgDarkBrush;
HBRUSH selectBaseBrush, selectDarkBrush;
HPEN rowPen, rowSelectPen;
HBRUSH editBrush, bookmarkBrush;
HPEN lerpPen, cosinePen, rampPen;
HCURSOR handCursor;
/* cursor position */
int editRow, editTrack;
int scrollPosX, scrollPosY;
int windowWidth, windowHeight;
int windowRows, windowTracks;
int windowRows;
SyncDocument *document;
std::string editString;
HWND hwnd;
UINT clipboardFormat;
QLineEdit *lineEdit;
bool dragging;
int anchorTrack;
};
ATOM registerTrackViewWindowClass(HINSTANCE hInstance);
#endif // !defined(TRACKVIEW_H)

View File

@ -1,21 +1,24 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
* sdl+opengl examle by rasmus/loonies http://visualizethis.tumblr.com 2011
*/
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <SDL.h>
#ifdef WIN32
#undef main /* avoid SDL's nasty SDLmain hack */
#endif
#include <SDL_opengl.h>
#include <bass.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "../sync/sync.h"
#if defined(__APPLE__) && defined(__MACH__)
#include <GLKit/GLKMatrix4.h>
#define gluPerspective(f, a, zn, zf) glMultMatrixf(GLKMatrix4MakePerspective((f) * M_PI / 180, a, zn, zf).m)
#define gluLookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz) glMultMatrixf(GLKMatrix4MakeLookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz).m)
#endif
#include "../lib/sync.h"
static const float bpm = 150.0f; /* beats per minute */
static const int rpb = 8; /* rows per beat */
@ -80,7 +83,7 @@ static void die(const char *fmt, ...)
static const unsigned int width = 800;
static const unsigned int height = 600;
SDL_Surface *setup_sdl()
void setup_sdl()
{
if (SDL_Init(SDL_INIT_VIDEO))
die("%s", SDL_GetError());
@ -93,7 +96,8 @@ SDL_Surface *setup_sdl()
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
return SDL_SetVideoMode(width, height, 32, SDL_OPENGL);
if (!SDL_SetVideoMode(width, height, 32, SDL_OPENGL))
die("%s", SDL_GetError());
}
void draw_cube()
@ -147,13 +151,12 @@ void draw_cube()
int main(int argc, char *argv[])
{
SDL_Surface *screen;
HSTREAM stream;
const struct sync_track *clear_r, *clear_g, *clear_b;
const struct sync_track *cam_rot, *cam_dist;
screen = setup_sdl();
setup_sdl();
/* init BASS */
if (!BASS_Init(-1, 44100, 0, 0, 0))
@ -193,13 +196,13 @@ int main(int argc, char *argv[])
/* draw */
glClearColor(sync_get_val(clear_r, row),
sync_get_val(clear_g, row),
sync_get_val(clear_b, row), 1.0f);
glClearColor(float(sync_get_val(clear_r, row)),
float(sync_get_val(clear_g, row)),
float(sync_get_val(clear_b, row)), 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float rot = sync_get_val(cam_rot, row);
float dist = sync_get_val(cam_dist, row);
float rot = float(sync_get_val(cam_rot, row));
float dist = float(sync_get_val(cam_dist, row));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

View File

@ -0,0 +1,361 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug Client|Win32">
<Configuration>Debug Client</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug Client|x64">
<Configuration>Debug Client</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Client|Win32">
<Configuration>Release Client</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Client|x64">
<Configuration>Release Client</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}</ProjectGuid>
<RootNamespace>example_bass</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>example_bass</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.30501.0</_ProjectFileVersion>
<NuGetPackageImportStamp>db1c9e5e</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<GenerateManifest>false</GenerateManifest>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DataExecutionPrevention />
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;bass.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DataExecutionPrevention />
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="example_bass.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\librocket.vs2013.vcxproj">
<Project>{5866042c-7fcb-4db1-baad-44df6567511f}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\SDL.redist.1.2.15.16\build\native\SDL.redist.targets" Condition="Exists('..\packages\SDL.redist.1.2.15.16\build\native\SDL.redist.targets')" />
<Import Project="..\packages\SDL.1.2.15.16\build\native\SDL.targets" Condition="Exists('..\packages\SDL.1.2.15.16\build\native\SDL.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\SDL.redist.1.2.15.16\build\native\SDL.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SDL.redist.1.2.15.16\build\native\SDL.redist.targets'))" />
<Error Condition="!Exists('..\packages\SDL.1.2.15.16\build\native\SDL.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SDL.1.2.15.16\build\native\SDL.targets'))" />
</Target>
</Project>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="example_bass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SDL" version="1.2.15.16" targetFramework="Native" />
<package id="SDL.redist" version="1.2.15.16" targetFramework="Native" />
</packages>

View File

@ -1,12 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_bass", "example_bass\example_bass.vcproj", "{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_bass", "example_bass\example_bass.vs2008.vcproj", "{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}"
ProjectSection(ProjectDependencies) = postProject
{5866042C-7FCB-4DB1-BAAD-44DF6567511F} = {5866042C-7FCB-4DB1-BAAD-44DF6567511F}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sync_player", "sync_player.vcproj", "{5866042C-7FCB-4DB1-BAAD-44DF6567511F}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librocket", "lib/librocket.vs2008.vcproj", "{5866042C-7FCB-4DB1-BAAD-44DF6567511F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

58
examples.vs2013.sln Normal file
View File

@ -0,0 +1,58 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_bass", "example_bass\example_bass.vs2013.vcxproj", "{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librocket", "lib\librocket.vs2013.vcxproj", "{5866042C-7FCB-4DB1-BAAD-44DF6567511F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Client|Win32 = Debug Client|Win32
Debug Client|x64 = Debug Client|x64
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release Client|Win32 = Release Client|Win32
Release Client|x64 = Release Client|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|Win32.ActiveCfg = Debug Client|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|Win32.Build.0 = Debug Client|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|x64.ActiveCfg = Debug Client|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug Client|x64.Build.0 = Debug Client|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|Win32.ActiveCfg = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|Win32.Build.0 = Debug|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|x64.ActiveCfg = Debug|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Debug|x64.Build.0 = Debug|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|Win32.ActiveCfg = Release Client|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|Win32.Build.0 = Release Client|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|x64.ActiveCfg = Release Client|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release Client|x64.Build.0 = Release Client|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|Win32.ActiveCfg = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|Win32.Build.0 = Release|Win32
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|x64.ActiveCfg = Release|x64
{96D91AAD-2F45-4CC6-A923-96B80E1C3CE3}.Release|x64.Build.0 = Release|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|Win32.ActiveCfg = Debug Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|Win32.Build.0 = Debug Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|x64.ActiveCfg = Debug Client|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug Client|x64.Build.0 = Debug Client|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug|Win32.ActiveCfg = Debug|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug|Win32.Build.0 = Debug|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug|x64.ActiveCfg = Debug|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Debug|x64.Build.0 = Debug|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release Client|Win32.ActiveCfg = Release Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release Client|Win32.Build.0 = Release Client|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release Client|x64.ActiveCfg = Release Client|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release Client|x64.Build.0 = Release Client|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release|Win32.ActiveCfg = Release|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release|Win32.Build.0 = Release|Win32
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release|x64.ActiveCfg = Release|x64
{5866042C-7FCB-4DB1-BAAD-44DF6567511F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

35
lib/base.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef SYNC_BASE_H
#define SYNC_BASE_H
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stddef.h>
/* configure inline keyword */
#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) && !defined(__cplusplus)
#if defined(_MSC_VER) || defined(__GNUC__) || defined(__SASC)
#define inline __inline
#else
/* compiler does not support inline */
#define inline
#endif
#endif
/* configure lacking CRT features */
#ifdef _MSC_VER
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
/* int is 32-bit for both x86 and x64 */
typedef unsigned int uint32_t;
#define UINT32_MAX UINT_MAX
#elif defined(__GNUC__)
#include <stdint.h>
#elif defined(M68000)
typedef unsigned int uint32_t;
#endif
#endif /* SYNC_BASE_H */

View File

@ -1,11 +1,18 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#include "device.h"
#include "sync.h"
#include "track.h"
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
static int find_track(struct sync_device *d, const char *name)
{
int i;
for (i = 0; i < (int)d->num_tracks; ++i)
if (!strcmp(name, d->tracks[i]->name))
return i;
return -1; /* not found */
}
static const char *sync_track_path(const char *base, const char *name)
{
@ -20,16 +27,70 @@ static const char *sync_track_path(const char *base, const char *name)
#ifndef SYNC_PLAYER
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"
enum {
SET_KEY = 0,
DELETE_KEY = 1,
GET_TRACK = 2,
SET_ROW = 3,
PAUSE = 4,
SAVE_TRACKS = 5
};
static inline int socket_poll(SOCKET socket)
{
struct timeval to = { 0, 0 };
fd_set fds;
FD_ZERO(&fds);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
FD_SET(socket, &fds);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
return select((int)socket + 1, &fds, NULL, NULL, &to) > 0;
}
static inline int xsend(SOCKET s, const void *buf, size_t len, int flags)
{
#ifdef WIN32
assert(len <= INT_MAX);
return send(s, (const char *)buf, (int)len, flags) != (int)len;
#else
return send(s, (const char *)buf, len, flags) != (int)len;
#endif
}
static inline int xrecv(SOCKET s, void *buf, size_t len, int flags)
{
#ifdef WIN32
assert(len <= INT_MAX);
return recv(s, (char *)buf, (int)len, flags) != (int)len;
#else
return recv(s, (char *)buf, len, flags) != (int)len;
#endif
}
#ifdef USE_AMITCP
static struct Library *socket_base = NULL;
#endif
static SOCKET server_connect(const char *host, unsigned short nport)
{
#ifdef USE_GETADDRINFO
struct addrinfo *addr;
char port[6];
#else
struct hostent *he;
struct sockaddr_in sa;
char greet[128], **ap;
SOCKET sock = INVALID_SOCKET;
char **ap;
#endif
#ifdef WIN32
static int need_init = 1;
@ -47,37 +108,58 @@ static SOCKET server_connect(const char *host, unsigned short nport)
}
#endif
#ifdef USE_GETADDRINFO
snprintf(port, sizeof(port), "%u", nport);
if (getaddrinfo(host, port, 0, &addr) != 0)
return INVALID_SOCKET;
for (; addr; addr = addr->ai_next) {
SOCKET sock;
int family = addr->ai_family;
struct sockaddr *sa = addr->ai_addr;
int sa_len = (int) addr->ai_addrlen; /* elim. warning on (at least) Win/x64, size_t vs. int/socklen_t */
#else
he = gethostbyname(host);
if (!he)
return INVALID_SOCKET;
for (ap = he->h_addr_list; *ap; ++ap) {
sa.sin_family = he->h_addrtype;
sa.sin_port = htons(nport);
memcpy(&sa.sin_addr, *ap, he->h_length);
SOCKET sock;
int family = he->h_addrtype;
struct sockaddr_in sin;
struct sockaddr *sa = (struct sockaddr *)&sin;
int sa_len = sizeof(*sa);
sock = socket(he->h_addrtype, SOCK_STREAM, 0);
sin.sin_family = he->h_addrtype;
sin.sin_port = htons(nport);
memcpy(&sin.sin_addr, *ap, he->h_length);
memset(&sin.sin_zero, 0, sizeof(sin.sin_zero));
#endif
sock = socket(family, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
continue;
if (connect(sock, (struct sockaddr *)&sa, sizeof(sa)) >= 0)
break;
if (connect(sock, sa, sa_len) >= 0) {
char greet[128];
if (xsend(sock, CLIENT_GREET, strlen(CLIENT_GREET), 0) ||
xrecv(sock, greet, strlen(SERVER_GREET), 0)) {
closesocket(sock);
continue;
}
if (!strncmp(SERVER_GREET, greet, strlen(SERVER_GREET)))
return sock;
}
closesocket(sock);
sock = INVALID_SOCKET;
}
if (sock == INVALID_SOCKET)
return INVALID_SOCKET;
if (xsend(sock, CLIENT_GREET, strlen(CLIENT_GREET), 0) ||
xrecv(sock, greet, strlen(SERVER_GREET), 0))
return INVALID_SOCKET;
if (!strncmp(SERVER_GREET, greet, strlen(SERVER_GREET)))
return sock;
closesocket(sock);
return INVALID_SOCKET;
}
@ -92,6 +174,17 @@ void sync_set_io_cb(struct sync_device *d, struct sync_io_cb *cb)
#endif
#ifdef NEED_STRDUP
static inline char *rocket_strdup(const char *str)
{
char *ret = malloc(strlen(str) + 1);
if (ret)
strcpy(ret, str);
return ret;
}
#define strdup rocket_strdup
#endif
struct sync_device *sync_create_device(const char *base)
{
struct sync_device *d = malloc(sizeof(*d));
@ -104,16 +197,16 @@ struct sync_device *sync_create_device(const char *base)
return NULL;
}
d->data.tracks = NULL;
d->data.num_tracks = 0;
d->tracks = NULL;
d->num_tracks = 0;
#ifndef SYNC_PLAYER
d->row = -1;
d->sock = INVALID_SOCKET;
#else
d->io_cb.open = fopen;
d->io_cb.read = fread;
d->io_cb.close = fclose;
d->io_cb.open = (void *(*)(const char *, const char *))fopen;
d->io_cb.read = (size_t (*)(void *, size_t, size_t, void *))fread;
d->io_cb.close = (int (*)(void *))fclose;
#endif
return d;
@ -121,8 +214,14 @@ struct sync_device *sync_create_device(const char *base)
void sync_destroy_device(struct sync_device *d)
{
int i;
for (i = 0; i < (int)d->num_tracks; ++i) {
free(d->tracks[i]->name);
free(d->tracks[i]->keys);
free(d->tracks[i]);
}
free(d->tracks);
free(d->base);
sync_data_deinit(&d->data);
free(d);
#if defined(USE_AMITCP) && !defined(SYNC_PLAYER)
@ -142,7 +241,7 @@ static int get_track_data(struct sync_device *d, struct sync_track *t)
if (!fp)
return -1;
d->io_cb.read(&t->num_keys, sizeof(size_t), 1, fp);
d->io_cb.read(&t->num_keys, sizeof(int), 1, fp);
t->keys = malloc(sizeof(struct track_key) * t->num_keys);
if (!t->keys)
return -1;
@ -150,7 +249,7 @@ static int get_track_data(struct sync_device *d, struct sync_track *t)
for (i = 0; i < (int)t->num_keys; ++i) {
struct track_key *key = t->keys + i;
char type;
d->io_cb.read(&key->row, sizeof(size_t), 1, fp);
d->io_cb.read(&key->row, sizeof(int), 1, fp);
d->io_cb.read(&key->value, sizeof(float), 1, fp);
d->io_cb.read(&type, sizeof(char), 1, fp);
key->type = (enum key_type)type;
@ -169,7 +268,7 @@ static int save_track(const struct sync_track *t, const char *path)
if (!fp)
return -1;
fwrite(&t->num_keys, sizeof(size_t), 1, fp);
fwrite(&t->num_keys, sizeof(int), 1, fp);
for (i = 0; i < (int)t->num_keys; ++i) {
char type = (char)t->keys[i].type;
fwrite(&t->keys[i].row, sizeof(int), 1, fp);
@ -184,8 +283,8 @@ static int save_track(const struct sync_track *t, const char *path)
void sync_save_tracks(const struct sync_device *d)
{
int i;
for (i = 0; i < (int)d->data.num_tracks; ++i) {
const struct sync_track *t = d->data.tracks[i];
for (i = 0; i < (int)d->num_tracks; ++i) {
const struct sync_track *t = d->tracks[i];
save_track(t, sync_track_path(d->base, t->name));
}
}
@ -211,7 +310,7 @@ static int get_track_data(struct sync_device *d, struct sync_track *t)
return 0;
}
static int handle_set_key_cmd(SOCKET sock, struct sync_data *data)
static int handle_set_key_cmd(SOCKET sock, struct sync_device *data)
{
uint32_t track, row;
union {
@ -239,7 +338,7 @@ static int handle_set_key_cmd(SOCKET sock, struct sync_data *data)
return sync_set_key(data->tracks[track], &key);
}
static int handle_del_key_cmd(SOCKET sock, struct sync_data *data)
static int handle_del_key_cmd(SOCKET sock, struct sync_device *data)
{
uint32_t track, row;
@ -264,14 +363,14 @@ int sync_connect(struct sync_device *d, const char *host, unsigned short port)
if (d->sock == INVALID_SOCKET)
return -1;
for (i = 0; i < (int)d->data.num_tracks; ++i) {
free(d->data.tracks[i]->keys);
d->data.tracks[i]->keys = NULL;
d->data.tracks[i]->num_keys = 0;
for (i = 0; i < (int)d->num_tracks; ++i) {
free(d->tracks[i]->keys);
d->tracks[i]->keys = NULL;
d->tracks[i]->num_keys = 0;
}
for (i = 0; i < (int)d->data.num_tracks; ++i) {
if (get_track_data(d, d->data.tracks[i])) {
for (i = 0; i < (int)d->num_tracks; ++i) {
if (get_track_data(d, d->tracks[i])) {
closesocket(d->sock);
d->sock = INVALID_SOCKET;
return -1;
@ -295,11 +394,11 @@ int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
switch (cmd) {
case SET_KEY:
if (handle_set_key_cmd(d->sock, &d->data))
if (handle_set_key_cmd(d->sock, d))
goto sockerr;
break;
case DELETE_KEY:
if (handle_del_key_cmd(d->sock, &d->data))
if (handle_del_key_cmd(d->sock, d))
goto sockerr;
break;
case SET_ROW:
@ -343,16 +442,33 @@ sockerr:
#endif
static int create_track(struct sync_device *d, const char *name)
{
struct sync_track *t;
assert(find_track(d, name) < 0);
t = malloc(sizeof(*t));
t->name = strdup(name);
t->keys = NULL;
t->num_keys = 0;
d->num_tracks++;
d->tracks = realloc(d->tracks, sizeof(d->tracks[0]) * d->num_tracks);
d->tracks[d->num_tracks - 1] = t;
return (int)d->num_tracks - 1;
}
const struct sync_track *sync_get_track(struct sync_device *d,
const char *name)
{
struct sync_track *t;
int idx = sync_find_track(&d->data, name);
int idx = find_track(d, name);
if (idx >= 0)
return d->data.tracks[idx];
return d->tracks[idx];
idx = sync_create_track(&d->data, name);
t = d->data.tracks[idx];
idx = create_track(d, name);
t = d->tracks[idx];
get_track_data(d, t);
return t;

55
lib/device.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef SYNC_DEVICE_H
#define SYNC_DEVICE_H
#include "base.h"
#include "sync.h"
#ifndef SYNC_PLAYER
/* configure socket-stack */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define USE_GETADDRINFO
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <limits.h>
#elif defined(USE_AMITCP)
#include <sys/socket.h>
#include <proto/exec.h>
#include <proto/socket.h>
#include <netdb.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
#define closesocket(x) CloseSocket(x)
#else
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket(x) close(x)
#endif
#endif /* !defined(SYNC_PLAYER) */
struct sync_device {
char *base;
struct sync_track **tracks;
size_t num_tracks;
#ifndef SYNC_PLAYER
int row;
SOCKET sock;
#else
struct sync_io_cb io_cb;
#endif
};
#endif /* SYNC_DEVICE_H */

View File

@ -2,9 +2,9 @@
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="sync_player"
Name="librocket"
ProjectGUID="{5866042C-7FCB-4DB1-BAAD-44DF6567511F}"
RootNamespace="sync_player"
RootNamespace="librocket"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
@ -21,7 +21,7 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(SolutionDir)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2"
@ -44,7 +44,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;SYNC_PLAYER"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SYNC_PLAYER"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@ -63,6 +63,7 @@
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\$(ProjectName)-playerd.lib"
/>
<Tool
Name="VCALinkTool"
@ -82,7 +83,7 @@
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(SolutionDir)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2"
@ -105,7 +106,7 @@
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;SYNC_PLAYER"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SYNC_PLAYER"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
@ -122,6 +123,7 @@
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\$(ProjectName)-player.lib"
/>
<Tool
Name="VCALinkTool"
@ -141,7 +143,7 @@
</Configuration>
<Configuration
Name="Debug Client|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(SolutionDir)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2"
@ -164,7 +166,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@ -184,6 +186,7 @@
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="ws2_32.lib"
OutputFile="$(OutDir)\$(ProjectName)d.lib"
/>
<Tool
Name="VCALinkTool"
@ -203,7 +206,7 @@
</Configuration>
<Configuration
Name="Release Client|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
OutputDirectory="$(SolutionDir)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="2"
@ -226,7 +229,7 @@
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
@ -287,7 +290,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;SYNC_PLAYER"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SYNC_PLAYER"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@ -350,7 +353,7 @@
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;SYNC_PLAYER"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SYNC_PLAYER"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
@ -411,7 +414,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@ -475,7 +478,7 @@
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
@ -520,15 +523,11 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\sync\data.c"
RelativePath=".\device.c"
>
</File>
<File
RelativePath=".\sync\device.c"
>
</File>
<File
RelativePath=".\sync\track.c"
RelativePath=".\track.c"
>
</File>
</Filter>
@ -538,23 +537,19 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\sync\base.h"
RelativePath=".\base.h"
>
</File>
<File
RelativePath=".\sync\data.h"
RelativePath=".\device.h"
>
</File>
<File
RelativePath=".\sync\device.h"
RelativePath=".\sync.h"
>
</File>
<File
RelativePath=".\sync\sync.h"
>
</File>
<File
RelativePath=".\sync\track.h"
RelativePath=".\track.h"
>
</File>
</Filter>

View File

@ -0,0 +1,292 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug Client|Win32">
<Configuration>Debug Client</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug Client|x64">
<Configuration>Debug Client</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Client|Win32">
<Configuration>Release Client</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release Client|x64">
<Configuration>Release Client</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5866042C-7FCB-4DB1-BAAD-44DF6567511F}</ProjectGuid>
<RootNamespace>librocket</RootNamespace>
<Keyword>Win32Proj</Keyword>
<ProjectName>librocket</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.30501.0</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)lib\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<TargetName>$(ProjectName)-playerd</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)lib\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<TargetName>$(ProjectName)-player</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'">
<OutDir>$(SolutionDir)lib\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<TargetName>$(ProjectName)d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'">
<OutDir>$(SolutionDir)lib\</OutDir>
<IntDir>$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)-playerd</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)-player</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName)-playerd.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName)-player.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName)d.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName)-playerd.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;SYNC_PLAYER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName)-player.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Client|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName)d.lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Client|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="device.c" />
<ClCompile Include="track.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="base.h" />
<ClInclude Include="device.h" />
<ClInclude Include="sync.h" />
<ClInclude Include="track.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="device.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="track.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="base.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="device.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="sync.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="track.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Erik Faye-Lund and Egbert Teeselink
/* Copyright (C) 2010 Contributors
* For conditions of distribution and use, see copyright notice in COPYING
*/
@ -9,6 +9,8 @@
extern "C" {
#endif
#include <stddef.h>
struct sync_device;
struct sync_track;

View File

@ -1,7 +1,3 @@
/* Copyright (C) 2010 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#include <stdlib.h>
#include <assert.h>
#include <math.h>

View File

@ -1,7 +1,3 @@
/* Copyright (C) 2007-2010 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef SYNC_TRACK_H
#define SYNC_TRACK_H

117
ogl_editor/CMakeLists.txt Normal file
View File

@ -0,0 +1,117 @@
set(CMAKE_OSX_ARCHITECTURES x86_64)
project(RocketEditor)
cmake_minimum_required(VERSION 2.8)
set(RKT_EXE_NAME "RocketEditor")
set(VERSION_MAJOR "1")
set(VERSION_MINOR "1")
set(VERSION_PATCH "0")
if(APPLE)
add_definitions(-DMACOSX)
add_definitions(-DEMGUI_MACOSX)
add_compile_options(-Wall)
add_compile_options(-Wno-format-security)
add_compile_options(-Wno-deprecated-declarations)
endif()
##############################################################################
# MXML
file(GLOB MXML_SRCS
external/mxml/*.c
)
add_library(mxml ${MXML_SRCS})
target_include_directories(mxml PUBLIC external/mxml)
target_compile_definitions(mxml PUBLIC _THREAD_SAFE _REENTRANT)
##############################################################################
# SYNC
file(GLOB SYNC_SRCS
../lib/*.c
)
add_library(sync ${SYNC_SRCS})
target_include_directories(sync PUBLIC ../lib)
##############################################################################
# EMGUI
file(GLOB_RECURSE EMGUI_SRCS
emgui/src/*.c
emgui/src/*.h
)
add_library(emgui ${EMGUI_SRCS})
target_include_directories(emgui PUBLIC emgui/src emgui/include)
target_compile_definitions(emgui PUBLIC _THREAD_SAFE _REENTRANT)
target_compile_options(emgui PUBLIC -Werror -pedantic-errors)
##############################################################################
# EDITOR
file(GLOB PROJECT_SRCS
src/*.c
src/*.m
src/*.h
)
if (APPLE)
file(GLOB PROJECT_PLATFORM_SRCS
src/macosx/*.c
src/macosx/*.m
src/macosx/*.h
)
endif()
file(GLOB RESOURCES_DATA
data/macosx/icon.icns
)
source_group("Data" FILES ${RESOURCES_DATA})
if (APPLE)
set(GUI_TYPE MACOSX_BUNDLE)
find_library(COCOA_FRAMEWORK Cocoa)
find_library(OPENGL_FRAMEWORK OpenGL)
find_library(CARBON_FRAMEWORK Carbon)
mark_as_advanced(COCOA_FRAMEWORK OPENGL_FRAMEWORK CARBON_FRAMEWORK)
set(PLATFORM_LIBS ${COCOA_FRAMEWORK} ${OPENGL_FRAMEWORK} ${CARBON_FRAMEWORK})
# Define some settings for the Bundle
set(MACOSX_BUNDLE_BUNDLE_NAME ${RKT_EXE_NAME})
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.tbl.rocketeditor")
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
set(MACOSX_BUNDLE_INFO_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH},Copyright © 2016 GNU Rocket Contributors")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2012-2016 GNU Rocket Contributors. All rights reserved.")
set_source_files_properties(${RESOURCES_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set(PROJECT_SRCS ${GUI_TYPE} ${PROJECT_SRCS} ${RESOURCES_DATA})
endif (APPLE)
add_executable(${RKT_EXE_NAME} ${PROJECT_SRCS} ${PROJECT_PLATFORM_SRCS} data/macosx/appnib.xib)
if (APPLE)
set_target_properties(${RKT_EXE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/data/macosx/MacOSXBundleInfo.plist.in)
endif ()
target_include_directories(${RKT_EXE_NAME} PUBLIC . src emgui/include external/mxml)
target_compile_options(${RKT_EXE_NAME} PUBLIC -Werror -pedantic-errors)
target_link_libraries(${RKT_EXE_NAME} sync mxml emgui ${PLATFORM_LIBS})
# compile the nibs
if (APPLE)
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
if (${IBTOOL} STREQUAL "IBTOOL-NOTFOUND")
message(SEND_ERROR "ibtool can not be found and is needed to compile the .xib files. It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
endif()
# Make sure the 'Resources' Directory is correctly created before we build
#add_custom_command (TARGET ${RKT_EXE_NAME} PRE_BUILD COMMAND echo ${CMAKE_BINARY_DIR}/\${CONFIGURATION}/${RKT_EXE_NAME}.app/Contents/Resources/appnib.nib)
# Compile the .xib files using the 'ibtool' program with the destination being the app package
add_custom_command (TARGET ${RKT_EXE_NAME} POST_BUILD
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text
--compile ${CMAKE_BINARY_DIR}/\${CONFIGURATION}/${RKT_EXE_NAME}.app/Contents/Resources/appnib.nib
${CMAKE_CURRENT_SOURCE_DIR}/data/macosx/appnib.xib
COMMENT "Compiling appnib.xib")
endif (APPLE)

View File

@ -1,9 +1,13 @@
Beta Disclaimar
GNU Rocket OpenGL editor
========================
Beta Disclaimer
---------------
First a screenshot of how it looks: https://dl.dropbox.com/u/5205843/RocketEditor.png
First a screenshot of how it looks:
![Rocket Opengl editor screenshot](https://dl.dropbox.com/u/5205843/RocketEditor.png)
Regular disclaimar: Backup your stuff before using software :)
Regular disclaimer: Backup your stuff before using software :)
If you encounter any issues please try to report them at https://github.com/emoon/rocket/issues as
this would make my life much easier and I will try to fix them given time. Hopefully the editor should be useful even if still not 100% finalized bug wise.
@ -11,8 +15,8 @@ Also the documentation hasn't been completed yet.
Here are the links to the current version of the editor:
Mac: https://dl.dropbox.com/u/5205843/RocketEditor1.1Beta1.zip
Windows: https://dl.dropbox.com/u/5205843/RocketEditor1.1Beta-win32.zip
* Mac: https://dl.dropbox.com/u/5205843/RocketEditor1.1Beta1.zip
* Windows: https://dl.dropbox.com/u/5205843/RocketEditor1.1Beta-win32.zip
About
-----
@ -20,7 +24,7 @@ About
RocketEditor is coded by Daniel 'emoon' Collin with documentation and testing by Heine 'bstrr' Gundersen.
Daniel Collin can be contacted at daniel aat collin dot com
Latest version of this program should be availible at https://github.com/emoon/rocket
Latest version of this program should be available at https://github.com/emoon/rocket
The SDL-based linux support is written by Konsta 'sooda' Hölttä at https://github.com/sooda/rocket
@ -59,8 +63,8 @@ Building the code
All Mac, Windows and Linux versions use the Tundra build system (https://github.com/deplinenoise/tundra) so in order to build the code you need a tundra executable for your OS
I have made two of the available here for your convenience if you don't want to build the code yourself.
Mac: https://dl.dropbox.com/u/5205843/tundra-mac.zip
Windows: https://dl.dropbox.com/u/5205843/tundra-win.zip
* Mac: https://dl.dropbox.com/u/5205843/tundra-mac.zip
* Windows: https://dl.dropbox.com/u/5205843/tundra-win.zip
Mac
---
@ -102,85 +106,103 @@ Tips & tricks
Keys
----
OSX:
### OSX:
Editing:
0-9 - Edit value
Esc - Cancel edit
QWERTY - Bias selection +0.01, +0.1, +1, +10, +100, +1000
ASDFGH - Bias selection -0.01, -0.1, -1, -10, -100, -1000
Alt+Trackpad scroll - Bias selection +1/-1
Shift+Alt+Trackpad - Bias selection +10/-10
I - Toggle interpolation (step/linear/smooth/ramp)
Return - Insert current interpolated value
Shift+Arrows - Select
Cmd+T - Select all keys in track
Cmd+X - Cut
Cmd+C - Copy
Cmd+V - Paste
Cmd+Z - Undo
Cmd+Shift+Z - Redo
Delete - Delete key
#### Editing:
View:
Space - Start/Stop
Arrows - Move cursor around
Alt+Up/Down - Jump 8 rows
Alt+Cmd+Up/Down - Jump to StartRow/NextBookmark - PrevBookmark/EndRow
Cmd+Left/Right - Jump to first/last track
Ctrl+Up/Down - Jump to Previous/Next key in current track
Alt+Left/Right - Fold/Unfold track
Ctrl+Alt+Left/Right - Fold/Unfold group
Trackpad scroll - Scroll
B - Toggle Bookmark
Cmd+B - Clear all Bookmarks
Tab - Jump between Row, Start Row, End Row, Track editing
Key | Action
--- | ---
0-9 | Edit value
Esc | Cancel edit
QWERTY | Bias selection +0.01, +0.1, +1, +10, +100, +1000
ASDFGH | Bias selection -0.01, -0.1, -1, -10, -100, -1000
Alt+Trackpad scroll | Bias selection +1/-1
Shift+Alt+Trackpad | Bias selection +10/-10
I | Toggle interpolation (step/linear/smooth/ramp)
Return | Insert current interpolated value
Shift+Arrows | Select
Cmd+T | Select all keys in track
Cmd+X | Cut
Cmd+C | Copy
Cmd+V | Paste
Cmd+Z | Undo
Cmd+Shift+Z | Redo
Delete | Delete key
Files:
Cmd+O - Open file
Cmd+S - Quicksave
Cmd+Shift+S - Save as
Cmd+1/2/3/4 - Quickload recent files
Cmd+E - Remote export
#### View:
Key | Action
--- | ---
Space | Start/Stop
Arrows | Move cursor around
Alt+Up/Down | Jump 8 rows
Alt+Cmd+Up/Down | Jump to StartRow/NextBookmark - PrevBookmark/EndRow
Cmd+Left/Right | Jump to first/last track
Ctrl+Up/Down | Jump to Previous/Next key in current track
Alt+Left/Right | Fold/Unfold track
Ctrl+Alt+Left/Right | Fold/Unfold group
Trackpad scroll | Scroll
B | Toggle Bookmark
Cmd+B | Clear all Bookmarks
Tab | Jump between Row, Start Row, End Row, Track editing
#### Files:
Key | Action
--- | ---
Cmd+O | Open file
Cmd+S | Quicksave
Cmd+Shift+S | Save as
Cmd+1/2/3/4 | Quickload recent files
Cmd+E | Remote export
---------------------------------------------------------------------------------
Windows and Linux:
### Windows and Linux:
Editing:
0-9 - Edit value
Esc - Cancel edit
QWERTY - Bias selection +0.01, +0.1, +1, +10, +100, +1000
ASDFGH - Bias selection -0.01, -0.1, -1, -10, -100, -1000
I - Toggle interpolation (step/linear/smooth/ramp)
Return - Insert current interpolated value
Shift+Arrows - Select
Ctrl+T - Select all keys in track
Ctrl+X - Cut
Ctrl+C - Copy
Ctrl+V - Paste
Ctrl+Z - Undo
Ctrl+Shift+Z - Redo
Delete - Delete key
#### Editing:
View:
Space - Start/Stop
Arrows - Move cursor around
Alt+Up/Down - Jump 8 rows
Ctrl+Alt+Up/Down - Jump to StartRow/NextBookmark - PrevBookmark/EndRow
Ctrl+Left/Right - Jump to first/last track
Ctrl+Up/Down - Jump to Previous/Next key in current track
Alt+Left/Right - Fold/Unfold track
Ctrl+Alt+Left/Right - Fold/Unfold group
Trackpad scroll - Scroll
B - Toggle Bookmark
Ctrl+B - Clear all Bookmarks
Tab - Jump between Row, Start Row, End Row, Track editing
Key | Action
--- | ---
0-9 | Edit value
Esc | Cancel edit
QWERTY | Bias selection +0.01, +0.1, +1, +10, +100, +1000
ASDFGH | Bias selection -0.01, -0.1, -1, -10, -100, -1000
I | Toggle interpolation (step/linear/smooth/ramp)
Return | Insert current interpolated value
Shift+Arrows | Select
Ctrl+T | Select all keys in track
Ctrl+X | Cut
Ctrl+C | Copy
Ctrl+V | Paste
Ctrl+Z | Undo
Ctrl+Shift+Z | Redo
Delete | Delete key
Files:
Ctrl+O - Open file
Ctrl+S - Quicksave
Ctrl+Shift+S - Save as
Ctrl+1/2/3/4 - Quickload recent files
Ctrl+E - Remote export
#### View:
Key | Action
--- | ---
Space | Start/Stop
Arrows | Move cursor around
Alt+Up/Down | Jump 8 rows
Ctrl+Alt+Up/Down | Jump to StartRow/NextBookmark - PrevBookmark/EndRow
Ctrl+Left/Right | Jump to first/last track
Ctrl+Up/Down | Jump to Previous/Next key in current track
Alt+Left/Right | Fold/Unfold track
Ctrl+Alt+Left/Right | Fold/Unfold group
Trackpad scroll | Scroll
B | Toggle Bookmark
Ctrl+B | Clear all Bookmarks
Tab | Jump between Row, Start Row, End Row, Track editing
#### Files:
Key | Action
--- | ---
Ctrl+O | Open file
Ctrl+S | Quicksave
Ctrl+Shift+S | Save as
Ctrl+1/2/3/4 | Quickload recent files
Ctrl+E | Remote export

View File

@ -5,7 +5,7 @@
#else
#include <unistd.h>
#endif
#include "../../sync/sync.h"
#include "../../lib/sync.h"
static struct sync_device *device;
#if !defined(SYNC_PLAYER)

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSMainNibFile</key>
<string>appnib</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.4</string>
</dict>
</plist>

View File

@ -2,8 +2,8 @@
#include "RemoteConnection.h"
#include "TrackData.h"
#include "TrackView.h"
#include "../../sync/sync.h"
#include "../../sync/track.h"
#include "../../lib/sync.h"
#include "../../lib/track.h"
#include <stdlib.h>
#include <stdio.h>
#include <emgui/Types.h>

View File

@ -14,11 +14,18 @@
#include "Commands.h"
#include "MinecraftiaFont.h"
#include "Window.h"
#include "../../sync/sync.h"
#include "../../sync/base.h"
#include "../../sync/data.h"
#include "../../lib/sync.h"
#include "../../lib/base.h"
#include <emgui/Emgui.h>
enum {
SET_KEY = 0,
DELETE_KEY = 1,
GET_TRACK = 2,
SET_ROW = 3,
PAUSE = 4,
SAVE_TRACKS = 5
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void updateNeedsSaving();
@ -140,7 +147,7 @@ void setMostRecentFile(const text_t* filename)
static inline struct sync_track** getTracks()
{
return s_editorData.trackData.syncData.tracks;
return s_editorData.trackData.syncTracks;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -175,7 +182,7 @@ static inline int getActiveTrack()
static inline int getTrackCount()
{
return s_editorData.trackData.syncData.num_tracks;
return s_editorData.trackData.num_syncTracks;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -865,7 +872,7 @@ static int processCommands()
// setup remap and send the keyframes to the demo
RemoteConnection_mapTrackName(trackName);
RemoteConnection_sendKeyFrames(trackName, s_editorData.trackData.syncData.tracks[serverIndex]);
RemoteConnection_sendKeyFrames(trackName, s_editorData.trackData.syncTracks[serverIndex]);
TrackData_linkTrack(serverIndex, trackName, &s_editorData.trackData);
s_editorData.trackData.tracks[serverIndex].active = true;

View File

@ -22,11 +22,13 @@
#include <arpa/inet.h>
#endif
#include "../../sync/base.h"
#include "../../sync/track.h"
#include "../../lib/base.h"
#include "../../lib/track.h"
#include "rlog.h"
#include <stdio.h>
#include <assert.h>
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
@ -35,6 +37,69 @@
#define SOCKET_ERROR -1
#endif
/* configure socket-stack */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define USE_GETADDRINFO
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <limits.h>
#elif defined(USE_AMITCP)
#include <sys/socket.h>
#include <proto/exec.h>
#include <proto/socket.h>
#include <netdb.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
#define closesocket(x) CloseSocket(x)
#else
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket(x) close(x)
#endif
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"
enum {
SET_KEY = 0,
DELETE_KEY = 1,
GET_TRACK = 2,
SET_ROW = 3,
PAUSE = 4,
SAVE_TRACKS = 5
};
static inline int socket_poll(SOCKET socket)
{
struct timeval to = { 0, 0 };
fd_set fds;
FD_ZERO(&fds);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
FD_SET(socket, &fds);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
return select((int)socket + 1, &fds, NULL, NULL, &to) > 0;
}
static int s_clientIndex;
int s_socket = INVALID_SOCKET;
int s_serverSocket = INVALID_SOCKET;

View File

@ -2,22 +2,54 @@
#include "Commands.h"
#include "rlog.h"
#include <stdio.h>
#include <assert.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int sync_find_track(struct sync_track **tracks, size_t num_tracks, const char *name)
{
int i;
for (i = 0; i < (int)num_tracks; ++i)
if (!strcmp(name, tracks[i]->name))
return i;
return -1; /* not found */
}
int sync_create_track(struct sync_track ***tracksPtr, size_t *num_tracksPtr, const char *name)
{
struct sync_track *t;
struct sync_track **tracks = *tracksPtr;
size_t num_tracks = *num_tracksPtr;
assert(sync_find_track(tracks, num_tracks, name) < 0);
t = malloc(sizeof(*t));
t->name = strdup(name);
t->keys = NULL;
t->num_keys = 0;
tracks = realloc(tracks, sizeof(tracks[0]) * (num_tracks+1));
tracks[num_tracks] = t;
*num_tracksPtr = num_tracks+1;
*tracksPtr = tracks;
return (int)num_tracks;
}
int TrackData_createGetTrack(TrackData* trackData, const char* name)
{
int index = sync_find_track(&trackData->syncData, name);
int index = sync_find_track(trackData->syncTracks, trackData->num_syncTracks, name);
if (index < 0)
{
index = sync_create_track(&trackData->syncData, name);
index = sync_create_track(&trackData->syncTracks, &trackData->num_syncTracks, name);
memset(&trackData->tracks[index], 0, sizeof(Track));
trackData->tracks[index].index = index;
trackData->tracks[index].color = TrackData_getNextColor(trackData);
}
if (trackData->syncData.tracks)
Commands_init(trackData->syncData.tracks, trackData);
if (trackData->syncTracks)
Commands_init(trackData->syncTracks, trackData);
return index;
}
@ -151,10 +183,9 @@ void TrackData_linkTrack(int index, const char* name, TrackData* trackData)
void TrackData_linkGroups(TrackData* trackData)
{
int i, track_count;
struct sync_data* sync = &trackData->syncData;
for (i = 0, track_count = sync->num_tracks; i < track_count; ++i)
TrackData_linkTrack(i, sync->tracks[i]->name, trackData);
for (i = 0, track_count = trackData->num_syncTracks; i < track_count; ++i)
TrackData_linkTrack(i, trackData->syncTracks[i]->name, trackData);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,7 @@
#pragma once
#include <emgui/Types.h>
#include "../../sync/data.h"
#include "../../lib/track.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -64,7 +64,8 @@ typedef struct Group
typedef struct TrackData
{
struct sync_data syncData;
struct sync_track **syncTracks;
size_t num_syncTracks;
Track tracks[EDITOR_MAX_TRACKS];
Group groups[EDITOR_MAX_TRACKS];
int* loopmarks;

View File

@ -7,9 +7,8 @@
#include "rlog.h"
#include "minmax.h"
#include "ImageData.h"
#include "../../sync/sync.h"
#include "../../sync/data.h"
#include "../../sync/track.h"
#include "../../lib/sync.h"
#include "../../lib/track.h"
#if defined(__APPLE__)
#include <OpenGL/OpenGL.h>
@ -397,8 +396,8 @@ static int renderChannel(struct TrackInfo* info, int startX, Track* trackData, b
folded = trackData->folded;
if (info->trackData->syncData.tracks)
track = info->trackData->syncData.tracks[trackData->index];
if (info->trackData->syncTracks)
track = info->trackData->syncTracks[trackData->index];
size = renderName(trackData->displayName, startX, info->startY - (font_size * 2), min_track_size, folded, trackData->active);

View File

@ -3,10 +3,10 @@
#include "TrackData.h"
#include "../external/mxml/mxml.h"
#include "RemoteConnection.h"
#include "../../sync/data.h"
#include <stdio.h>
#include <stdlib.h>
#include <emgui/Types.h>
#include <assert.h>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -101,7 +101,7 @@ static void parseXml(mxml_node_t* rootNode, TrackData* trackData)
track_index = TrackData_createGetTrack(trackData, track_name);
t = &trackData->tracks[track_index];
track = trackData->syncData.tracks[track_index];
track = trackData->syncTracks[track_index];
if (!color_text && t->color == 0)
{
@ -162,7 +162,7 @@ static void parseXml(mxml_node_t* rootNode, TrackData* trackData)
}
else if (!strcmp("key", element_name))
{
struct sync_track* track = trackData->syncData.tracks[track_index];
struct sync_track* track = trackData->syncTracks[track_index];
Track* t = &trackData->tracks[track_index];
const char* row = mxmlElementGetAttr(node, "row");
@ -354,7 +354,6 @@ int LoadSave_saveRocketXML(const text_t* path, TrackData* trackData)
FILE* fp;
size_t p;
struct sync_data* sync_data = &trackData->syncData;
int* bookmarks = trackData->bookmarks;
int* loopmarks = trackData->loopmarks;
@ -410,9 +409,9 @@ int LoadSave_saveRocketXML(const text_t* path, TrackData* trackData)
setElementInt(tracks, "endRow", "%d", trackData->endRow);
setElementInt(tracks, "highlightRowStep", "%d", trackData->highlightRowStep);
for (p = 0; p < sync_data->num_tracks; ++p)
for (p = 0; p < trackData->num_syncTracks; ++p)
{
const struct sync_track* t = sync_data->tracks[p];
const struct sync_track* t = trackData->syncTracks[p];
mxml_node_t* track = mxmlNewElement(tracks, "track");
bool isMuted = trackData->tracks[p].muteBackup ? true : false;

View File

@ -65,7 +65,7 @@ StaticLibrary {
Sources = {
Glob {
Dir = "../sync",
Dir = "../lib",
Extensions = { ".c" },
},
},

View File

@ -1,20 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sync_editor", "editor\editor.vcproj", "{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Debug|Win32.ActiveCfg = Debug|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Debug|Win32.Build.0 = Debug|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.ActiveCfg = Release|Win32
{76B44BC8-8BB4-4B6E-B2FA-7738C9E7F80B}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -1,124 +0,0 @@
/* Copyright (C) 2007-2010 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef SYNC_BASE_H
#define SYNC_BASE_H
/* configure inline keyword */
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
#if defined(_MSC_VER) || defined(__GNUC__) || defined(__SASC)
#ifndef inline
#define inline __inline
#endif
#else
/* compiler does not support inline, make function static instead */
#define inline static
#endif
#endif
/* configure lacking CRT features */
#ifdef _MSC_VER
#define strdup _strdup
#define snprintf _snprintf
/* int is 32-bit for both x86 and x64 */
typedef unsigned int uint32_t;
#define UINT32_MAX UINT_MAX
#elif defined(__GNUC__)
#include <stdint.h>
#elif defined(M68000)
typedef unsigned int uint32_t;
#endif
/* configure socket-stack */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <winsock2.h>
#include <windows.h>
#include <limits.h>
#elif defined(USE_AMITCP)
#include <sys/socket.h>
#include <proto/exec.h>
#include <proto/socket.h>
#include <netdb.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
#define closesocket(x) CloseSocket(x)
#else
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket(x) close(x)
#endif
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"
enum {
SET_KEY = 0,
DELETE_KEY = 1,
GET_TRACK = 2,
SET_ROW = 3,
PAUSE = 4,
SAVE_TRACKS = 5
};
static inline int socket_poll(SOCKET socket)
{
struct timeval to = { 0, 0 };
fd_set fds;
FD_ZERO(&fds);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
FD_SET(socket, &fds);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
return select((int)socket + 1, &fds, NULL, NULL, &to) > 0;
}
#include <assert.h>
static inline int xsend(SOCKET s, const void *buf, size_t len, int flags)
{
#ifdef WIN32
assert(len <= INT_MAX);
return send(s, (const char *)buf, (int)len, flags) != (int)len;
#else
return send(s, (const char *)buf, len, flags) != len;
#endif
}
static inline int xrecv(SOCKET s, void *buf, size_t len, int flags)
{
#ifdef WIN32
assert(len <= INT_MAX);
return recv(s, (char *)buf, (int)len, flags) != (int)len;
#else
return recv(s, (char *)buf, len, flags) != len;
#endif
}
#ifdef NEED_STRDUP
static inline char *rocket_strdup(const char *str)
{
char *ret = malloc(strlen(str) + 1);
if (ret)
strcpy(ret, str);
return ret;
}
#define strdup rocket_strdup
#endif
#endif /* SYNC_BASE_H */

View File

@ -1,33 +0,0 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#include "data.h"
void sync_data_deinit(struct sync_data *d)
{
int i;
for (i = 0; i < (int)d->num_tracks; ++i) {
free(d->tracks[i]->name);
free(d->tracks[i]->keys);
free(d->tracks[i]);
}
free(d->tracks);
}
int sync_create_track(struct sync_data *d, const char *name)
{
struct sync_track *t;
assert(sync_find_track(d, name) < 0);
t = malloc(sizeof(*t));
t->name = strdup(name);
t->keys = NULL;
t->num_keys = 0;
d->num_tracks++;
d->tracks = realloc(d->tracks, sizeof(d->tracks[0]) * d->num_tracks);
d->tracks[d->num_tracks - 1] = t;
return (int)d->num_tracks - 1;
}

View File

@ -1,28 +0,0 @@
/* Copyright (C) 2007-2010 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef SYNC_DATA_H
#define SYNC_DATA_H
#include "track.h"
struct sync_data {
struct sync_track **tracks;
size_t num_tracks;
};
static inline int sync_find_track(const struct sync_data *data,
const char *name)
{
int i;
for (i = 0; i < (int)data->num_tracks; ++i)
if (!strcmp(name, data->tracks[i]->name))
return i;
return -1; /* not found */
}
void sync_data_deinit(struct sync_data *);
int sync_create_track(struct sync_data *, const char *);
#endif /* SYNC_DATA_H */

View File

@ -1,23 +0,0 @@
/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in COPYING
*/
#ifndef SYNC_DEVICE_H
#define SYNC_DEVICE_H
#include "data.h"
#include "sync.h"
struct sync_device {
char *base;
struct sync_data data;
#ifndef SYNC_PLAYER
int row;
SOCKET sock;
#else
struct sync_io_cb io_cb;
#endif
};
#endif /* SYNC_DEVICE_H */