transition length popup rework
authorGood Guy <good1.2guy@gmail.com>
Sun, 24 Feb 2019 01:38:41 +0000 (18:38 -0700)
committerGood Guy <good1.2guy@gmail.com>
Sun, 24 Feb 2019 01:38:41 +0000 (18:38 -0700)
cinelerra-5.1/bld.sh
cinelerra-5.1/cinelerra/mtimebar.C
cinelerra-5.1/cinelerra/transitionpopup.C
cinelerra-5.1/cinelerra/transitionpopup.h
cinelerra-5.1/cinelerra/transitionpopup.inc
cinelerra-5.1/guicast/bctextbox.C
cinelerra-5.1/guicast/bctextbox.h

index f09b34a05881ca9d63b8cd2cb530f7f371b7f88f..7c8837bfbf9a6b4443f93c38c35299aad8851b4d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 ( ./autogen.sh
-  ./configure --with-single-user --with-booby --with-shuttle-usb
+  ./configure --with-single-user --with-booby
   make && make install ) 2>&1 | tee log
 mv Makefile Makefile.cfg
 cp Makefile.devel Makefile
index 8889cc87b47391b048175cf9c329f7377c6e453d..bf00a1b7e1a49f5e4ee0b94a245e9bd9876271b2 100644 (file)
@@ -657,10 +657,6 @@ void MTimeBar::activate_timeline()
 }
 
 
-
-
-
-
 TimeBarPopupItem::TimeBarPopupItem(MWindow *mwindow,
        TimeBarPopup *menu,
        const char *text,
@@ -683,11 +679,7 @@ int TimeBarPopupItem::handle_event()
 
 
 TimeBarPopup::TimeBarPopup(MWindow *mwindow)
- : BC_PopupMenu(0,
-               0,
-               0,
-               "",
-               0)
+ : BC_PopupMenu(0, 0, 0, "", 0)
 {
        this->mwindow = mwindow;
 }
@@ -700,47 +692,26 @@ TimeBarPopup::~TimeBarPopup()
 void TimeBarPopup::create_objects()
 {
        add_item(items[0] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_HMS_TEXT,
-               TIME_HMS));
+               this, TIME_HMS_TEXT, TIME_HMS));
        add_item(items[1] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_HMSF_TEXT,
-               TIME_HMSF));
+               this, TIME_HMSF_TEXT, TIME_HMSF));
        add_item(items[2] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_FRAMES_TEXT,
-               TIME_FRAMES));
+               this, TIME_FRAMES_TEXT, TIME_FRAMES));
        add_item(items[3] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_SAMPLES_TEXT,
-               TIME_SAMPLES));
+               this, TIME_SAMPLES_TEXT, TIME_SAMPLES));
        add_item(items[4] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_SAMPLES_HEX_TEXT,
-               TIME_SAMPLES_HEX));
+               this, TIME_SAMPLES_HEX_TEXT, TIME_SAMPLES_HEX));
        add_item(items[5] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_SECONDS_TEXT,
-               TIME_SECONDS));
+               this, TIME_SECONDS_TEXT, TIME_SECONDS));
        add_item(items[6] = new TimeBarPopupItem(mwindow,
-               this,
-               TIME_FEET_FRAMES_TEXT,
-               TIME_FEET_FRAMES));
+               this, TIME_FEET_FRAMES_TEXT, TIME_FEET_FRAMES));
 }
 
 void TimeBarPopup::update()
 {
-       for(int i = 0; i < TOTAL_TIMEFORMATS; i++)
-       {
-               if(items[i]->value == mwindow->edl->session->time_format)
-               {
-                       items[i]->set_checked(1);
-               }
-               else
-               {
-                       items[i]->set_checked(0);
-               }
+       int time_format = mwindow->edl->session->time_format;
+       for( int i=0; i<TOTAL_TIMEFORMATS; ++i ) {
+               items[i]->set_checked(items[i]->value == time_format);
        }
 }
 
index c5d82b4b1cf32cfc7c8e0b4688f02421870a295d..dd834d566221cfb7e8f25444b1285d31624e6570 100644 (file)
@@ -45,11 +45,11 @@ TransitionLengthThread::~TransitionLengthThread()
        close_window();
 }
 
-void TransitionLengthThread::start(Transition *transition,
-       double length)
+void TransitionLengthThread::start(Transition *transition, double length)
 {
        this->transition = transition;
-       this->length = this->orig_length = length;
+       this->orig_length = length;
+       this->new_length = length;
        BC_DialogThread::start();
 }
 
@@ -58,51 +58,94 @@ BC_Window* TransitionLengthThread::new_gui()
        BC_DisplayInfo display_info;
        int x = display_info.get_abs_cursor_x() - 150;
        int y = display_info.get_abs_cursor_y() - 50;
-       TransitionLengthDialog *gui = new TransitionLengthDialog(mwindow,
-               this,
-               x,
-               y);
+       TransitionLengthDialog *gui = new TransitionLengthDialog(mwindow, this, x, y);
        gui->create_objects();
        return gui;
 }
 
 void TransitionLengthThread::handle_close_event(int result)
 {
-       if(!result)
-       {
-               if(transition)
-               {
-                       mwindow->set_transition_length(transition, length);
-               }
+       if( !result ) {
+               if( transition )
+                       mwindow->set_transition_length(transition, new_length);
                else
-               {
-                       mwindow->set_transition_length(length);
+                       mwindow->set_transition_length(new_length);
+       }
+       else
+               update(orig_length);
+}
+
+int TransitionLengthThread::update(double length)
+{
+       if( !EQUIV(this->new_length, length) ) {
+               this->new_length = length;
+               if( transition ) {
+                       transition->length = transition->track->to_units(length, 1);
+                       mwindow->sync_parameters(CHANGE_EDL);
+                       mwindow->gui->lock_window();
+                       mwindow->gui->draw_overlays(1);
+                       mwindow->gui->unlock_window();
                }
        }
+       return 1;
 }
 
 
+TransitionUnitsItem::TransitionUnitsItem(TransitionUnitsPopup *popup,
+               const char *text, int id)
+ : BC_MenuItem(text)
+{
+        this->popup = popup;
+       this->id = id;
+}
 
+TransitionUnitsItem::~TransitionUnitsItem()
+{
+}
 
+int TransitionUnitsItem::handle_event()
+{
+       TransitionUnitsPopup *units_popup = (TransitionUnitsPopup *)get_popup_menu();
+       TransitionLengthDialog *gui = units_popup->gui;
+       TransitionLengthText *length_text = gui->text;
+       EDLSession *session = gui->mwindow->edl->session;
+       double length = gui->thread->new_length;
+       char text[BCSTRLEN];
+       units_popup->units = id;
+       Units::totext(text, length, units_popup->units, session->sample_rate,
+                       session->frame_rate, session->frames_per_foot);
+       length_text->update(text);
+       units_popup->set_text(get_text());
+       return 1;
+}
 
+TransitionUnitsPopup::TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y)
+ : BC_PopupMenu(x, y, 100, "", 1)
+{
+       this->gui = gui;
+       units = TIME_SECONDS;
+}
 
+TransitionUnitsPopup::~TransitionUnitsPopup()
+{
+}
 
+void TransitionUnitsPopup::create_objects()
+{
+       TransitionUnitsItem *units_item;
+       add_item(units_item = new TransitionUnitsItem(this, _("Seconds"), TIME_SECONDS));
+       add_item(new TransitionUnitsItem(this, _("Frames"), TIME_FRAMES));
+       add_item(new TransitionUnitsItem(this, _("Samples"), TIME_SAMPLES));
+       add_item(new TransitionUnitsItem(this, _("H:M:S.xxx"), TIME_HMS));
+       add_item(new TransitionUnitsItem(this, _("H:M:S:frm"), TIME_HMSF));
+       set_text(units_item->get_text());
+}
 
 
 TransitionLengthDialog::TransitionLengthDialog(MWindow *mwindow,
-       TransitionLengthThread *thread,
-       int x,
-       int y)
- : BC_Window(_(PROGRAM_NAME ": Transition length"),
-       x,
-       y,
-       300,
-       100,
-       -1,
-       -1,
-       0,
-       0,
-       1)
+       TransitionLengthThread *thread, int x, int y)
+ : BC_Window(_(PROGRAM_NAME ": Transition length"), x, y,
+               300, 100, -1, -1, 0, 0, 1)
 {
        this->mwindow = mwindow;
        this->thread = thread;
@@ -116,9 +159,12 @@ TransitionLengthDialog::~TransitionLengthDialog()
 void TransitionLengthDialog::create_objects()
 {
        lock_window("TransitionLengthDialog::create_objects");
-       add_subwindow(new BC_Title(10, 10, _("Seconds:")));
-       text = new TransitionLengthText(mwindow, this, 100, 10);
+       add_subwindow(units_popup = new TransitionUnitsPopup(this, 10, 10));
+       units_popup->create_objects();
+       text = new TransitionLengthText(mwindow, this, 160, 10);
        text->create_objects();
+       text->set_precision(3);
+       text->set_increment(0.1);
        add_subwindow(new BC_OKButton(this));
        add_subwindow(new BC_CancelButton(this));
        show_window();
@@ -132,21 +178,10 @@ int TransitionLengthDialog::close_event()
 }
 
 
-
-
-
-
 TransitionLengthText::TransitionLengthText(MWindow *mwindow,
-       TransitionLengthDialog *gui,
-       int x,
-       int y)
- : BC_TumbleTextBox(gui,
-       (float)gui->thread->length,
-       (float)0,
-       (float)100,
-       x,
-       y,
-       100)
+       TransitionLengthDialog *gui, int x, int y)
+ : BC_TumbleTextBox(gui, (float)gui->thread->new_length,
+               0.f, 100.f, x, y, 100)
 {
        this->mwindow = mwindow;
        this->gui = gui;
@@ -154,26 +189,49 @@ TransitionLengthText::TransitionLengthText(MWindow *mwindow,
 
 int TransitionLengthText::handle_event()
 {
-       double result = atof(get_text());
-       if(!EQUIV(result, gui->thread->length))
-       {
-               gui->thread->length = result;
-               mwindow->gui->lock_window();
-               mwindow->gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
-               mwindow->gui->unlock_window();
-       }
-
-       return 1;
+       const char *text = get_text();
+       int units = gui->units_popup->units;
+       EDLSession *session = gui->mwindow->edl->session;
+       double result = Units::text_to_seconds(text, session->sample_rate,
+               units, session->frame_rate, session->frames_per_foot);
+       return gui->thread->update(result);
 }
 
+int TransitionLengthText::handle_up_down(int dir)
+{
+       double delta = 0;
+       int units = gui->units_popup->units;
+       EDLSession *session = gui->mwindow->edl->session;
+       switch( units ) {
+       case TIME_SECONDS:
+       case TIME_HMS:
+               delta = 0.1;
+               break;
+       case TIME_HMSF:
+       case TIME_FRAMES:
+               delta = session->frame_rate > 0 ? 1./session->frame_rate : 0;
+               break;
+       case TIME_SAMPLES:
+               delta = session->sample_rate > 0 ? 1./session->sample_rate : 0;
+               break;
+       }
+       double length = gui->thread->new_length + delta * dir;
+       char text[BCSTRLEN];
+       Units::totext(text, length, units,
+               session->sample_rate, session->frame_rate,
+               session->frames_per_foot);
+       update(text);
+       return gui->thread->update(length);
+}
 
-
-
-
-
-
-
-
+int TransitionLengthText::handle_up_event()
+{
+       return handle_up_down(+1);
+}
+int TransitionLengthText::handle_down_event()
+{
+       return handle_up_down(-1);
+}
 
 
 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
@@ -203,7 +261,6 @@ void TransitionPopup::create_objects()
 int TransitionPopup::update(Transition *transition)
 {
        this->transition = transition;
-       this->length = transition->edit->track->from_units(transition->length);
        show->set_checked(transition->show);
        on->set_checked(transition->on);
        char len_text[50];
@@ -213,9 +270,6 @@ int TransitionPopup::update(Transition *transition)
 }
 
 
-
-
-
 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
  : BC_MenuItem(_("Attach..."))
 {
@@ -234,11 +288,6 @@ int TransitionPopupAttach::handle_event()
 }
 
 
-
-
-
-
-
 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
  : BC_MenuItem(_("Detach"))
 {
@@ -276,10 +325,6 @@ int TransitionPopupOn::handle_event()
 }
 
 
-
-
-
-
 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
  : BC_MenuItem(_("Show"))
 {
@@ -298,12 +343,6 @@ int TransitionPopupShow::handle_event()
 }
 
 
-
-
-
-
-
-
 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
  : BC_MenuItem(_("Length"))
 {
@@ -317,8 +356,9 @@ TransitionPopupLength::~TransitionPopupLength()
 
 int TransitionPopupLength::handle_event()
 {
-       popup->length_thread->start(popup->transition,
-               popup->length);
+       Transition *transition = popup->transition;
+       double length = transition->edit->track->from_units(transition->length);
+       popup->length_thread->start(popup->transition, length);
        return 1;
 }
 
index 1ac4154a20b59db30857204bc10fe30660399817..67498a32f7f2a472a2aada31567a83fec07f3466 100644 (file)
 #include "transition.inc"
 #include "transitionpopup.inc"
 
-class TransitionPopupOn;
-class TransitionPopupShow;
-class TransitionPopupAttach;
-class TransitionPopupDetach;
-class TransitionPopupLength;
-class TransitionLengthText;
+class TransitionUnitsItem : public BC_MenuItem
+{
+public:
+       TransitionUnitsItem(TransitionUnitsPopup *popup, const char *text, int id);
+       ~TransitionUnitsItem();
+
+       int handle_event();
+
+       TransitionUnitsPopup *popup;
+       int id;
+};
+
+class TransitionUnitsPopup : public BC_PopupMenu
+{
+public:
+       TransitionUnitsPopup(TransitionLengthDialog *gui, int x, int y);
+       ~TransitionUnitsPopup();
+
+       void create_objects();
+
+       TransitionLengthDialog *gui;
+       int units;
+};
+
 
 class TransitionLengthThread : public BC_DialogThread
 {
@@ -46,15 +64,15 @@ public:
                double length);
        BC_Window* new_gui();
        void handle_close_event(int result);
+       int update(double length);
 
        MWindow *mwindow;
 
        Transition *transition;
-       double length;
        double orig_length;
+       double new_length;
 };
 
-
 class TransitionLengthDialog : public BC_Window
 {
 public:
@@ -69,6 +87,7 @@ public:
 
        MWindow *mwindow;
        TransitionLengthThread *thread;
+       TransitionUnitsPopup *units_popup;
        TransitionLengthText *text;
        double length;
 };
@@ -81,6 +100,10 @@ public:
                int x,
                int y);
        int handle_event();
+       int handle_up_down(int dir);
+       int handle_up_event();
+       int handle_down_event();
+
        MWindow *mwindow;
        TransitionLengthDialog *gui;
 };
@@ -98,7 +121,6 @@ public:
 // Acquired through the update command as the plugin currently being operated on
 // Can't be dereferenced.
        Transition *transition;
-       double length;
 
 // Set when the user clicks a transition.
        MWindow *mwindow;
index fad8f7f7bbd105e80246add900f61b1c4b7636be..f2c655573ec00ec587247d2d55a845ae26bd43f1 100644 (file)
 #ifndef TRANSITIONPOPUP_INC
 #define TRANSITIONPOPUP_INC
 
+class TransitionUnitsItem;
+class TransitionUnitsPopup;
 class TransitionLengthThread;
+class TransitionLengthDialog;
+class TransitionLengthText;
 class TransitionPopup;
-
+class TransitionPopupAttach;
+class TransitionPopupDetach;
+class TransitionPopupShow;
+class TransitionPopupOn;
+class TransitionPopupLength;
 
 #endif
index c404877cced5fbcf885be1096435d7df3a5a21b9..725bbfa56683a9d46bd41e3e0dcb1f444ff6029a 100644 (file)
@@ -2628,17 +2628,6 @@ void BC_PopupTextBox::reposition_window(int x, int y)
 
 
 
-
-
-
-
-
-
-
-
-
-
-
 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
        int64_t default_value, int x, int y)
  : BC_TextBox(x, y, popup->text_w, 1, default_value)
@@ -2684,7 +2673,6 @@ int BC_TumbleTextBoxText::button_press_event()
 
 
 
-
 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
                int64_t default_value, int64_t min, int64_t max,
                int x, int y, int text_w)
@@ -2787,13 +2775,27 @@ int BC_TumbleTextBox::create_objects()
        x += textbox->get_w();
 
        tumbler = use_float ?
-               (BC_Tumbler *)new BC_FTumbler(textbox, min_f, max_f, x, y) :
-               (BC_Tumbler *)new BC_ITumbler(textbox, min, max, x, y);
+               (BC_Tumbler *)new BC_FTextTumbler(this, min_f, max_f, x, y) :
+               (BC_Tumbler *)new BC_ITextTumbler(this, min, max, x, y);
        parent_window->add_subwindow(tumbler);
        tumbler->set_increment(increment);
        return 0;
 }
 
+int BC_TumbleTextBox::handle_up_event()
+{
+       return use_float ?
+               ((BC_FTumbler *)tumbler)->BC_FTumbler::handle_up_event() :
+               ((BC_ITumbler *)tumbler)->BC_ITumbler::handle_up_event() ;
+}
+
+int BC_TumbleTextBox::handle_down_event()
+{
+       return use_float ?
+               ((BC_FTumbler *)tumbler)->BC_FTumbler::handle_down_event() :
+               ((BC_ITumbler *)tumbler)->BC_ITumbler::handle_down_event() ;
+}
+
 const char* BC_TumbleTextBox::get_text()
 {
        return textbox->get_text();
index 70c99003bc11a9704fa6f325d81d1cc718e2c9eb..fa569fa809a22f8b67572ea202d7bf1ccd15b8d7 100644 (file)
@@ -396,8 +396,11 @@ public:
 };
 
 
+class BC_TumbleTextBox;
 class BC_TumbleTextBoxText;
-class BC_TumbleTextBoxTumble;
+class BC_FTextTumbler;
+class BC_ITextTumbler;
+
 
 class BC_TumbleTextBox
 {
@@ -416,6 +419,8 @@ public:
        int create_objects();
        void reset();
        virtual int handle_event();
+       virtual int handle_up_event();
+       virtual int handle_down_event();
        const char* get_text();
        const wchar_t* get_wtext();
        BC_TextBox* get_textbox();
@@ -438,7 +443,8 @@ public:
        void set_tooltip(const char *text);
 
        friend class BC_TumbleTextBoxText;
-       friend class BC_TumbleTextBoxTumble;
+       friend class BC_FTextTumbler;
+       friend class BC_ITextTumbler;
 
 private:
        int x, y, text_w;
@@ -464,6 +470,36 @@ public:
        BC_TumbleTextBox *popup;
 };
 
+class BC_FTextTumbler : public BC_FTumbler
+{
+public:
+       BC_FTextTumbler(BC_TumbleTextBox *tumble_text,
+                       float min_f, float max_f, int x, int y)
+        : BC_FTumbler(tumble_text->textbox, min_f, max_f, x, y) {
+               this->tumble_text = tumble_text;
+       }
+       ~BC_FTextTumbler() {}
+       int handle_up_event() { return tumble_text->handle_up_event(); }
+       int handle_down_event() { return tumble_text->handle_down_event(); }
+
+       BC_TumbleTextBox *tumble_text;
+};
+
+class BC_ITextTumbler : public BC_ITumbler
+{
+public:
+       BC_ITextTumbler(BC_TumbleTextBox *tumble_text,
+                       int64_t min, int64_t max, int x, int y)
+        : BC_ITumbler(tumble_text->textbox, min, max, x, y) {
+               this->tumble_text = tumble_text;
+       }
+       ~BC_ITextTumbler() {}
+       int handle_up_event() { return tumble_text->handle_up_event(); }
+       int handle_down_event() { return tumble_text->handle_down_event(); }
+
+       BC_TumbleTextBox *tumble_text;
+};
+
 
 class BC_TextMenu : public BC_PopupMenu
 {