add waveform audio icons, clear vwdw on change_source
authorGood Guy <good1.2guy@gmail.com>
Sun, 28 Jan 2018 23:57:48 +0000 (16:57 -0700)
committerGood Guy <good1.2guy@gmail.com>
Sun, 28 Jan 2018 23:57:48 +0000 (16:57 -0700)
cinelerra-5.1/cinelerra/awindowgui.C
cinelerra-5.1/cinelerra/awindowgui.h
cinelerra-5.1/cinelerra/canvas.C
cinelerra-5.1/cinelerra/canvas.h
cinelerra-5.1/cinelerra/tracking.h
cinelerra-5.1/cinelerra/vwindowgui.C

index ae74854b19e0517640e164b042943dc5a9c97b42..9769b99847f940811adaeacc8c5a47c32fd8901e 100644 (file)
@@ -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<w; ++x,x1=x2 ) {
+               double min = *dp, max = min;
+               x2 = (len * (x+1))/w;
+               for( int i=x1; i<x2; ++i ) {
+                       double value = *dp++;
+                       if( value < min ) min = value;
+                       if( value > 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<ih; ++y ) {
+                                               unsigned char *rp = rows[y];
+                                               for( int x=0; x<iw; rp+=3,++x ) {
+                                                       rp[0] = ir;  rp[1] = ig;  rp[2] = ib;
+                                               }
+                                       }
+                                       length = sample_rate;
+                                       Samples samples(length);
+                                       static int line_colors[2] = { GREEN, YELLOW };
+                                       static int base_colors[2] = { RED, PINK };
+                                       for( int i=channels; --i>=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;
index 3068ac99f00eb79164541d55807074fca08740d5..985b4a0ea99e42ca3ecaf492d863e1d148292501 100644 (file)
@@ -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;
index 9f3ddc3b6e7d6cac46b5520164eda2419e5603a0..aabe440de3c470bfd47a1865e0dfc732c7893a29 100644 (file)
@@ -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);
+}
 
 
 
index c5d53703a791cd34d9e6e6bd5b432ebcf04b9875..89a7eb8268e375b6686df39e319ef5e79f3c9cb7 100644 (file)
@@ -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.
index 3947ac6d3a3270cbd9666bbee53ea46267ef5083..71fd582f85056cebd4f3645800e37dc837c713bc 100644 (file)
@@ -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;
index d6ab939d0e6376ec0461c0a765dd61fa036e83d1..a94e176750392f3efdf8b29849b546095eaa4536 100644 (file)
@@ -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();