From: Good Guy Date: Sun, 28 Jan 2018 23:57:48 +0000 (-0700) Subject: add waveform audio icons, clear vwdw on change_source X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=7b25542808937e46959c104a706b75f04b1215be;p=goodguy%2Fhistory.git add waveform audio icons, clear vwdw on change_source --- diff --git a/cinelerra-5.1/cinelerra/awindowgui.C b/cinelerra-5.1/cinelerra/awindowgui.C index ae74854b..9769b998 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.C +++ b/cinelerra-5.1/cinelerra/awindowgui.C @@ -54,6 +54,7 @@ #include "nestededls.h" #include "newfolder.h" #include "preferences.h" +#include "samples.h" #include "theme.h" #include "vframe.h" #include "vicon.h" @@ -211,6 +212,32 @@ AssetPicon::~AssetPicon() } } +void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color) +{ + int w = frame->get_w(), h = frame->get_h(); + int h1 = h-1, h2 = h/2, y = h2; + int rgb_color = frame->pixel_rgb; + for( int x=0,x1=0,x2=0; x max ) max = value; + } + int ctr = (min + max) / 2; + int y0 = (int)(h2 - ctr*h2); CLAMP(y0, 0,h1); + int y1 = (int)(h2 - min*h2); CLAMP(y1, 0,h1); + int y2 = (int)(h2 - max*h2); CLAMP(y2, 0,h1); + frame->pixel_rgb = line_color; + frame->draw_line(x,y1, x,y2); + frame->pixel_rgb = base_color; + frame->draw_line(x,y, x,y0); + y = y0; + } + frame->pixel_rgb = rgb_color; +} + void AssetPicon::reset() { plugin = 0; @@ -309,8 +336,69 @@ void AssetPicon::create_objects() } else if( asset->audio_data ) { - icon = gui->audio_icon; - icon_vframe = gui->audio_vframe; + if( mwindow->preferences->use_thumbnails ) { + gui->unlock_window(); + File *file = mwindow->audio_cache->check_out(asset, + mwindow->edl, + 1); + if( file ) { + pixmap_w = pixmap_h * 16/9; + icon_vframe = new VFrame(0, + -1, pixmap_w, pixmap_h, BC_RGB888, -1); + { char string[BCTEXTLEN]; + sprintf(string, _("Reading %s"), name); + mwindow->gui->lock_window("AssetPicon::create_objects 3"); + mwindow->gui->show_message(string); + mwindow->gui->unlock_window(); } + int sample_rate = asset->get_sample_rate(); + int channels = asset->get_audio_channels(); + if( channels > 2 ) channels = 2; + int64_t length = asset->get_audio_samples(); + double duration = (double)length / sample_rate; + float t = duration > 1 ? (logf(duration) / logf(3600.f)) : 0; + if( t > 1 ) t = 1; + float h = 300 * t, s = 1., v = 1.; + float r, g, b; // duration, 0..1hr == hue red..magenta + HSV::hsv_to_rgb(r,g,b, h,s,v); + int ih = icon_vframe->get_h()/8, iw = icon_vframe->get_w(); + int ir = r * 256; CLAMP(ir, 0,255); + int ig = g * 256; CLAMP(ig, 0,255); + int ib = b * 256; CLAMP(ib, 0,255); + unsigned char **rows = icon_vframe->get_rows(); + for( int y=0; y=0; ) { + file->set_channel(i); + file->set_audio_position(0); + file->read_samples(&samples, length); + draw_wave(icon_vframe, samples.get_data(), length, + base_colors[i], line_colors[i]); + } + mwindow->audio_cache->check_in(asset); + gui->lock_window("AssetPicon::create_objects 4"); + icon = new BC_Pixmap(gui, pixmap_w, pixmap_h); + icon->draw_vframe(icon_vframe, + 0, 0, pixmap_w, pixmap_h, 0, 0); + } + else { + gui->lock_window("AssetPicon::create_objects 5"); + icon = gui->audio_icon; + icon_vframe = gui->audio_vframe; + } + } + else { + icon = gui->audio_icon; + icon_vframe = gui->audio_vframe; + } + } struct stat st; mtime = !stat(asset->path, &st) ? st.st_mtime : 0; diff --git a/cinelerra-5.1/cinelerra/awindowgui.h b/cinelerra-5.1/cinelerra/awindowgui.h index 3068ac99..985b4a0e 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.h +++ b/cinelerra-5.1/cinelerra/awindowgui.h @@ -55,6 +55,8 @@ public: void create_objects(); void reset(); + void draw_wave(VFrame *frame, double *dp, int len, + int base_color, int line_color); MWindow *mwindow; AWindowGUI *gui; diff --git a/cinelerra-5.1/cinelerra/canvas.C b/cinelerra-5.1/cinelerra/canvas.C index 9f3ddc3b..aabe440d 100644 --- a/cinelerra-5.1/cinelerra/canvas.C +++ b/cinelerra-5.1/cinelerra/canvas.C @@ -883,6 +883,16 @@ void Canvas::update_refresh(VideoDevice *device, VFrame *output_frame) } +void Canvas::clear(int flush) +{ + if( refresh_frame ) + refresh_frame->clear_frame(); + BC_WindowBase *wdw = get_canvas(); + if( !wdw ) return; + wdw->set_bg_color(BLACK); + wdw->clear_box(0,0, wdw->get_w(), wdw->get_h()); + wdw->flash(flush); +} diff --git a/cinelerra-5.1/cinelerra/canvas.h b/cinelerra-5.1/cinelerra/canvas.h index c5d53703..89a7eb82 100644 --- a/cinelerra-5.1/cinelerra/canvas.h +++ b/cinelerra-5.1/cinelerra/canvas.h @@ -146,6 +146,7 @@ public: void update_refresh(VideoDevice *device, VFrame *output_frame); // Redraws the refresh_frame virtual void draw_refresh(int flush = 1) {}; + virtual void clear(int flush=1); // Get top left offset of canvas relative to output. // Normally negative. Can be positive if output is smaller than canvas. diff --git a/cinelerra-5.1/cinelerra/tracking.h b/cinelerra-5.1/cinelerra/tracking.h index 3947ac6d..71fd582f 100644 --- a/cinelerra-5.1/cinelerra/tracking.h +++ b/cinelerra-5.1/cinelerra/tracking.h @@ -64,7 +64,6 @@ public: int state; void show_playback_cursor(int64_t position); - int view_follows_playback; // Delay until startup Condition *startup_lock; MWindow *mwindow; diff --git a/cinelerra-5.1/cinelerra/vwindowgui.C b/cinelerra-5.1/cinelerra/vwindowgui.C index d6ab939d..a94e1767 100644 --- a/cinelerra-5.1/cinelerra/vwindowgui.C +++ b/cinelerra-5.1/cinelerra/vwindowgui.C @@ -104,6 +104,7 @@ void VWindowGUI::change_source(EDL *edl, const char *title) sprintf(string, _(PROGRAM_NAME ": Viewer")); lock_window("VWindowGUI::change_source"); + canvas->clear(); timebar->update(0); set_title(string); unlock_window();