Skip to content

Commit

Permalink
Cleanup: Stripped out a bunch of unneeded stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmetoneillpdx committed Dec 4, 2023
1 parent 63073b4 commit a434f7f
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions src/modules/krita/producer_krita.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,24 @@

typedef struct
{
int frame_start;
int frame_end;
int limit_enabled;
double speed;
mlt_producer producer_internal;
} private_data;

static int restrict_range(int input, int min, int max)

/** Restricts frame index to within range by modulus wrapping (not clamping).
*/
static int restrict_range(int index, int min, int max)
{
const int span = max - min;
return (MAX(input - min, 0) % (span + 1)) + min;
return (MAX(index - min, 0) % (span + 1)) + min;
}

int is_valid_range(const private_data *pdata)
static int is_valid_range(const int frame_start, const int frame_end)
{
return pdata->frame_start > -1 && pdata->frame_end > -1
&& pdata->frame_end > pdata->frame_start;
}
const bool NON_NEGATIVE = frame_start >= 0 && frame_end >= 0;
const bool NON_INVERTED = frame_end > frame_start;

int is_limit_enabled(const private_data *pdata)
{
return pdata->limit_enabled != 0;
return NON_NEGATIVE && NON_INVERTED;
}

static int producer_get_audio(mlt_frame frame,
Expand All @@ -65,8 +61,6 @@ static int producer_get_audio(mlt_frame frame,
int *channels,
int *samples)
{
mlt_producer producer = mlt_frame_pop_audio(frame);
private_data *pdata = (private_data *) producer->child;
struct mlt_audio_s audio;
mlt_audio_set_values(&audio, *buffer, *frequency, *format, *samples, *channels);

Expand All @@ -77,10 +71,14 @@ static int producer_get_audio(mlt_frame frame,
&audio.channels,
&audio.samples);

// Scale the frequency to account for the speed change.
audio.frequency = (double) audio.frequency * fabs(pdata->speed);
mlt_producer producer = mlt_frame_pop_audio(frame);
mlt_properties props = MLT_PRODUCER_PROPERTIES(producer);

if (pdata->speed < 0.0) {
// Scale the frequency to account for the dynamic speed (normalized).
const double SPEED = mlt_properties_get_double(props, "speed");

audio.frequency = (double) audio.frequency * fabs(SPEED);
if (SPEED < 0.0) {
mlt_audio_reverse(&audio);
}

Expand All @@ -91,13 +89,18 @@ static int producer_get_audio(mlt_frame frame,

static int producer_get_frame(mlt_producer producer, mlt_frame_ptr frame, int index)
{
mlt_properties props = MLT_PRODUCER_PROPERTIES(producer);
const int FRAME_START = mlt_properties_get_int(props, "start_frame");
const int FRAME_END = mlt_properties_get_int(props, "end_frame");
const bool IS_RANGE_LIMITED = mlt_properties_get_int(props, "limit_enabled");

private_data *pdata = (private_data *) producer->child;
const int POSITION = mlt_producer_position(pdata->producer_internal);

const int position = mlt_producer_position(pdata->producer_internal);
if (is_valid_range(pdata) && is_limit_enabled(pdata)) {
if (IS_RANGE_LIMITED && is_valid_range(FRAME_START, FRAME_END)) {
mlt_properties_set_position(MLT_PRODUCER_PROPERTIES(pdata->producer_internal),
"_position",
restrict_range(position, pdata->frame_start, pdata->frame_end));
restrict_range(POSITION, FRAME_START, FRAME_END));
}

int r = mlt_service_get_frame((mlt_service) pdata->producer_internal, frame, index);
Expand All @@ -119,7 +122,7 @@ static int producer_seek(mlt_producer producer, mlt_position position)
return r;
}

static void producer_property_changed(mlt_service owner,
/*static void producer_property_changed(mlt_service owner,
mlt_producer self,
mlt_event_data event_data)
{
Expand Down Expand Up @@ -147,7 +150,7 @@ static void producer_property_changed(mlt_service owner,
mlt_service_set_profile((mlt_service) pdata->producer_internal,
mlt_service_profile((mlt_service) self));
}
}
}*/

static void producer_close(mlt_producer producer)
{
Expand Down Expand Up @@ -187,7 +190,15 @@ mlt_producer producer_krita_init(mlt_profile profile,
// Get the resource to be passed to the clip producer
char *resource = arg;

// Default frame start / end props.
// Create a producer for the clip using the false profile.
pdata->producer_internal = mlt_factory_producer(profile, "abnormal", resource);

if (pdata->producer_internal) {
mlt_producer_set_speed(pdata->producer_internal, 1.0);
}

// TODO: Reevaluate. Is this needed?
/*// Default frame start / end props.
pdata->frame_start = -1;
pdata->frame_end = -1;
pdata->limit_enabled = 1;
Expand All @@ -197,22 +208,18 @@ mlt_producer producer_krita_init(mlt_profile profile,
mlt_properties_set_int(producer_properties, "start_frame", pdata->frame_start);
mlt_properties_set_int(producer_properties, "end_frame", pdata->frame_end);
mlt_properties_set_int(producer_properties, "limit_enabled", pdata->limit_enabled);
mlt_properties_set_double(producer_properties, "speed", pdata->speed);

// Create a producer for the clip using the false profile.
pdata->producer_internal = mlt_factory_producer(profile, "abnormal", resource);

if (pdata->producer_internal) {
mlt_producer_set_speed(pdata->producer_internal, 1.0);
}

mlt_events_listen(producer_properties,
mlt_properties_set_double(producer_properties, "speed", pdata->speed);*/

// TODO: Reevaluate. Is this needed?
/*mlt_events_listen(producer_properties,
producer,
"property-changed",
(mlt_listener) producer_property_changed);
(mlt_listener) producer_property_changed);*/
}

if (!producer || !pdata || !pdata->producer_internal) {

const bool INVALID_CONTEXT = !producer || !pdata || !pdata->producer_internal;
if (INVALID_CONTEXT) { // Clean up early...
if (pdata) {
mlt_producer_close(pdata->producer_internal);
free(pdata);
Expand Down

0 comments on commit a434f7f

Please sign in to comment.