From: Good Guy Date: Sun, 24 Feb 2019 01:38:41 +0000 (-0700) Subject: transition length popup rework X-Git-Tag: 2019-08~97 X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=55b362978e0118efc34c0a654b19c99484c0f346;p=goodguy%2Fcinelerra.git transition length popup rework --- diff --git a/cinelerra-5.1/bld.sh b/cinelerra-5.1/bld.sh index f09b34a0..7c8837bf 100755 --- a/cinelerra-5.1/bld.sh +++ b/cinelerra-5.1/bld.sh @@ -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 diff --git a/cinelerra-5.1/cinelerra/mtimebar.C b/cinelerra-5.1/cinelerra/mtimebar.C index 8889cc87..bf00a1b7 100644 --- a/cinelerra-5.1/cinelerra/mtimebar.C +++ b/cinelerra-5.1/cinelerra/mtimebar.C @@ -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; iset_checked(items[i]->value == time_format); } } diff --git a/cinelerra-5.1/cinelerra/transitionpopup.C b/cinelerra-5.1/cinelerra/transitionpopup.C index c5d82b4b..dd834d56 100644 --- a/cinelerra-5.1/cinelerra/transitionpopup.C +++ b/cinelerra-5.1/cinelerra/transitionpopup.C @@ -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; } diff --git a/cinelerra-5.1/cinelerra/transitionpopup.h b/cinelerra-5.1/cinelerra/transitionpopup.h index 1ac4154a..67498a32 100644 --- a/cinelerra-5.1/cinelerra/transitionpopup.h +++ b/cinelerra-5.1/cinelerra/transitionpopup.h @@ -29,12 +29,30 @@ #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; diff --git a/cinelerra-5.1/cinelerra/transitionpopup.inc b/cinelerra-5.1/cinelerra/transitionpopup.inc index fad8f7f7..f2c65557 100644 --- a/cinelerra-5.1/cinelerra/transitionpopup.inc +++ b/cinelerra-5.1/cinelerra/transitionpopup.inc @@ -22,8 +22,16 @@ #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 diff --git a/cinelerra-5.1/guicast/bctextbox.C b/cinelerra-5.1/guicast/bctextbox.C index c404877c..725bbfa5 100644 --- a/cinelerra-5.1/guicast/bctextbox.C +++ b/cinelerra-5.1/guicast/bctextbox.C @@ -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(); diff --git a/cinelerra-5.1/guicast/bctextbox.h b/cinelerra-5.1/guicast/bctextbox.h index 70c99003..fa569fa8 100644 --- a/cinelerra-5.1/guicast/bctextbox.h +++ b/cinelerra-5.1/guicast/bctextbox.h @@ -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 {