Merge branch 'master' of git://github.com/kusma/rocket

This commit is contained in:
Daniel Collin 2013-01-09 09:39:34 +01:00
commit 55ac22414a
7 changed files with 53 additions and 17 deletions

View File

@ -9,6 +9,7 @@
#include <commctrl.h>
#include <objbase.h>
#include <commdlg.h>
#include <shellapi.h>
#include <stdio.h>
#include <stdarg.h>
@ -673,7 +674,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
if (NULL == hwnd)
die("Window Creation Failed!");
fileNew();
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));

View File

@ -60,6 +60,7 @@ BEGIN
"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

View File

@ -97,7 +97,7 @@ bool SyncDocument::save(const std::wstring &fileName)
MSXML2::IXMLDOMElementPtr tracksNode =
doc->createElement("tracks");
for (size_t i = 0; i < num_tracks; ++i) {
const sync_track *t = tracks[i];
const sync_track *t = tracks[trackOrder[i]];
MSXML2::IXMLDOMElementPtr trackElem =
doc->createElement("track");

View File

@ -80,6 +80,16 @@ static SOCKET server_connect(const char *host, unsigned short nport)
closesocket(sock);
return INVALID_SOCKET;
}
#else
void sync_set_io_cb(struct sync_device *d, struct sync_io_cb *cb)
{
d->io_cb.open = cb->open;
d->io_cb.read = cb->read;
d->io_cb.close = cb->close;
}
#endif
struct sync_device *sync_create_device(const char *base)
@ -100,6 +110,10 @@ struct sync_device *sync_create_device(const char *base)
#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;
#endif
return d;
@ -124,11 +138,11 @@ void sync_destroy_device(struct sync_device *d)
static int get_track_data(struct sync_device *d, struct sync_track *t)
{
int i;
FILE *fp = fopen(sync_track_path(d->base, t->name), "rb");
void *fp = d->io_cb.open(sync_track_path(d->base, t->name), "rb");
if (!fp)
return -1;
fread(&t->num_keys, sizeof(size_t), 1, fp);
d->io_cb.read(&t->num_keys, sizeof(size_t), 1, fp);
t->keys = malloc(sizeof(struct track_key) * t->num_keys);
if (!t->keys)
return -1;
@ -136,13 +150,13 @@ 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;
fread(&key->row, sizeof(size_t), 1, fp);
fread(&key->value, sizeof(float), 1, fp);
fread(&type, sizeof(char), 1, fp);
d->io_cb.read(&key->row, sizeof(size_t), 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;
}
fclose(fp);
d->io_cb.close(fp);
return 0;
}

View File

@ -6,6 +6,7 @@
#define SYNC_DEVICE_H
#include "data.h"
#include "sync.h"
struct sync_device {
char *base;
@ -14,6 +15,8 @@ struct sync_device {
#ifndef SYNC_PLAYER
int row;
SOCKET sock;
#else
struct sync_io_cb io_cb;
#endif
};

View File

@ -25,10 +25,17 @@ struct sync_cb {
int sync_connect(struct sync_device *, const char *, unsigned short);
int sync_update(struct sync_device *, int, struct sync_cb *, void *);
void sync_save_tracks(const struct sync_device *);
#endif /* !defined(SYNC_PLAYER) */
#else /* defined(SYNC_PLAYER) */
struct sync_io_cb {
void *(*open)(const char *filename, const char *mode);
size_t (*read)(void *ptr, size_t size, size_t nitems, void *stream);
int (*close)(void *stream);
};
void sync_set_io_cb(struct sync_device *d, struct sync_io_cb *cb);
#endif /* defined(SYNC_PLAYER) */
const struct sync_track *sync_get_track(struct sync_device *, const char *);
float sync_get_val(const struct sync_track *, double);
double sync_get_val(const struct sync_track *, double);
#ifdef __cplusplus
}

View File

@ -13,27 +13,27 @@
#include "track.h"
#include "base.h"
static float key_linear(const struct track_key k[2], double row)
static double key_linear(const struct track_key k[2], double row)
{
double t = (row - k[0].row) / (k[1].row - k[0].row);
return (float)(k[0].value + (k[1].value - k[0].value) * t);
return k[0].value + (k[1].value - k[0].value) * t;
}
static float key_smooth(const struct track_key k[2], double row)
static double key_smooth(const struct track_key k[2], double row)
{
double t = (row - k[0].row) / (k[1].row - k[0].row);
t = t * t * (3 - 2 * t);
return (float)(k[0].value + (k[1].value - k[0].value) * t);
return k[0].value + (k[1].value - k[0].value) * t;
}
static float key_ramp(const struct track_key k[2], double row)
static double key_ramp(const struct track_key k[2], double row)
{
double t = (row - k[0].row) / (k[1].row - k[0].row);
t = pow(t, 2.0);
return (float)(k[0].value + (k[1].value - k[0].value) * t);
return k[0].value + (k[1].value - k[0].value) * t;
}
float sync_get_val(const struct sync_track *t, double row)
double sync_get_val(const struct sync_track *t, double row)
{
int idx, irow;