Skip to content

Commit

Permalink
Allow to clip/clap loop file start
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Mar 19, 2024
1 parent 72fa9eb commit 6e157fd
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 38 deletions.
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

BLUE = "\033[1;34m"
RED = "\033[1;31m"
NONE = "\033[0m"
include libxputty/Build/Makefile.base

NOGOAL := install all features

PASS := features

SUBDIR := src

Expand All @@ -10,18 +12,25 @@ SUBDIR := src
$(MAKECMDGOALS) recurse: $(SUBDIR)

check-and-reinit-submodules :
ifeq (,$(filter $(NOGOAL),$(MAKECMDGOALS)))
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
@if git submodule status 2>/dev/null | egrep -q '^[-]|^[+]' ; then \
echo $(RED)"INFO: Need to reinitialize git submodules"$(NONE); \
echo "$(red)INFO: Need to reinitialize git submodules$(reset)"; \
git submodule update --init; \
echo $(BLUE)"Done"$(NONE); \
else echo $(BLUE)"Submodule up to date"$(NONE); \
echo "$(blue)Done$(reset)"; \
else echo "$(blue) Submodule up to date$(reset)"; \
fi

clean:
endif
endif

libxputty: check-and-reinit-submodules
@exec $(MAKE) -j 1 -C $@ $(MAKECMDGOALS)
ifeq (,$(filter $(NOGOAL),$(MAKECMDGOALS)))
@exec $(MAKE) --no-print-directory -j 1 -C $@ $(MAKECMDGOALS)
endif

$(SUBDIR): libxputty
@exec $(MAKE) -j 1 -C $@ $(MAKECMDGOALS)
ifeq (,$(filter $(PASS),$(MAKECMDGOALS)))
@exec $(MAKE) --no-print-directory -j 1 -C $@ $(MAKECMDGOALS)
endif

features:
48 changes: 27 additions & 21 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
.PHONY : all debug nls gettext updatepot po clean install uninstall

all : check $(NAME)
@if [ -f ./$(BUILD_DIR)/$(EXEC_NAME) ]; then echo $(BLUE)"build finish, now run make install"; \
else echo $(RED)"sorry, build failed"; fi
@echo $(NONE)
@if [ -f ./$(BUILD_DIR)/$(EXEC_NAME) ]; then \
$(B_ECHO) "=================== DONE =======================$(reset)"; \
else \
$(R_ECHO) "sorry, build failed$(reset)"; \
fi

debug: CXXFLAGS = $(DEBUG_CXXFLAGS)
debug: all
Expand Down Expand Up @@ -100,23 +102,23 @@ po:
check :
@mkdir -p ./$(BUILD_DIR)
ifdef ARMCPU
@echo $(RED)ARM CPU DEDECTED, please check the optimization flags
@echo $(NONE)
@(R_ECHO) "ARM CPU DEDECTED, please check the optimization flags $(reset)"
endif

clean :
@rm -f ./$(BUILD_DIR)/$(EXEC_NAME)
@rm -rf ./$(BUILD_DIR)
@echo ". ." $(BLUE)", clean up"$(NONE)
@$(ECHO) ". . , clean up$(reset)"

install :
ifneq ("$(wildcard ./$(BUILD_DIR))","")
mkdir -p $(DESTDIR)$(BIN_DIR)
cp ./$(BUILD_DIR)/$(EXEC_NAME) $(DESTDIR)$(BIN_DIR)/$(EXEC_NAME)
mkdir -p $(DESTDIR)$(DESKAPPS_DIR)
cp $(NAME).desktop $(DESTDIR)$(DESKAPPS_DIR)
mkdir -p $(DESTDIR)$(PIXMAPS_DIR)
cp $(NAME).svg $(DESTDIR)$(PIXMAPS_DIR)
@$(B_ECHO) "Install Mamba$(reset)"
$(QUIET)mkdir -p $(DESTDIR)$(BIN_DIR)
$(QUIET)cp ./$(BUILD_DIR)/$(EXEC_NAME) $(DESTDIR)$(BIN_DIR)/$(EXEC_NAME)
$(QUIET)mkdir -p $(DESTDIR)$(DESKAPPS_DIR)
$(QUIET)cp $(NAME).desktop $(DESTDIR)$(DESKAPPS_DIR)
$(QUIET)mkdir -p $(DESTDIR)$(PIXMAPS_DIR)
$(QUIET)cp $(NAME).svg $(DESTDIR)$(PIXMAPS_DIR)
@if [ ${LANGW} -gt 1 ]; then \
for lang in $(LANGS) ; \
do \
Expand All @@ -131,10 +133,10 @@ ifneq ("$(wildcard ./$(BUILD_DIR))","")
cp $(LANGS)/$(EXEC_NAME).mo $(DESTDIR)$(SHARE_DIR)/$(LANGS); \
fi \
fi
update-desktop-database || true
@echo ". ." $(BLUE)", done"$(NONE)
$(QUIET)update-desktop-database || true
@$(B_ECHO) "=================== DONE =======================$(reset)"
else
@echo ". ." $(BLUE)", you must build first"$(NONE)
@$(B_ECHO) ". . , you must build first$(reset)"
endif

uninstall :
Expand All @@ -143,23 +145,27 @@ uninstall :
@rm -rf $(DESTDIR)$(PIXMAPS_DIR)/$(NAME).svg
@rm -rf $(DESTDIR)$(PIXMAPS_DIR)/$(NAME).png
@rm -rf $(addprefix $(SHARE_DIR)/, $(MSGOBJS))
@echo ". ." $(BLUE)", done"$(NONE)
@$(B_ECHO) "=================== DONE =======================$(reset)"

./$(BUILD_DIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@
@$(ECHO) "Building object file $@ $(reset)"
$(QUIET)$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@

./$(BUILD_DIR)/%.o: $(LIBSCALA_DIR)%.cpp
$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@
@$(ECHO) "Building object file $@ $(reset)"
$(QUIET)$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@

./$(BUILD_DIR)/%.o: %.c
$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@
@$(ECHO) "Building object file $@ $(reset)"
$(QUIET)$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $< -o $@

-include $(OBJ_FILES:%.o=%.d)
-include $(SOBJ_FILES:%.o=%.d)
-include $(COBJ_FILES:%.o=%.d)

$(NAME) : $(OBJ_FILES) $(SOBJ_FILES) $(COBJ_FILES)
$(CXX) $(CXXFLAGS) -o ./$(BUILD_DIR)/$(EXEC_NAME) $(OBJ_FILES) $(SOBJ_FILES) $(COBJ_FILES) $(INCFLAGS) $(LDFLAGS) $(LXPUTTY)
$(NAME) : $(OBJ_FILES) $(SOBJ_FILES) $(COBJ_FILES)
@$(B_ECHO) "Compiling $(NAME) $(reset)"
$(QUIET)$(CXX) $(CXXFLAGS) -o ./$(BUILD_DIR)/$(EXEC_NAME) $(OBJ_FILES) $(SOBJ_FILES) $(COBJ_FILES) $(INCFLAGS) $(LDFLAGS) $(LXPUTTY)

doc:
#pass
107 changes: 100 additions & 7 deletions src/MidiKeyBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,17 +1175,34 @@ void XKeyBoard::init_ui(Xputty *app) {
songbpm->func.key_press_callback = key_press;
songbpm->func.key_release_callback = key_release;

time_line = add_label(proc_box,_("--"),610,10,100,20);
tmp = mamba_add_keyboard_button(proc_box, _("-"), 645, 0, 15, 15);
tmp->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
tmp->func.value_changed_callback = clips_time;
tmp->func.key_press_callback = key_press;
tmp->func.key_release_callback = key_release;
tmp = mamba_add_keyboard_button(proc_box, _("+"), 660, 0, 15, 15);
tmp->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
tmp->func.value_changed_callback = claps_time;
tmp->func.key_press_callback = key_press;
tmp->func.key_release_callback = key_release;

time_line = add_label(proc_box,_("--"),610,15,100,15);
time_line->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
snprintf(time_line->input_label, 31,"%.2f sec", xjack->get_max_loop_time());
time_line->label = time_line->input_label;
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->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
tmp->func.value_changed_callback = clip_time;
tmp->func.key_press_callback = key_press;
tmp->func.key_release_callback = key_release;
tmp = mamba_add_keyboard_button(proc_box, _("+"), 660, 30, 15, 15);
tmp->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
tmp->func.value_changed_callback = clap_time;
tmp->func.key_press_callback = key_press;
tmp->func.key_release_callback = key_release;

// middle box
int bpos = 70;
Expand Down Expand Up @@ -2469,17 +2486,89 @@ void XKeyBoard::sostenuto_callback(void *w_, void* user_data) noexcept{
}

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

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

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

// static
void XKeyBoard::clips_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_min_time_vector();
if (v > -1) {
const mamba::MidiEvent ev = xjmkb->xjack->rec.play[v][3];
double absoluteTime = ev.absoluteTime; // seconds
const double beat = 60.0/(double)xjmkb->song_bpm;
if ( absoluteTime-beat >= beat) {

for (int j = 0; j < 16; j++) {
for(std::vector<mamba::MidiEvent>::iterator i = xjmkb->xjack->rec.play[j].begin(); i != xjmkb->xjack->rec.play[j].end(); ++i) {
if (i == xjmkb->xjack->rec.play[j].begin()+2) {
if ((*i).deltaTime) (*i).deltaTime -= beat;
}
if ((*i).absoluteTime) (*i).absoluteTime -= beat;
}
}

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);
xjmkb->need_save = true;
}
}
}
adj_set_value(w->adj, 0.0);
}

// static
void XKeyBoard::claps_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_min_time_vector();
if (v > -1) {
const double beat = 60.0/(double)xjmkb->song_bpm;
for (int j = 0; j < 16; j++) {
for(std::vector<mamba::MidiEvent>::iterator i = xjmkb->xjack->rec.play[j].begin(); i != xjmkb->xjack->rec.play[j].end(); ++i) {
if (i == xjmkb->xjack->rec.play[j].begin()+2) {
if ((*i).deltaTime) (*i).deltaTime += beat;
}
if ((*i).absoluteTime) (*i).absoluteTime += beat;
}
}
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);
xjmkb->need_save = true;
}
}
adj_set_value(w->adj, 0.0);
}

inline int XKeyBoard::get_max_time_vector() noexcept {
int v = -1;
double max_loop_time = 0.0;
Expand All @@ -2494,46 +2583,50 @@ inline int XKeyBoard::get_max_time_vector() noexcept {
return v;
}

// static
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();
if (v > 0) {
if (v > -1) {
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;
const 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);
xjmkb->need_save = true;
}
}
}
adj_set_value(w->adj, 0.0);
}

// static
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();
if (v > 0) {
if (v > -1) {
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;
const 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);
xjmkb->need_save = true;
}
}
adj_set_value(w->adj, 0.0);
Expand Down
3 changes: 3 additions & 0 deletions src/MidiKeyBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ class XKeyBoard {
static void set_play_label(void *w_, void* user_data) noexcept;

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

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

Expand Down

0 comments on commit 6e157fd

Please sign in to comment.