Skip to content

Commit

Permalink
Update libxputty
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Mar 18, 2024
1 parent 46fc696 commit 602cdb0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libxputty
Submodule libxputty updated 100 files
66 changes: 66 additions & 0 deletions src/MidiKeyBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,11 @@ void XKeyBoard::init_ui(Xputty *app) {
time_line->func.key_press_callback = key_press;
time_line->func.key_release_callback = key_release;

tmp = mamba_add_keyboard_button(proc_box, _("-"), 645, 30, 15, 15);
tmp->func.value_changed_callback = clip_time;
tmp = mamba_add_keyboard_button(proc_box, _("+"), 660, 30, 15, 15);
tmp->func.value_changed_callback = clap_time;

// middle box
int bpos = 70;
if (!view_program) bpos -= 45;
Expand Down Expand Up @@ -2469,6 +2474,67 @@ void XKeyBoard::find_next_beat_time(double *absoluteTime) {
(*absoluteTime) = (double)beats*beat;
}

void XKeyBoard::find_previus_beat_time(double *absoluteTime) {
double beat = 60.0/(double)song_bpm;
int beats = std::round((((*absoluteTime)-beat)/beat));
(*absoluteTime) = (double)beats*beat;
}

inline int XKeyBoard::get_max_time_vector() noexcept {
int v = -1;
double max_loop_time = 0.0;
for (int j = 0; j<16;j++) {
if (!xjack->rec.play[j].size()) continue;
const mamba::MidiEvent ev = xjack->rec.play[j][xjack->rec.play[j].size()-1];
if (ev.absoluteTime > max_loop_time) {
max_loop_time = ev.absoluteTime;
v = j;
}
}
return v;
}

void XKeyBoard::clip_time(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
XKeyBoard *xjmkb = XKeyBoard::get_instance(w);
int value = (int)adj_get_value(w->adj);
if (value > 0) {
int v = xjmkb->get_max_time_vector();
const mamba::MidiEvent ev = xjmkb->xjack->rec.play[v][xjmkb->xjack->rec.play[v].size()-1];
const mamba::MidiEvent prev = xjmkb->xjack->rec.play[v][xjmkb->xjack->rec.play[v].size()-2];
double deltaTime = ev.deltaTime; // seconds
double absoluteTime = ev.absoluteTime; // seconds
double beat = 60.0/(double)xjmkb->song_bpm;
if ( absoluteTime-beat > prev.absoluteTime) {
mamba::MidiEvent nev = {{0x80, 0, 0}, 3, deltaTime-beat, absoluteTime-beat};
xjmkb->xjack->rec.play[v][xjmkb->xjack->rec.play[v].size()-1] = nev;
snprintf(xjmkb->time_line->input_label, 31,"%.2f sec", xjmkb->xjack->get_max_loop_time());
xjmkb->time_line->label = xjmkb->time_line->input_label;
expose_widget(xjmkb->time_line);
}
}
adj_set_value(w->adj, 0.0);
}

void XKeyBoard::clap_time(void *w_, void* user_data) noexcept{
Widget_t *w = (Widget_t*)w_;
XKeyBoard *xjmkb = XKeyBoard::get_instance(w);
int value = (int)adj_get_value(w->adj);
if (value > 0) {
int v = xjmkb->get_max_time_vector();
const mamba::MidiEvent ev = xjmkb->xjack->rec.play[v][xjmkb->xjack->rec.play[v].size()-1];
double deltaTime = ev.deltaTime; // seconds
double absoluteTime = ev.absoluteTime; // seconds
double beat = 60.0/(double)xjmkb->song_bpm;
mamba::MidiEvent nev = {{0x80, 0, 0}, 3, deltaTime+beat, absoluteTime+beat};
xjmkb->xjack->rec.play[v][xjmkb->xjack->rec.play[v].size()-1] = nev;
snprintf(xjmkb->time_line->input_label, 31,"%.2f sec", xjmkb->xjack->get_max_loop_time());
xjmkb->time_line->label = xjmkb->time_line->input_label;
expose_widget(xjmkb->time_line);
}
adj_set_value(w->adj, 0.0);
}

// static
void XKeyBoard::record_callback(void *w_, void* user_data) {
Widget_t *w = (Widget_t*)w_;
Expand Down
5 changes: 5 additions & 0 deletions src/MidiKeyBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ class XKeyBoard {
static void draw_button(void *w_, void* user_data) noexcept;
static void set_play_label(void *w_, void* user_data) noexcept;

static void clip_time(void *w_, void* user_data) noexcept;
static void clap_time(void *w_, void* user_data) noexcept;
inline int get_max_time_vector() noexcept;

static void synth_ui_callback(void *w_, void* user_data);

static void chorus_type_callback(void *w_, void* user_data);
Expand Down Expand Up @@ -338,6 +342,7 @@ class XKeyBoard {
void pattern_in(Widget_t *w, Color_state st, int height);
void pattern_out(Widget_t *w, int height);
void find_next_beat_time(double *absoluteTime);
void find_previus_beat_time(double *absoluteTime);
void get_alsa_port_menu();
void nsm_show_ui();
void nsm_hide_ui();
Expand Down

0 comments on commit 602cdb0

Please sign in to comment.