aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-03 18:59:15 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-07-03 18:59:15 +0200
commitd22e8081534abd668c97a351a7a347d739bcbc67 (patch)
tree41ce0d8e50f7e8fdc689a3156588e45b2580d092
parente995aff05b6d89a92caa91af9df3c78ae07d7f99 (diff)
downloadtracker.lv2-d22e8081534abd668c97a351a7a347d739bcbc67.tar.xz
Squashed 'timely.lv2/' changes from e995aff..e42f631
e42f631 prototype timely:multiplier. 43a7d74 remove duplicate parameter. 40852e9 fix last commit. 7de603f take time:speed into account for frames/beat. 54412b1 migrate test to lv2_logger. git-subtree-dir: timely.lv2 git-subtree-split: e42f631d0d111de0e3f5c0bb5ebc9c4a09a16a70
-rw-r--r--test/timely.c82
-rw-r--r--timely.h84
2 files changed, 104 insertions, 62 deletions
diff --git a/test/timely.c b/test/timely.c
index 171fc9d..ce442b0 100644
--- a/test/timely.c
+++ b/test/timely.c
@@ -22,6 +22,7 @@
#include <timely.h>
#include <lv2/lv2plug.in/ns/ext/log/log.h>
+#include <lv2/lv2plug.in/ns/ext/log/logger.h>
#define TIMELY_PREFIX "http://open-music-kontrollers.ch/lv2/timely#"
#define TIMELY_TEST_URI TIMELY_PREFIX"test"
@@ -31,59 +32,69 @@ typedef struct _plughandle_t plughandle_t;
struct _plughandle_t {
LV2_URID_Map *map;
LV2_Log_Log *log;
+ LV2_Log_Logger logger;
timely_t timely;
- LV2_URID log_trace;
const LV2_Atom_Sequence *event_in;
};
-static int
-_log_vprintf(plughandle_t *handle, LV2_URID type, const char *fmt, va_list args)
-{
- return handle->log->vprintf(handle->log->handle, type, fmt, args);
-}
-
-// non-rt || rt with LV2_LOG__Trace
-static int
-_log_printf(plughandle_t *handle, LV2_URID type, const char *fmt, ...)
-{
- va_list args;
- int ret;
-
- va_start (args, fmt);
- ret = _log_vprintf(handle, type, fmt, args);
- va_end(args);
-
- return ret;
-}
-
static void
_timely_cb(timely_t *timely, int64_t frames, LV2_URID type, void *data)
{
plughandle_t *handle = data;
- const char *uri = NULL;
+ const int64_t frame = TIMELY_FRAME(timely);
if(type == TIMELY_URI_BAR_BEAT(timely))
- uri = LV2_TIME__barBeat;
+ {
+ const float bar_beat = TIMELY_BAR_BEAT_RAW(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:barBeat %f\n",
+ frame, frames, bar_beat);
+ }
else if(type == TIMELY_URI_BAR(timely))
- uri = LV2_TIME__bar;
+ {
+ const int64_t bar = TIMELY_BAR(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:bar %"PRIi64"\n",
+ frame, frames, bar);
+ }
else if(type == TIMELY_URI_BEAT_UNIT(timely))
- uri = LV2_TIME__beatUnit;
+ {
+ const int32_t beat_unit = TIMELY_BEAT_UNIT(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:beatUnit %"PRIi32"\n",
+ frame, frames, beat_unit);
+ }
else if(type == TIMELY_URI_BEATS_PER_BAR(timely))
- uri = LV2_TIME__beatsPerBar;
+ {
+ const float bpb = TIMELY_BEATS_PER_BAR(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:beatsPerBar %f\n",
+ frame, frames, bpb);
+ }
else if(type == TIMELY_URI_BEATS_PER_MINUTE(timely))
- uri = LV2_TIME__beatsPerMinute;
+ {
+ const float bpm = TIMELY_BEATS_PER_MINUTE(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:beatsPerMinute %f\n",
+ frame, frames, bpm);
+ }
else if(type == TIMELY_URI_FRAME(timely))
- uri = LV2_TIME__frame;
+ {
+ /*
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:frame %"PRIi64"\n",
+ frame, frames, frame);
+ */
+ }
else if(type == TIMELY_URI_FRAMES_PER_SECOND(timely))
- uri = LV2_TIME__framesPerSecond;
+ {
+ const float fps = TIMELY_FRAMES_PER_SECOND(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:framesPerSecond %f\n",
+ frame, frames, fps);
+ }
else if(type == TIMELY_URI_SPEED(timely))
- uri = LV2_TIME__speed;
-
- const int64_t frame = TIMELY_FRAME(timely);
- _log_printf(data, handle->log_trace, "0x%08"PRIx64" %4"PRIi64" %s (%i)", frame, frames, uri, type);
+ {
+ const float speed = TIMELY_SPEED(timely);
+ lv2_log_trace(&handle->logger, "0x%08"PRIx64" %4"PRIi64" time:speed %f\n",
+ frame, frames, speed);
+ }
}
static LV2_Handle
@@ -117,19 +128,20 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
return NULL;
}
- handle->log_trace = handle->map->map(handle->map->handle, LV2_LOG__Trace);
+ lv2_log_logger_init(&handle->logger, handle->map, handle->log);
timely_mask_t mask = TIMELY_MASK_BAR_BEAT
| TIMELY_MASK_BAR
| TIMELY_MASK_BEAT_UNIT
| TIMELY_MASK_BEATS_PER_BAR
| TIMELY_MASK_BEATS_PER_MINUTE
- | TIMELY_MASK_FRAME
+ //| TIMELY_MASK_FRAME
| TIMELY_MASK_FRAMES_PER_SECOND
| TIMELY_MASK_SPEED
| TIMELY_MASK_BAR_BEAT_WHOLE
| TIMELY_MASK_BAR_WHOLE;
timely_init(&handle->timely, handle->map, rate, mask, _timely_cb, handle);
+ timely_set_multiplier(&handle->timely, 1.f);
return handle;
}
diff --git a/timely.h b/timely.h
index 0cdf679..7dd00ee 100644
--- a/timely.h
+++ b/timely.h
@@ -75,6 +75,8 @@ struct _timely_t {
float speed;
} pos;
+ float multiplier;
+
double frames_per_beat;
double frames_per_bar;
@@ -83,11 +85,6 @@ struct _timely_t {
double bar;
} offset;
- struct {
- double beat;
- double bar;
- } window;
-
bool first;
timely_mask_t mask;
timely_cb_t cb;
@@ -104,7 +101,8 @@ struct _timely_t {
#define TIMELY_URI_SPEED(timely) ((timely)->urid.time_speed)
#define TIMELY_BAR_BEAT_RAW(timely) ((timely)->pos.bar_beat)
-#define TIMELY_BAR_BEAT(timely) (floor((timely)->pos.bar_beat) + (timely)->offset.beat / (timely)->frames_per_beat)
+#define TIMELY_BAR_BEAT(timely) (floor((timely)->pos.bar_beat) \
+ + (timely)->offset.beat / (timely)->frames_per_beat)
#define TIMELY_BAR(timely) ((timely)->pos.bar)
#define TIMELY_BEAT_UNIT(timely) ((timely)->pos.beat_unit)
#define TIMELY_BEATS_PER_BAR(timely) ((timely)->pos.beats_per_bar)
@@ -148,18 +146,26 @@ _timely_deatomize_body(timely_t *timely, int64_t frames, uint32_t size,
timely->cb(timely, frames, timely->urid.time_speed, timely->data);
}
- if(beat_unit && (beat_unit->body != timely->pos.beat_unit) )
+ if(beat_unit)
{
- timely->pos.beat_unit = beat_unit->body;
- if(timely->mask & TIMELY_MASK_BEAT_UNIT)
- timely->cb(timely, frames, timely->urid.time_beatUnit, timely->data);
+ const int32_t _beat_unit = beat_unit->body * timely->multiplier;
+ if(_beat_unit != timely->pos.beat_unit)
+ {
+ timely->pos.beat_unit = _beat_unit;
+ if(timely->mask & TIMELY_MASK_BEAT_UNIT)
+ timely->cb(timely, frames, timely->urid.time_beatUnit, timely->data);
+ }
}
- if(beats_per_bar && (beats_per_bar->body != timely->pos.beats_per_bar) )
+ if(beats_per_bar)
{
- timely->pos.beats_per_bar = beats_per_bar->body;
- if(timely->mask & TIMELY_MASK_BEATS_PER_BAR)
- timely->cb(timely, frames, timely->urid.time_beatsPerBar, timely->data);
+ const float _beats_per_bar = beats_per_bar->body * timely->multiplier;
+ if(_beats_per_bar != timely->pos.beats_per_bar)
+ {
+ timely->pos.beats_per_bar = _beats_per_bar;
+ if(timely->mask & TIMELY_MASK_BEATS_PER_BAR)
+ timely->cb(timely, frames, timely->urid.time_beatsPerBar, timely->data);
+ }
}
if(beats_per_minute && (beats_per_minute->body != timely->pos.beats_per_minute) )
@@ -190,11 +196,15 @@ _timely_deatomize_body(timely_t *timely, int64_t frames, uint32_t size,
timely->cb(timely, frames, timely->urid.time_bar, timely->data);
}
- if(bar_beat && (bar_beat->body != timely->pos.bar_beat) )
+ if(bar_beat)
{
- timely->pos.bar_beat = bar_beat->body;
- if(timely->mask & TIMELY_MASK_BAR_BEAT)
- timely->cb(timely, frames, timely->urid.time_barBeat, timely->data);
+ const float _bar_beat = bar_beat->body * timely->multiplier;
+ if(_bar_beat != timely->pos.bar_beat)
+ {
+ timely->pos.bar_beat = _bar_beat;
+ if(timely->mask & TIMELY_MASK_BAR_BEAT)
+ timely->cb(timely, frames, timely->urid.time_barBeat, timely->data);
+ }
}
// send speed last upon transport start
@@ -209,16 +219,18 @@ _timely_deatomize_body(timely_t *timely, int64_t frames, uint32_t size,
static inline void
_timely_refresh(timely_t *timely)
{
- timely->frames_per_beat = 240.0 / (timely->pos.beats_per_minute * timely->pos.beat_unit)
- * timely->pos.frames_per_second;
+ const float speed = (timely->pos.speed != 0.f)
+ ? timely->pos.speed
+ : 1.f; // prevent divisions through zero later on
+
+ timely->frames_per_beat = 240.0 * timely->pos.frames_per_second
+ / (timely->pos.beats_per_minute * timely->pos.beat_unit * speed);
timely->frames_per_bar = timely->frames_per_beat * timely->pos.beats_per_bar;
// bar
- timely->window.bar = timely->frames_per_bar;
timely->offset.bar = timely->pos.bar_beat * timely->frames_per_beat;
// beat
- timely->window.beat = timely->frames_per_beat;
double integral;
double beat_beat = modf(timely->pos.bar_beat, &integral);
(void)integral;
@@ -248,6 +260,8 @@ timely_init(timely_t *timely, LV2_URID_Map *map, double rate,
timely->urid.time_framesPerSecond = map->map(map->handle, LV2_TIME__framesPerSecond);
timely->urid.time_speed = map->map(map->handle, LV2_TIME__speed);
+ timely->multiplier = 1.f;
+
timely->pos.speed = 0.f;
timely->pos.bar_beat = 0.f;
timely->pos.bar = 0;
@@ -262,6 +276,22 @@ timely_init(timely_t *timely, LV2_URID_Map *map, double rate,
timely->first = true;
}
+static inline void
+timely_set_multiplier(timely_t *timely, float multiplier)
+{
+ const float mul = multiplier / timely->multiplier;
+
+ timely->pos.bar_beat *= mul;
+ timely->pos.beat_unit *= mul;
+ timely->pos.beats_per_bar *= mul;
+
+ timely->multiplier = multiplier;
+
+ _timely_refresh(timely);
+
+ timely->first = true;
+}
+
static inline int
timely_advance_body(timely_t *timely, uint32_t size, uint32_t type,
const LV2_Atom_Object_Body *body, uint32_t from, uint32_t to)
@@ -297,7 +327,7 @@ timely_advance_body(timely_t *timely, uint32_t size, uint32_t type,
}
// are we rolling?
- if(timely->pos.speed > 0.f)
+ if(timely->pos.speed != 0.f)
{
if( (timely->offset.bar == 0) && (timely->pos.bar == 0) )
{
@@ -314,10 +344,10 @@ timely_advance_body(timely_t *timely, uint32_t size, uint32_t type,
unsigned update_frame = to;
for(unsigned i=from; i<to; i++)
{
- if(timely->offset.bar >= timely->window.bar)
+ if(timely->offset.bar >= timely->frames_per_bar)
{
timely->pos.bar += 1;
- timely->offset.bar -= timely->window.bar;
+ timely->offset.bar -= timely->frames_per_bar;
if(timely->mask & TIMELY_MASK_FRAME)
timely->cb(timely, (update_frame = i), timely->urid.time_frame, timely->data);
@@ -326,10 +356,10 @@ timely_advance_body(timely_t *timely, uint32_t size, uint32_t type,
timely->cb(timely, i, timely->urid.time_bar, timely->data);
}
- if( (timely->offset.beat >= timely->window.beat) )
+ if( (timely->offset.beat >= timely->frames_per_beat) )
{
timely->pos.bar_beat = floor(timely->pos.bar_beat) + 1;
- timely->offset.beat -= timely->window.beat;
+ timely->offset.beat -= timely->frames_per_beat;
if(timely->pos.bar_beat >= timely->pos.beats_per_bar)
timely->pos.bar_beat -= timely->pos.beats_per_bar;