Commit e42f631d authored by Hanspeter Portner's avatar Hanspeter Portner

prototype timely:multiplier.

parent 43a7d745
......@@ -141,6 +141,7 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
| 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;
}
......
......@@ -75,6 +75,8 @@ struct _timely_t {
float speed;
} pos;
float multiplier;
double frames_per_beat;
double frames_per_bar;
......@@ -144,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) )
......@@ -186,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
......@@ -246,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;
......@@ -260,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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment