Skip to content

Commit

Permalink
added easable class to seperate it from drawable
Browse files Browse the repository at this point in the history
fade out selection box :).  implemented pausing videos.
video synched to audio.
  • Loading branch information
dsheeler committed Feb 6, 2018
1 parent f4a7289 commit bcdc951
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 120 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ CFLAGS += $(shell pkg-config --cflags pangocairo) \
$(shell pkg-config --cflags fftw3)
SRCS = drawable.cc v4l2_wayland.cc muxing.cc sound_shape.cc midi.cc kmeter.cc \
video_file_source.cc dingle_dots.cc v4l2.cc sprite.cc snapshot_shape.cc \
easer.cc
easer.cc easable.cc
CSRCS= easing.c

OBJS := $(SRCS:.cc=.o) $(CSRCS:.c=.o)

HDRS = drawable.h muxing.h sound_shape.h midi.h v4l2_wayland.h kmeter.h \
video_file_source.h dingle_dots.h v4l2.h sprite.h snapshot_shape.h \
easer.h easing.h
easer.h easing.h easable.h

.SUFFIXES:

Expand Down
39 changes: 38 additions & 1 deletion dingle_dots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int DingleDots::init(int width, int height,
this->show_shapshot_shape = 0;
this->mdown = 0;
this->dragging = 0;
this->selection_in_progress = 0;
this->set_selecting_off();
this->motion_threshold = 0.001;
for (int i = 0; i < MAX_NUM_SOUND_SHAPES; ++i) {
this->sound_shapes[i].clear_state();
Expand Down Expand Up @@ -72,6 +72,7 @@ int DingleDots::deactivate_sound_shapes() {
return 0;
}


int DingleDots::free() {
if (this->analysis_resize) {
sws_freeContext(this->analysis_resize);
Expand Down Expand Up @@ -118,6 +119,42 @@ void DingleDots::add_scale(midi_key_t *key, int midi_channel,
}
}

void DingleDots::render_selection_box(cairo_t *cr) {
cairo_save(cr);
cairo_rectangle(cr, floor(this->selection_rect.x)+0.5, floor(this->selection_rect.y)+0.5,
this->selection_rect.width, this->selection_rect.height);
cairo_set_source_rgba(cr, 1, 1, 1, 0.2 * this->selection_box_alpha);
cairo_fill_preserve(cr);
cairo_set_source_rgba(cr, 1, 1, 1, 1 * this->selection_box_alpha);
cairo_set_line_width(cr, 0.5);
cairo_stroke(cr);
cairo_restore(cr);
}

void DingleDots::set_selecting_on() {
this->selection_in_progress = 1;
this->selection_box_alpha = 1.0;
this->easers.clear();
gtk_widget_queue_draw(this->drawing_area);
}

void DingleDots::set_selecting_off() {
this->selection_in_progress = 0;
gtk_widget_queue_draw(this->drawing_area);
}

double DingleDots::get_selection_box_alpha() const
{
return selection_box_alpha;
}

void DingleDots::set_selection_box_alpha(double value)
{
selection_box_alpha = value;
gtk_widget_queue_draw(this->drawing_area);

}

uint8_t DingleDots::get_animating() const {
return animating;
}
Expand Down
11 changes: 9 additions & 2 deletions dingle_dots.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ typedef struct midi_key_t midi_key_t;
#include "video_file_source.h"
#include "v4l2.h"
#include "sprite.h"
#include "easable.h"

#define STR_LEN 80
#define MAX_NUM_V4L2 4
#define MAX_NUM_VIDEO_FILES 2
#define MAX_NUM_VIDEO_FILES 8
#define MAX_NUM_SPRITES 32
#define MAX_NUM_SOUND_SHAPES 128

class DingleDots {
class DingleDots : public Easable {
public:
DingleDots();
int init(int width, int height, int video_bitrate);
Expand All @@ -54,6 +55,7 @@ class DingleDots {
int use_rand_color_for_scale;
int shift_pressed;
int delete_active;
double selection_box_alpha;
uint8_t animating;
uint32_t video_bitrate;
AVFormatContext *video_output_context;
Expand Down Expand Up @@ -118,6 +120,11 @@ class DingleDots {
void set_animating(const uint8_t &value);
void get_sound_shapes(std::vector<Drawable *> &sound_shapes);
void get_sources(std::vector<Drawable *> &list);
double get_selection_box_alpha() const;
void set_selection_box_alpha(double value);
void render_selection_box(cairo_t *cr);
void set_selecting_on();
void set_selecting_off();
};

#endif
18 changes: 1 addition & 17 deletions drawable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,7 @@ Drawable::Drawable(double x, double y, int64_t z, double opacity, double scale)
this->scale = scale;
}

void Drawable::update_easers() {
std::vector<Easer *> to_finalize;
for (std::vector<Easer *>::iterator it = this->easers.begin(); it != this->easers.end(); ++it) {
Easer *easer = *it;
if (easer->active) {
easer->update_value();
if (easer->done()) {
to_finalize.push_back(easer);
}
}
}
while(to_finalize.size()) {
Easer *e = to_finalize.back();
e->finalize();
to_finalize.pop_back();
}
}


bool Drawable::render(std::vector<cairo_t *> &) {
return FALSE;
Expand Down
6 changes: 2 additions & 4 deletions drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdint.h>
#include "v4l2_wayland.h"
#include "easer.h"
#include "easable.h"

struct rectangle_double {
double x;
Expand All @@ -14,8 +15,7 @@ struct rectangle_double {
double height;
};

//class Easer;
class Drawable {
class Drawable : public Easable {
private:
void render_label(cairo_t *cr);
public:
Expand All @@ -33,15 +33,13 @@ class Drawable {
uint8_t active;
bool selected;
GdkPoint selected_pos;
std::vector<Easer *> easers;
DingleDots *dingle_dots;
public:
Drawable();
virtual ~Drawable() {}
Drawable(double x, double y, int64_t z, double opacity, double scale);
virtual int deactivate();
virtual int activate();
void update_easers();
void set_mdown(double x, double y, int64_t z);
void drag(double mouse_x, double mouse_y);
virtual int in(double x_in, double y_in);
Expand Down
30 changes: 30 additions & 0 deletions easable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "easable.h"
#include "easer.h"

Easable::Easable()
{

}

void Easable::update_easers() {
std::vector<Easer *> to_finalize;
for (std::vector<Easer *>::iterator it = this->easers.begin(); it != this->easers.end(); ++it) {
Easer *easer = *it;
if (easer->active) {
easer->update_value();
if (easer->done()) {
to_finalize.push_back(easer);
}
}
}
while(to_finalize.size()) {
Easer *e = to_finalize.back();
e->finalize();
to_finalize.pop_back();
}
}

void Easable::add_easer(Easer *value)
{
this->easers.push_back(value);
}
15 changes: 15 additions & 0 deletions easable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef EASABLE_H
#define EASABLE_H
#include "easer.h"

class Easable
{
public:
Easable();
void update_easers();
void add_easer(Easer *value);
protected:
std::vector<Easer *> easers;
};

#endif // EASABLE_H
4 changes: 2 additions & 2 deletions easer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ EasingFuncPtr Easer::easer_type_to_easing_func(Easer_Type type)
return func;
}

void Easer::initialize(Drawable *target, Easer_Type type, boost::function<void(double)> functor,
void Easer::initialize(Easable *target, Easer_Type type, boost::function<void(double)> functor,
double value_start, double value_finish,
double duration_secs)
{
Expand All @@ -126,7 +126,7 @@ void Easer::initialize(Drawable *target, Easer_Type type, boost::function<void(d
}

void Easer::start() {
target->easers.push_back(this);
target->add_easer(this);
this->active = TRUE;
clock_gettime(CLOCK_MONOTONIC, &this->start_ts);
}
Expand Down
7 changes: 4 additions & 3 deletions easer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ typedef enum {

class DingleDots;
class Drawable;
class Easable;
typedef AHFloat (*EasingFuncPtr)(AHFloat);
class Easer {
public:
Easer();
static EasingFuncPtr easer_type_to_easing_func(Easer_Type);
void initialize(Drawable *target, DingleDots *dd, Easer_Type type, double *value, double value_start, double value_finish, double duration_secs);
void initialize(Easable *target, DingleDots *dd, Easer_Type type, double *value, double value_start, double value_finish, double duration_secs);
void start();
void finalize();
void update_value();
Expand All @@ -60,7 +61,7 @@ class Easer {
void add_finish_action(boost::function<void ()> action);
EasingFuncPtr easing_func;

Drawable *target;
Easable *target;
boost::function<void(double)> setter;
DingleDots *dd;
bool active;
Expand All @@ -71,7 +72,7 @@ class Easer {
struct timespec start_ts;
std::vector<Easer *> finsh_easers;
std::vector<boost::function<void ()>> finish_actions;
void initialize(Drawable *target, Easer_Type type, boost::function<void (double)>, double value_start, double value_finish, double duration_secs);
void initialize(Easable *target, Easer_Type type, boost::function<void (double)>, double value_start, double value_finish, double duration_secs);
};

#endif // EASER_H
11 changes: 6 additions & 5 deletions v4l2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ void V4l2::create(DingleDots *dd, char *dev_name, double width, double height, u
this->pos.width = width;
this->pos.height = height;
pthread_create(&this->thread_id, NULL, V4l2::thread, this);
int rc = pthread_setname_np(this->thread_id, "vw_v4l2_source");
if (rc != 0) {
errno = rc;
perror("pthread_setname_np");
}

}

void *V4l2::thread(void *arg) {
V4l2 *v = (V4l2 *)arg;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
int rc = pthread_setname_np(v->thread_id, "v4l2_wayland_v4l2_source");
if (rc != 0) {
errno = rc;
perror("pthread_setname_np");
}
v->open_device();
v->init_device();
v->rbuf = jack_ringbuffer_create(5*4*v->pos.width*v->pos.height);
Expand Down
Loading

0 comments on commit bcdc951

Please sign in to comment.