diff --git a/Ratatouille.png b/Ratatouille.png index a5999f5..f792daf 100644 Binary files a/Ratatouille.png and b/Ratatouille.png differ diff --git a/Ratatouille/Ratatouille.c b/Ratatouille/Ratatouille.c index c08e9ce..91396e6 100644 --- a/Ratatouille/Ratatouille.c +++ b/Ratatouille/Ratatouille.c @@ -333,19 +333,19 @@ void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri) { asprintf(&ps->ir1.filepicker->filter ,"%s", ".wav"); ps->ir1.filepicker->use_filter = 1; - ps->ma.filebutton = add_lv2_file_button (ps->ma.filebutton, ui->win, -1, "Neural Model", ui, 25, 254, 60, 30); + ps->ma.filebutton = add_lv2_file_button (ps->ma.filebutton, ui->win, -1, "Neural Model", ui, 40, 258, 25, 25); ps->ma.filebutton->parent_struct = (void*)&ps->ma; ps->ma.filebutton->func.user_callback = file_load_response; - ps->mb.filebutton = add_lv2_file_button (ps->mb.filebutton, ui->win, -2, "Neural Model", ui, 25, 294, 60, 30); + ps->mb.filebutton = add_lv2_file_button (ps->mb.filebutton, ui->win, -2, "Neural Model", ui, 40, 298, 25, 25); ps->mb.filebutton->parent_struct = (void*)&ps->mb; ps->mb.filebutton->func.user_callback = file_load_response; - ps->ir.filebutton = add_lv2_irfile_button (ps->ir.filebutton, ui->win, -3, "IR File", ui, 25, 334, 60, 30); + ps->ir.filebutton = add_lv2_irfile_button (ps->ir.filebutton, ui->win, -3, "IR File", ui, 40, 338, 25, 25); ps->ir.filebutton->parent_struct = (void*)&ps->ir; ps->ir.filebutton->func.user_callback = file_load_response; - ps->ir1.filebutton = add_lv2_irfile_button (ps->ir1.filebutton, ui->win, -4, "IR File", ui, 25, 374, 60, 30); + ps->ir1.filebutton = add_lv2_irfile_button (ps->ir1.filebutton, ui->win, -4, "IR File", ui, 40, 378, 25, 25); ps->ir1.filebutton->parent_struct = (void*)&ps->ir1; ps->ir1.filebutton->func.user_callback = file_load_response; @@ -374,25 +374,25 @@ void plugin_create_controller_widgets(X11_UI *ui, const char * plugin_uri) { set_widget_color(ui->widget[1], 0, 0, 0.259, 0.518, 0.894, 1.0); set_widget_color(ui->widget[1], 0, 3, 0.686, 0.729, 0.773, 1.0); - ps->ma.fbutton = add_lv2_button(ps->ma.fbutton, ui->win, "", ui, 450, 254, 22, 30); + ps->ma.fbutton = add_lv2_button(ps->ma.fbutton, ui->win, "", ui, 435, 254, 22, 30); ps->ma.fbutton->parent_struct = (void*)&ps->ma; combobox_set_pop_position(ps->ma.fbutton, 0); combobox_add_entry(ps->ma.fbutton, "None"); ps->ma.fbutton->func.value_changed_callback = file_menu_callback; - ps->mb.fbutton = add_lv2_button(ps->mb.fbutton, ui->win, "", ui, 450, 294, 22, 30); + ps->mb.fbutton = add_lv2_button(ps->mb.fbutton, ui->win, "", ui, 435, 294, 22, 30); ps->mb.fbutton->parent_struct = (void*)&ps->mb; combobox_set_pop_position(ps->mb.fbutton, 0); combobox_add_entry(ps->mb.fbutton, "None"); ps->mb.fbutton->func.value_changed_callback = file_menu_callback; - ps->ir.fbutton = add_lv2_button(ps->ir.fbutton, ui->win, "", ui, 450, 334, 22, 30); + ps->ir.fbutton = add_lv2_button(ps->ir.fbutton, ui->win, "", ui, 435, 334, 22, 30); ps->ir.fbutton->parent_struct = (void*)&ps->ir; combobox_set_pop_position(ps->ir.fbutton, 0); combobox_add_entry(ps->ir.fbutton, "None"); ps->ir.fbutton->func.value_changed_callback = file_menu_callback; - ps->ir1.fbutton = add_lv2_button(ps->ir1.fbutton, ui->win, "", ui, 450, 374, 22, 30); + ps->ir1.fbutton = add_lv2_button(ps->ir1.fbutton, ui->win, "", ui, 435, 374, 22, 30); ps->ir1.fbutton->parent_struct = (void*)&ps->ir1; combobox_set_pop_position(ps->ir1.fbutton, 0); combobox_add_entry(ps->ir1.fbutton, "None"); diff --git a/Ratatouille/gx_convolver.cc b/Ratatouille/gx_convolver.cc index bfaa662..db9f5b4 100644 --- a/Ratatouille/gx_convolver.cc +++ b/Ratatouille/gx_convolver.cc @@ -481,7 +481,7 @@ void ConvolverWorker::set_priority() { fprintf(stderr, "ConvolverWorker: fail to set priority\n"); } #else - //system does not supports thread priority! + //system does not supports thread priority! #endif } @@ -510,6 +510,7 @@ void ConvolverWorker::run() { if (_execute.load(std::memory_order_acquire)) { _xr.doBackgroundProcessing(); _xr.co.notify_one(); + _xr.setWait.store(false, std::memory_order_release); } } // when done @@ -527,12 +528,10 @@ bool ConvolverWorker::is_running() const noexcept { void DoubleThreadConvolver::startBackgroundProcessing() { - //fprintf(stderr, "startBackgroundProcessing\n"); if (work.is_running()) { + timePoint = std::chrono::steady_clock::now() + timeoutPeriod; + setWait.store(true, std::memory_order_release); work.cv.notify_one(); - std::unique_lock lk(mo); - if (co.wait_until(lk, timePoint) == std::cv_status::timeout) - fprintf(stderr, "Convolver: overrun, time out!!\n"); } else { doBackgroundProcessing(); } @@ -541,8 +540,13 @@ void DoubleThreadConvolver::startBackgroundProcessing() void DoubleThreadConvolver::waitForBackgroundProcessing() { - timePoint = std::chrono::steady_clock::now() + timeoutPeriod; - //fprintf(stderr, "waitForBackgroundProcessing\n"); + if (setWait.load(std::memory_order_acquire)) { + if (work.is_running()) { + std::unique_lock lk(mo); + if (co.wait_until(lk, timePoint) == std::cv_status::timeout) + fprintf(stderr, "Convolver: overrun, time out!!\n"); + } + } } bool DoubleThreadConvolver::get_buffer(std::string fname, float **buffer, uint32_t *rate, int *asize) @@ -600,7 +604,7 @@ bool DoubleThreadConvolver::get_buffer(std::string fname, float **buffer, uint32 bool DoubleThreadConvolver::configure(std::string fname, float gain, unsigned int delay, unsigned int offset, - unsigned int length, unsigned int size, unsigned int bufsize) + unsigned int length, unsigned int size, unsigned int bufsize) { float* abuf = NULL; uint32_t arate = 0; diff --git a/Ratatouille/gx_convolver.h b/Ratatouille/gx_convolver.h index 4b28950..a91f19f 100644 --- a/Ratatouille/gx_convolver.h +++ b/Ratatouille/gx_convolver.h @@ -232,7 +232,8 @@ class DoubleThreadConvolver: public ConvolverBase, public fftconvolver::TwoStage DoubleThreadConvolver() : resamp(), ready(false), samplerate(0), work(*this) { - timeoutPeriod = std::chrono::microseconds(2000);} + timeoutPeriod = std::chrono::microseconds(2000); + setWait.store(false, std::memory_order_release);} ~DoubleThreadConvolver() { reset(); work.stop();} @@ -247,6 +248,7 @@ class DoubleThreadConvolver: public ConvolverBase, public fftconvolver::TwoStage uint32_t buffersize; uint32_t samplerate; ConvolverWorker work; + std::atomic setWait; std::chrono::time_point timePoint; std::chrono::microseconds timeoutPeriod; bool get_buffer(std::string fname, float **buffer, uint32_t* rate, int* size); diff --git a/Ratatouille/lv2_plugin.cc b/Ratatouille/lv2_plugin.cc index 8e8f997..bc6e988 100644 --- a/Ratatouille/lv2_plugin.cc +++ b/Ratatouille/lv2_plugin.cc @@ -152,35 +152,35 @@ static void draw_window(void *w_, void* user_data) { cairo_stroke (w->crb); cairo_set_source_rgba(w->crb, 0.1, 0.1, 0.1, 1); - round_rectangle(w->crb, 90 * w->app->hdpi, 254 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, 0.5); + round_rectangle(w->crb, 30 * w->app->hdpi, 254 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, 0.5); cairo_fill_preserve (w->crb); - boxShadowInset(w->crb,90 * w->app->hdpi,254 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, true); + boxShadowInset(w->crb,30 * w->app->hdpi,254 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, true); cairo_fill (w->crb); cairo_set_source_rgba(w->crb, 0.1, 0.1, 0.1, 1); - round_rectangle(w->crb, 90 * w->app->hdpi, 294 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, 0.5); + round_rectangle(w->crb, 30 * w->app->hdpi, 294 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, 0.5); cairo_fill_preserve (w->crb); - boxShadowInset(w->crb,90 * w->app->hdpi,294 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, true); + boxShadowInset(w->crb,30 * w->app->hdpi,294 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, true); cairo_fill (w->crb); cairo_set_source_rgba(w->crb, 0.1, 0.1, 0.1, 1); - round_rectangle(w->crb, 90 * w->app->hdpi, 334 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, 0.5); + round_rectangle(w->crb, 30 * w->app->hdpi, 334 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, 0.5); cairo_fill_preserve (w->crb); - boxShadowInset(w->crb,90 * w->app->hdpi,334 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, true); + boxShadowInset(w->crb,30 * w->app->hdpi,334 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, true); cairo_fill (w->crb); cairo_set_source_rgba(w->crb, 0.1, 0.1, 0.1, 1); - round_rectangle(w->crb, 90 * w->app->hdpi, 374 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, 0.5); + round_rectangle(w->crb, 30 * w->app->hdpi, 374 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, 0.5); cairo_fill_preserve (w->crb); - boxShadowInset(w->crb,90 * w->app->hdpi,374 * w->app->hdpi, - 350 * w->app->hdpi, 30 * w->app->hdpi, true); + boxShadowInset(w->crb,30 * w->app->hdpi,374 * w->app->hdpi, + 440 * w->app->hdpi, 30 * w->app->hdpi, true); cairo_fill (w->crb); use_text_color_scheme(w, NORMAL_); @@ -590,7 +590,7 @@ void draw_my_button(void *w_, void* user_data) { if (!w->state && (int)w->adj_y->value) w->state = 3; - roundrec(w->crb,2.0, 4.0, width, height, height*0.33); + /* roundrec(w->crb,2.0, 4.0, width, height, height*0.33); if(w->state==0) { cairo_set_line_width(w->crb, 1.0); @@ -615,7 +615,7 @@ void draw_my_button(void *w_, void* user_data) { } else if (w->state==3) { roundrec(w->crb,3.0, 4.0, width, height, height*0.33); cairo_stroke(w->crb); - } + } */ float offset = 0.0; if(w->state==0) { @@ -677,6 +677,11 @@ static void my_fbutton_callback(void *w_, void* user_data) { if (!filebutton->w) { filebutton->w = open_file_dialog(w,filebutton->path,filebutton->filter); filebutton->w->flags |= HIDE_ON_DELETE; + if (strcmp(filebutton->filter, ".wav") == 0) { + widget_set_title(filebutton->w, _("File Selector - Select Impulse Response")); + } else { + widget_set_title(filebutton->w, _("File Selector - Select Neural Model")); + } #ifdef __linux__ Atom wmStateAbove = XInternAtom(w->app->dpy, "_NET_WM_STATE_ABOVE", 1 ); Atom wmNetWmState = XInternAtom(w->app->dpy, "_NET_WM_STATE", 1 ); @@ -703,6 +708,46 @@ static void my_fbutton_mem_free(void *w_, void* user_data) { filebutton = NULL; } +void draw_image_(Widget_t *w, int width_t, int height_t, float offset) { + int width, height; + os_get_surface_size(w->image, &width, &height); + //double half_width = (width/height >=2) ? width*0.5 : width; + double x = (double)width_t/(double)(width); + double y = (double)height_t/(double)height; + double x1 = (double)height/(double)height_t; + double y1 = (double)(width)/(double)width_t; + double off_set = offset*x1; + cairo_scale(w->crb, x,y); + cairo_set_source_surface (w->crb, w->image, off_set, off_set); + cairo_rectangle(w->crb,0, 0, height, height); + cairo_fill(w->crb); + cairo_scale(w->crb, x1,y1); +} + +void draw_i_button(void *w_, void* user_data) { + Widget_t *w = (Widget_t*)w_; + if (!w) return; + Metrics_t metrics; + os_get_window_metrics(w, &metrics); + int width = metrics.width-5; + int height = metrics.height-5; + if (!metrics.visible) return; + if (w->image) { + float offset = 0.0; + if(w->state==1 && ! (int)w->adj_y->value) { + offset = 1.0; + } else if(w->state==1) { + offset = 2.0; + } else if(w->state==2) { + offset = 2.0; + } else if(w->state==3) { + offset = 1.0; + } + + draw_image_(w, width, height,offset); + } +} + Widget_t *add_my_file_button(Widget_t *parent, int x, int y, int width, int height, const char* label, const char *path, const char *filter) { FileButton *filebutton = (FileButton*)malloc(sizeof(FileButton)); @@ -718,6 +763,7 @@ Widget_t *add_my_file_button(Widget_t *parent, int x, int y, int width, int heig fbutton->func.mem_free_callback = my_fbutton_mem_free; fbutton->func.value_changed_callback = my_fbutton_callback; fbutton->func.dialog_callback = my_fdialog_response; + fbutton->func.expose_callback = draw_i_button; return fbutton; } @@ -725,6 +771,7 @@ Widget_t *add_my_file_button(Widget_t *parent, int x, int y, int width, int heig Widget_t* add_lv2_file_button(Widget_t *w, Widget_t *p, PortIndex index, const char * label, X11_UI* ui, int x, int y, int width, int height) { w = add_my_file_button(p, x, y, width, height, "neural", "", ".nam|.aidax|.json"); + widget_get_png(w, LDVAR(neuraldir_png)); w->data = index; return w; } @@ -732,6 +779,7 @@ Widget_t* add_lv2_file_button(Widget_t *w, Widget_t *p, PortIndex index, const c Widget_t* add_lv2_irfile_button(Widget_t *w, Widget_t *p, PortIndex index, const char * label, X11_UI* ui, int x, int y, int width, int height) { w = add_my_file_button(p, x, y, width, height, "IR File", "", ".wav"); + widget_get_png(w, LDVAR(wavdir_png)); w->data = index; return w; } diff --git a/Ratatouille/resources/neuraldir.png b/Ratatouille/resources/neuraldir.png new file mode 100644 index 0000000..54700da Binary files /dev/null and b/Ratatouille/resources/neuraldir.png differ diff --git a/Ratatouille/resources/wavdir.png b/Ratatouille/resources/wavdir.png new file mode 100644 index 0000000..b86d674 Binary files /dev/null and b/Ratatouille/resources/wavdir.png differ diff --git a/makefile b/makefile index 4cdb767..112d549 100644 --- a/makefile +++ b/makefile @@ -38,5 +38,7 @@ endif clean: @rm -f ./libxputty/xputty/resources/texture.png + @rm -f ./libxputty/xputty/resources/wavdir.png + @rm -f ./libxputty/xputty/resources/neuraldir.png features: