fix for undo compression bug, fix for 'o' in recsources win, titler alias=smooth
[goodguy/history.git] / cinelerra-5.1 / guicast / vicon.C
index deb3c57fd6370b1aa7af9b7d54ca4c88b8c01b9c..2bfedd9277b9a1465091361adafa7e1c757689a0 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "bctimer.h"
 #include "bcwindow.h"
-#include "colors.h"
+#include "bccolors.h"
 #include "keys.h"
 #include "mutex.h"
 #include "condition.h"
@@ -13,16 +13,22 @@ VIcon(int vw, int vh, double rate)
        this->vw = vw;
        this->vh = vh;
        this->frame_rate = rate;
-       this->cycle_start = 0;
-       this->age = 0;
-       this->seq_no = 0;
-       this->in_use = 1;
+
+       cycle_start = 0;
+       age = 0;
+       seq_no = 0;
+       in_use = 1;
+       hidden = 0;
+       audio_data = 0;
+       audio_size = 0;
+       playing_audio = 0;
 }
 
 VIcon::
 ~VIcon()
 {
        clear_images();
+       delete [] audio_data;
 }
 
 void VIcon::
@@ -76,7 +82,7 @@ VIconThread(BC_WindowBase *wdw, int vw, int vh)
        timer = new Timer();
        this->refresh_rate = VICON_RATE;
        done = 0;
-       interrupted = 1;
+       interrupted = -1;
 }
 
 VIconThread::
@@ -100,8 +106,9 @@ start_drawing()
        wdw->lock_window("VIconThread::start_drawing");
        if( view_win )
                wdw->set_active_subwindow(view_win);
-        if( interrupted )
+        if( interrupted < 0 )
                draw_lock->unlock();
+       interrupted = 0;
        wdw->unlock_window();
 }
 
@@ -110,7 +117,8 @@ stop_drawing()
 {
        wdw->lock_window("VIconThread::stop_drawing");
        set_view_popup(0);
-       interrupted = 1;
+       if( !interrupted )
+               interrupted = 1;
        wdw->unlock_window();
 }
 
@@ -130,6 +138,7 @@ int ViewPopup::button_press_event()
 bool VIconThread::
 visible(VIcon *vicon, int x, int y)
 {
+       if( vicon->hidden ) return false;
        int y0 = 0;
        int my = y + vicon->vh;
        if( my <= y0 ) return false;
@@ -166,9 +175,15 @@ void ViewPopup::draw_vframe(VFrame *frame)
 
 ViewPopup *VIconThread::new_view_window(VFrame *frame)
 {
-       int wx = viewing->get_vx() - view_w, rx = 0;
-       int wy = viewing->get_vy() - view_h, ry = 0;
-       wdw->get_root_coordinates(wx, wy, &rx, &ry);
+       BC_WindowBase *parent = wdw->get_parent();
+       XineramaScreenInfo *info = parent->get_xinerama_info(-1);
+       int cx = info ? info->x_org + info->width/2 : parent->get_root_w(0)/2;
+       int cy = info ? info->y_org + info->height/2 : parent->get_root_h(0)/2;
+       int vx = viewing->get_vx(), rx = 0;
+       int vy = viewing->get_vy(), ry = 0;
+       wdw->get_root_coordinates(vx, vy, &rx, &ry);
+       rx += (rx >= cx ? -view_w : viewing->vw);
+       ry += (ry >= cy ? -view_h : viewing->vh);
        ViewPopup *vwin = new ViewPopup(this, frame, rx, ry, view_w, view_h);
        wdw->set_active_subwindow(vwin);
        return vwin;
@@ -203,6 +218,8 @@ int VIconThread::del_vicon(VIcon *&vicon)
 
 void VIconThread::set_view_popup(VIcon *vicon)
 {
+       if( !vicon && this->vicon )
+               this->vicon->stop_audio();
        this->vicon = vicon;
 }
 
@@ -214,6 +231,7 @@ update_view()
                VFrame *frame = viewing->frame();
                view_win = new_view_window(frame);
                view_win->show_window();
+               vicon->start_audio();
        }
        wdw->set_active_subwindow(view_win);
        return 1;
@@ -260,9 +278,8 @@ run()
 {
        while(!done) {
                draw_lock->lock("VIconThread::run 0");
-               if( done ) break;;
+               if( done ) break;
                wdw->lock_window("BC_WindowBase::run 1");
-               interrupted = 0;
                drawing_started();
                reset_images();
                int64_t seq_no = 0, now = 0;
@@ -275,7 +292,11 @@ run()
                                now = timer->get_difference();
                                if( now >= draw_flash ) break;
                                draw(next);
-                               if( !next->seq_no ) next->cycle_start = now;
+                               if( !next->seq_no ) {
+                                       next->cycle_start = now;
+                                       if( next->playing_audio )
+                                               next->start_audio();
+                               }
                                int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate;
                                int count = ref_no - next->seq_no;
                                if( count < 1 ) count = 1;
@@ -316,6 +337,14 @@ run()
        }
 }
 
+
+void VIcon::init_audio(int audio_size)
+{
+       this->audio_size = audio_size;
+       audio_data = new uint8_t[audio_size];
+       memset(audio_data, 0, audio_size);
+}
+
 void VIcon::dump(const char *dir)
 {
        mkdir(dir,0777);