Skip to content

Commit

Permalink
WIP: made most things classes, but not using, yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsheeler committed Nov 19, 2017
1 parent 84e3526 commit ee7ac14
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 287 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ PROGS=$(PROGNAME)

all: $(PROGS)

LFLAGS = $(shell pkg-config --libs wayland-client) \
$(shell pkg-config --libs wayland-cursor) \
$(shell pkg-config --libs cairo) \
LFLAGS = $(shell pkg-config --libs cairo) \
$(shell pkg-config --libs pangocairo) \
$(shell pkg-config --libs gtk+-3.0) \
$(shell pkg-config --libs fftw3) \
Expand All @@ -24,8 +22,8 @@ CFLAGS = -O3 -ffast-math -Wall
CFLAGS += $(shell pkg-config --cflags pangocairo) \
$(shell pkg-config --cflags gtk+-3.0) \
$(shell pkg-config --cflags fftw3)
SRCS = draggable.c v4l2_wayland.c muxing.c sound_shape.c midi.c kmeter.c \
video_file_source.c dingle_dots.c v4l2.c
SRCS = draggable.cc v4l2_wayland.c muxing.c sound_shape.c midi.c kmeter.c \
video_file_source.c dingle_dots.c v4l2.cc
OBJS = $(SRCS:.c=.o)
HDRS = draggable.h muxing.h sound_shape.h midi.h v4l2_wayland.h kmeter.h \
video_file_source.h dingle_dots.h v4l2.h
Expand Down
14 changes: 6 additions & 8 deletions dingle_dots.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ extern "C" {
#endif
#include <gtk/gtk.h>
#include "v4l2_wayland.h"
typedef struct dingle_dots_t dingle_dots_t;
typedef struct midi_key_t midi_key_t;
typedef struct dd_v4l2_t dd_v4l2_t;
#include "sound_shape.h"
#include "kmeter.h"
#include "midi.h"
Expand All @@ -23,11 +26,6 @@ extern "C" {
#define STR_LEN 80
#define MAX_NUM_V4L2 3

typedef struct sound_shape sound_shape;
typedef struct dingle_dots_t dingle_dots_t;
typedef struct midi_key_t midi_key_t;
typedef struct dd_v4l2_t dd_v4l2_t;

struct dingle_dots_t {
GApplication *app;
gboolean fullscreen;
Expand Down Expand Up @@ -57,10 +55,10 @@ struct dingle_dots_t {
struct SwsContext *screen_resize;
AVFrame *video_frame;
double scale;
video_file_t vf[MAX_NUM_VIDEO_FILES];
VideoFile *vf[MAX_NUM_VIDEO_FILES];
int current_video_file_source_index;
dd_v4l2_t dd_v4l2[MAX_NUM_V4L2];
sound_shape sound_shapes[MAX_NSOUND_SHAPES];
V4l2 *v4l2[MAX_NUM_V4L2];
SoundShape sound_shapes[MAX_NSOUND_SHAPES];
kmeter meters[2];
GdkRectangle drawing_rect;
int doing_motion;
Expand Down
29 changes: 0 additions & 29 deletions draggable.c

This file was deleted.

33 changes: 33 additions & 0 deletions draggable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "draggable.h"

Draggable::Draggable() {
pos.x = 0.0;
pos.y = 0.0;
z = 0;
mdown = 0;
}

Draggable::Draggable(double x, double y, uint64_t z) {
pos.x = x;
pos.y = y;
z = z;
mdown = 0;
}

void Draggable::set_mdown(double x, double y, uint64_t z) {
mdown = 1;
z = z;
mdown_pos.x = x;
mdown_pos.y = y;
down_pos.x = pos.x;
down_pos.y = pos.y;
}

void Draggable::drag(double mouse_x, double mouse_y) {
if (mdown) {
pos.x = mouse_x - mdown_pos.x + down_pos.x;
pos.y = mouse_y - mdown_pos.y + down_pos.y;
}
}


28 changes: 15 additions & 13 deletions draggable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
#include "gtk/gtk.h"
#include <stdint.h>

typedef struct draggable {
void (*set_mdown)(void* dr, double x, double y, uint64_t z);
void (*drag)(void *dr, double mouse_x, double mouse_y);
uint64_t z;
int mdown;
GdkRectangle pos;
GdkRectangle mdown_pos;
GdkRectangle down_pos;
} draggable;

void draggable_set_mdown(void *dr, double x, double y, uint64_t z);
void draggable_drag(void *dr, double mouse_x, double mouse_y);
void draggable_init(void *dr, double x, double y, uint64_t z);
class Draggable {
private:
void render_label(cairo_t *cr);
uint64_t z;
int mdown;
protected:
GdkRectangle pos;
GdkRectangle mdown_pos;
GdkRectangle down_pos;
public:
Draggable();
Draggable(double x, double y, uint64_t z);
void set_mdown(double x, double y, uint64_t z);
void drag(double mouse_x, double mouse_y);
};

#endif
39 changes: 19 additions & 20 deletions sound_shape.c
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
#include "sound_shape.h"
#include "midi.h"

int sound_shape_init(sound_shape *ss, char *label,
uint8_t midi_note, uint8_t midi_channel, double x, double y, double r,
color *c, dingle_dots_t *dd) {
draggable_init(ss, x, y, dd->next_z++);
ss->dd = dd;
ss->active = 0;
ss->r = r;
strncpy(ss->label, label, NCHAR);
ss->midi_note = midi_note;
ss->midi_channel = midi_channel;
ss->normal = color_copy(c);
ss->playing = color_lighten(c, 0.95);
ss->on = 0;
SoundShape::SoundShape(string &label, uint8_t midi_note, uint8_t midi_channel,
double x, double y, double r, color *c, dingle_dots_t *dd)
: Draggable(x, y, 0) {
dd = dd;
active = 0;
r = r;
label = string(label);
midi_note = midi_note;
midi_channel = midi_channel;
normal = color_copy(c);
playing = color_lighten(c, 0.95);
on = 0;
return 0;
}

static void sound_shape_render_label(sound_shape *ss, cairo_t *cr) {
void SoundShape::render_label(cairo_t *cr) {
PangoLayout *layout;
PangoFontDescription *desc;
int width, height;
char font[32];
sprintf(font, "Agave %d", (int)ceil(0.2 * ss->r));
sprintf(font, "Agave %d", (int)ceil(0.2 * this->r));
layout = pango_cairo_create_layout(cr);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_text(layout, ss->label, -1);
pango_layout_set_text(layout, this.label.c_str(), -1);
desc = pango_font_description_from_string(font);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
cairo_save(cr);
ss->on ? cairo_set_source_rgba(cr, 0., 0., 0., ss->playing.a) :
this->is_on() ? cairo_set_source_rgba(cr, 0., 0., 0., this->playing.a) :
cairo_set_source_rgba(cr, 1., 1., 1., ss->normal.a);
pango_layout_get_size(layout, &width, &height);
cairo_translate(cr, ss->dr.pos.x - 0.5*width/PANGO_SCALE, ss->dr.pos.y
cairo_translate(cr, this.pos.x - 0.5*width/PANGO_SCALE, this.pos.y
- 0.5*height/PANGO_SCALE);
pango_cairo_show_layout(cr, layout);
cairo_restore(cr);
g_object_unref(layout);
}

int sound_shape_render(sound_shape *ss, cairo_t *cr) {
int SoundShape::render(cairo_t *cr) {
color *c;
c = &ss->normal;
c = &this->normal;
cairo_save(cr);
cairo_set_source_rgba(cr, c->r, c->g, c->b, c->a);
cairo_translate(cr, ss->dr.pos.x, ss->dr.pos.y);
Expand Down
70 changes: 36 additions & 34 deletions sound_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
#include <pango/pangocairo.h>
#include <math.h>
#include <string.h>
#include <string>
#include <stdint.h>
#include <gdk/gdk.h>
#include "dingle_dots.h"
#include "draggable.h"
#include "v4l2_wayland.h"

#define NCHAR 32
#define MAX_NSOUND_SHAPES 256

typedef struct sound_shape sound_shape;
typedef struct dingle_dots_t dingle_dots_t;

#ifdef __cplusplus
using namespace std;
#endif
typedef struct {
double r;
double g;
Expand All @@ -30,43 +32,43 @@ struct hsva {
double a;
};

struct sound_shape {
draggable dr;
dingle_dots_t *dd;
uint8_t active;
uint8_t on;
uint8_t double_clicked_on;
uint8_t selected;
uint8_t hovered;
uint8_t motion_state;
uint8_t motion_state_to_off;
struct timespec motion_ts;
uint8_t tld_state;
GdkPoint selected_pos;
double r;
char label[NCHAR];
uint8_t midi_note;
uint8_t midi_channel;
color normal;
color playing;
class SoundShape : Draggable {
public:
SoundShape(string &label, uint8_t midi_note, uint8_t midi_channel,
double x, double y, double r, color *c, dingle_dots_t *dd);
int render(cairo_t *cr);
int activate();
int deactivate();
int in(double x, double y);
int set_on();
int set_off();
void tick();
int is_on();
void set_motion_state(uint8_t state);
private:
dingle_dots_t *dd;
uint8_t active;
uint8_t on;
uint8_t double_clicked_on;
uint8_t selected;
uint8_t hovered;
uint8_t motion_state;
uint8_t motion_state_to_off;
struct timespec motion_ts;
uint8_t tld_state;
GdkPoint selected_pos;
double r;
string label[NCHAR];
uint8_t midi_note;
uint8_t midi_channel;
color normal;
color playing;
};

int sound_shape_init(sound_shape *ss, char *label,
uint8_t midi_note, uint8_t midi_channel, double x, double y, double r,
color *c, dingle_dots_t *dd);
int sound_shape_render(sound_shape *ss, cairo_t *cr);
int sound_shape_activate(sound_shape *ss);
int sound_shape_deactivate(sound_shape *ss);
int sound_shape_in(sound_shape *ss, double x, double y);
int sound_shape_on(sound_shape *ss);
int sound_shape_off(sound_shape *ss);
void sound_shape_tick(sound_shape *ss);
void sound_shape_set_motion_state(sound_shape *ss, uint8_t state);
int color_init(color *c, double r, double g, double b, double a);
color color_copy(color *c);
struct hsva rgb2hsv(color *c);
color hsv2rgb(struct hsva *in);
color color_lighten(color *in, double mag);
extern uint64_t next_z;

#endif
Loading

0 comments on commit ee7ac14

Please sign in to comment.