X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;ds=sidebyside;f=cinelerra-5.1%2Fplugins%2Fmotion%2Fmotionwindow.C;h=b96bea48d301cc07a837363dfc95741d1677b2dc;hb=0be11f0132d5c50b4c073626fe092fdac34e09e5;hp=b8930e206f813f612a4292e9244c3cea9dfb1db5;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/plugins/motion/motionwindow.C b/cinelerra-5.1/plugins/motion/motionwindow.C index b8930e20..b96bea48 100644 --- a/cinelerra-5.1/plugins/motion/motionwindow.C +++ b/cinelerra-5.1/plugins/motion/motionwindow.C @@ -32,7 +32,7 @@ #include "pluginserver.h" MotionWindow::MotionWindow(MotionMain *plugin) - : PluginClientWindow(plugin, 800, 640, 800, 640, 0) + : PluginClientWindow(plugin, xS(800), yS(750), xS(800), yS(750), 0) { this->plugin = plugin; } @@ -43,36 +43,38 @@ MotionWindow::~MotionWindow() void MotionWindow::create_objects() { - int x = 10, y = 10; - int x1 = x, x2 = get_w() / 2; + int xs10 = xS(10), xs20 = xS(20), xs50 = xS(50), xs120 = xS(120); + int ys10 = yS(10), ys20 = yS(20), ys50 = yS(50), ys30 = yS(30), ys40 = yS(40); + int x = xs10, y = ys10; + int x2 = get_w() / 2; BC_Title *title; - add_subwindow(global = new MotionGlobal(plugin, this, x1, y)); + add_subwindow(global = new MotionGlobal(plugin, this, x, y)); add_subwindow(rotate = new MotionRotate(plugin, this, x2, y)); - y += 50; + y += ys50; - add_subwindow(title = new BC_Title(x1, y, + add_subwindow(title = new BC_Title(x, y, _("Translation search radius:\n(W/H Percent of image)"))); add_subwindow(global_range_w = new GlobalRange(plugin, - x1 + title->get_w() + 10, y, + x + title->get_w() + xs10, y, &plugin->config.global_range_w)); add_subwindow(global_range_h = new GlobalRange(plugin, - x1 + title->get_w() + 10 + global_range_w->get_w(), y, + x + title->get_w() + xs10 + global_range_w->get_w(), y, &plugin->config.global_range_h)); add_subwindow(title = new BC_Title(x2, y, _("Rotation search radius:\n(Degrees)"))); add_subwindow(rotation_range = new RotationRange(plugin, - x2 + title->get_w() + 10, y)); + x2 + title->get_w() + xs10, y)); - y += 50; - add_subwindow(title = new BC_Title(x1, y, + y += ys50; + add_subwindow(title = new BC_Title(x, y, _("Translation block size:\n(W/H Percent of image)"))); add_subwindow(global_block_w = - new BlockSize(plugin, x1 + title->get_w() + 10, y, + new BlockSize(plugin, x + title->get_w() + xs10, y, &plugin->config.global_block_w)); add_subwindow(global_block_h = - new BlockSize(plugin, x1 + title->get_w() + 10 + + new BlockSize(plugin, x + title->get_w() + xs10 + global_block_w->get_w(), y, &plugin->config.global_block_h)); @@ -80,126 +82,152 @@ void MotionWindow::create_objects() // y, // _("Rotation block size:\n(W/H Percent of image)"))); // add_subwindow(rotation_block_w = new BlockSize(plugin, -// x2 + title->get_w() + 10, +// x2 + title->get_w() + xs10, // y, // &plugin->config.rotation_block_w)); // add_subwindow(rotation_block_h = new BlockSize(plugin, -// x2 + title->get_w() + 10 + rotation_block_w->get_w(), +// x2 + title->get_w() + xs10 + rotation_block_w->get_w(), // y, // &plugin->config.rotation_block_h)); - y += 50; - add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:"))); + y += ys50; + add_subwindow(title = new BC_Title(x, y, _("Translation search steps:"))); add_subwindow(global_search_positions = - new GlobalSearchPositions(plugin, x1 + title->get_w() + 10, y, 80)); + new GlobalSearchPositions(plugin, x + title->get_w() + xs10, y, xs120)); global_search_positions->create_objects(); add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:"))); add_subwindow(rotation_search_positions = - new RotationSearchPositions(plugin, x2 + title->get_w() + 10, y, 80)); + new RotationSearchPositions(plugin, x2 + title->get_w() + xs10, y, xs120)); rotation_search_positions->create_objects(); - y += 50; + y += ys50; add_subwindow(title = new BC_Title(x, y, _("Translation direction:"))); add_subwindow(track_direction = new TrackDirection(plugin, this, - x + title->get_w() + 10, + x + title->get_w() + xs10, y)); track_direction->create_objects(); - y += 40; - add_subwindow(title = new BC_Title(x2, y, _("Tracking file:"))); - add_subwindow(tracking_file = new MotionTrackingFile(plugin, - plugin->config.tracking_file, this, x2+title->get_w() + 20, y)); - - int y1 = y; - add_subwindow(title = new BC_Title(x, y + 10, _("Block X:"))); + y += ys40; + add_subwindow(title = new BC_Title(x, y + ys10, _("Block X:"))); add_subwindow(block_x = - new MotionBlockX(plugin, this, x + title->get_w() + 10, y)); + new MotionBlockX(plugin, this, x + title->get_w() + xs10, y)); add_subwindow(block_x_text = new MotionBlockXText(plugin, this, - x + title->get_w() + 10 + block_x->get_w() + 10, y + 10)); + x + title->get_w() + xs10 + block_x->get_w() + xs10, y + ys10)); - y += 40; - add_subwindow(title = new BC_Title(x2, y, _("Rotation center:"))); + add_subwindow(title = new BC_Title(x2, y + ys10, _("Rotation center:"))); add_subwindow(rotation_center = - new RotationCenter(plugin, x2 + title->get_w() + 10, y)); + new RotationCenter(plugin, x2 + title->get_w() + xs10, y)); - y += 40; - add_subwindow(title = new BC_Title(x2, y + 10, _("Maximum angle offset:"))); - add_subwindow(rotate_magnitude = - new MotionRMagnitude(plugin, x2 + title->get_w() + 10, y)); - - y += 40; - add_subwindow(title = new BC_Title(x2, y + 10, _("Rotation settling speed:"))); - add_subwindow(rotate_return_speed = - new MotionRReturnSpeed(plugin, x2 + title->get_w() + 10, y)); - y += 40; - add_subwindow(vectors = new MotionDrawVectors(plugin, this, x2, y)); - - y = y1 + 60; - add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:"))); + y += ys40; + add_subwindow(title = new BC_Title(x, y + ys10, _("Block Y:"))); add_subwindow(block_y = - new MotionBlockY(plugin, this, x + title->get_w() + 10, y)); + new MotionBlockY(plugin, this, x + title->get_w() + xs10, y)); add_subwindow(block_y_text = new MotionBlockYText(plugin, this, - x + title->get_w() + 10 + block_y->get_w() + 10, y + 10)); + x + title->get_w() + xs10 + block_y->get_w() + xs10, y + ys10)); - y += 50; - add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:"))); + y += ys50; + add_subwindow(title = new BC_Title(x, y + ys10, _("Maximum absolute offset:"))); add_subwindow(magnitude = new MotionMagnitude(plugin, - x + title->get_w() + 10, + x + title->get_w() + xs10, y)); - y += 40; - add_subwindow(title = new BC_Title(x, y + 10, _("Motion settling speed:"))); + add_subwindow(title = new BC_Title(x2, y + ys10, _("Maximum angle offset:"))); + add_subwindow(rotate_magnitude = + new MotionRMagnitude(plugin, x2 + title->get_w() + xs10, y)); + + y += ys40; + add_subwindow(title = new BC_Title(x, y + ys10, _("Motion settling speed:"))); add_subwindow(return_speed = - new MotionReturnSpeed(plugin, x + title->get_w() + 10, y)); + new MotionReturnSpeed(plugin, x + title->get_w() + xs10, y)); - y += 40; + add_subwindow(title = new BC_Title(x2, y + ys10, _("Rotation settling speed:"))); + add_subwindow(rotate_return_speed = + new MotionRReturnSpeed(plugin, x2 + title->get_w() + xs10, y)); + + y += ys40; + add_subwindow(title = new BC_Title(x, y, _("Motion noise level:\n(% of max diff.)"))); + add_subwindow(noise_level = + new MotionNoiseLevel(plugin, this, x + title->get_w() + xs10, y)); + add_subwindow(noise_level_text = + new MotionNoiseLevelText(plugin, this, + x + title->get_w() + xs10 + noise_level->get_w() + xs10, y + ys10)); + + add_subwindow(title = new BC_Title(x2, y, _("Rotation noise level:\n(% of max diff.)"))); + add_subwindow(noise_rotation = + new MotionNoiseRotation(plugin, this, x2 + title->get_w() + xs10, y)); + add_subwindow(noise_rotation_text = + new MotionNoiseRotationText(plugin, this, + x2 + title->get_w() + xs10 + noise_rotation->get_w() + xs10, y + ys10)); + + y += ys50; + add_subwindow(vectors = new MotionDrawVectors(plugin, this, x, y)); + add_subwindow(twopass = new MotionTwopass(plugin, this, x2, y)); + + y += ys40; add_subwindow(track_single = new TrackSingleFrame(plugin, this, x, y)); - y += 20; - add_subwindow(track_previous = - new TrackPreviousFrame(plugin, this, x, y)); - y += 20; - add_subwindow(previous_same = - new PreviousFrameSameBlock(plugin, this, x, y)); - y += 40; - x1 = x; y1 = y; - add_subwindow(title = - new BC_Title(x1=x2, y1, _("Frame number:"))); + add_subwindow(title = new BC_Title(x2, y, _("Frame number:"))); add_subwindow(track_frame_number = - new TrackFrameNumber(plugin, this, x1 += title->get_w(), y1)); + new TrackFrameNumber(plugin, this, x2 + title->get_w() + xs10, y)); + add_subwindow(frame_current = + new MotionFrameCurrent(plugin, this, x2 + title->get_w() + track_frame_number->get_w() + xs20, y)); if(plugin->config.tracking_object != MotionScan::TRACK_SINGLE) + { track_frame_number->disable(); + frame_current->disable(); + } + + y += ys20; + add_subwindow(track_previous = + new TrackPreviousFrame(plugin, this, x, y)); + + y += ys20; + add_subwindow(previous_same = + new PreviousFrameSameBlock(plugin, this, x, y)); add_subwindow(addtrackedframeoffset = - new AddTrackedFrameOffset(plugin, this, x1=x2, y1+=track_frame_number->get_h())); - int pef = client->server->mwindow->edl->session->video_every_frame; - add_subwindow(pef_title = new BC_Title(x1=x2+50, y1+=addtrackedframeoffset->get_h() + 5, - !pef ? _("For best results\n" - " Set: Play every frame\n" - " Preferences-> Playback-> Video Out") : - _("Currently using: Play every frame"), MEDIUMFONT, - !pef ? RED : GREEN)); + new AddTrackedFrameOffset(plugin, this, x2, y)); + + y += ys40; + add_subwindow(title = new BC_Title(x, y, _("Tracking file:"))); + add_subwindow(tracking_file = new MotionTrackingFile(plugin, + plugin->config.tracking_file, this, x+title->get_w() + xs10, y)); + + add_subwindow(reset_tracking = + new MotionResetTracking(plugin, this, x2, y)); + y += ys40; add_subwindow(title = new BC_Title(x, y, _("Master layer:"))); add_subwindow(master_layer = new MasterLayer(plugin, - this, x + title->get_w() + 10, y)); + this, x + title->get_w() + xs10, y)); master_layer->create_objects(); - y += 30; + add_subwindow(clear_tracking = + new MotionClearTracking(plugin, this, x2, y - ys10)); + + y += ys30; add_subwindow(title = new BC_Title(x, y, _("Action:"))); add_subwindow(action_type = new ActionType(plugin, - this, x + title->get_w() + 10, y)); + this, x + title->get_w() + xs10, y)); action_type->create_objects(); - y += 30; + int pef = client->server->mwindow->edl->session->video_every_frame; + add_subwindow(pef_title = new BC_Title(x2+xs50, y, + !pef ? _("For best results\n" + " Set: Play every frame\n" + " Preferences-> Playback-> Video Out") : + _("Currently using: Play every frame"), MEDIUMFONT, + !pef ? RED : GREEN)); + + y += ys30; add_subwindow(title = new BC_Title(x, y, _("Calculation:"))); add_subwindow(tracking_type = new TrackingType(plugin, - this, x + title->get_w() + 10, y)); + this, x + title->get_w() + xs10, y)); tracking_type->create_objects(); show_window(1); @@ -214,6 +242,7 @@ void MotionWindow::update_mode() rotation_range->update(plugin->config.rotation_range, MIN_ROTATION, MAX_ROTATION); vectors->update(plugin->config.draw_vectors); + twopass->update(plugin->config.twopass); tracking_file->update(plugin->config.tracking_file); global->update(plugin->config.global); rotate->update(plugin->config.rotate); @@ -222,7 +251,7 @@ void MotionWindow::update_mode() MotionTrackingFile::MotionTrackingFile(MotionMain *plugin, const char *filename, MotionWindow *gui, int x, int y) - : BC_TextBox(x, y, 150, 1, filename) + : BC_TextBox(x, y, gui->get_w()/2-x-xS(10), 1, filename) { this->plugin = plugin; this->gui = gui; @@ -230,7 +259,92 @@ MotionTrackingFile::MotionTrackingFile(MotionMain *plugin, int MotionTrackingFile::handle_event() { - strcpy(plugin->config.tracking_file, get_text()); + strncpy(plugin->config.tracking_file, get_text(), sizeof(plugin->config.tracking_file)); + plugin->reset_cache_file(); + plugin->send_configure_change(); + return 1; +} + +MotionResetTracking::MotionResetTracking(MotionMain *plugin, MotionWindow *gui, int x, int y) + : BC_GenericButton(x, y, _("Generate tracking file name")) +{ + this->plugin = plugin; + this->gui = gui; +}; + +int MotionResetTracking::handle_event() +{ +// First of all, ensure closing current tracking file + plugin->reset_cache_file(); + +// Generate new tracking filename based on the asset filename + const char *sp = TRACKING_FILE; + char *cp = plugin->config.tracking_file, *ep = cp+sizeof(plugin->config.tracking_file)-1; + while( cp < ep && *sp != 0 ) *cp++ = *sp++; + if( cp < ep-1 && (sp=plugin->get_source_path()) ) { + *cp++ = '-'; + const char *bp = strrchr(sp,'/'); + if( bp ) sp = bp+1; + while( cp < ep && *sp != 0 ) { + *cp++ = (*sp>='a' && *sp<='z') || + (*sp>='A' && *sp<='Z') || + (*sp>='0' && *sp<='9') ? *sp : '_'; + ++sp; + } + } + *cp = 0; + + gui->tracking_file->update(plugin->config.tracking_file); + plugin->reset_cache_file(); + +// Revert tracking type to not using tracking file + if( plugin->config.tracking_type == MotionScan::LOAD || + plugin->config.tracking_type == MotionScan::SAVE ) + { + plugin->config.tracking_type = MotionScan::NO_CALCULATE; + gui->tracking_type->set_text(TrackingType::to_text(plugin->config.tracking_type)); + } + + plugin->send_configure_change(); + return 1; +} + +MotionClearTracking::MotionClearTracking(MotionMain *plugin, MotionWindow *gui, int x, int y) + : BC_GenericButton(x, y, _("Clear tracking file contents")) +{ + this->plugin = plugin; + this->gui = gui; +}; + +int MotionClearTracking::handle_event() +{ + char save_file[BCTEXTLEN]; + +// First of all, ensure closing current tracking file + plugin->reset_cache_file(); + +// Suffix .bak not allowed: reserved for intermediate tracking file copy + snprintf(save_file, sizeof(save_file), "%s.old", plugin->config.tracking_file); + ::rename(plugin->config.tracking_file, save_file); + +// Just for safety + ::remove(plugin->config.tracking_file); + plugin->reset_cache_file(); + + return 1; +} + +MotionFrameCurrent::MotionFrameCurrent(MotionMain *plugin, MotionWindow *gui, int x, int y) + : BC_GenericButton(x, y, _("Get current")) +{ + this->plugin = plugin; + this->gui = gui; +}; + +int MotionFrameCurrent::handle_event() +{ + plugin->config.track_frame = plugin->get_source_position(); + gui->track_frame_number->update(plugin->config.track_frame); plugin->send_configure_change(); return 1; } @@ -480,6 +594,21 @@ int MotionRotate::handle_event() return 1; } +MotionTwopass::MotionTwopass(MotionMain *plugin, + MotionWindow *gui, int x, int y) + : BC_CheckBox(x, y, plugin->config.twopass, _("Two pass tracking")) +{ + this->plugin = plugin; + this->gui = gui; +} + +int MotionTwopass::handle_event() +{ + plugin->config.twopass = get_value(); + plugin->send_configure_change(); + return 1; +} + MotionBlockX::MotionBlockX(MotionMain *plugin, MotionWindow *gui, int x, int y) @@ -522,7 +651,7 @@ int MotionBlockY::handle_event() MotionBlockXText::MotionBlockXText(MotionMain *plugin, MotionWindow *gui, int x, int y) - : BC_TextBox(x, y, 75, 1, (float)plugin->config.block_x) + : BC_TextBox(x, y, xS(75), 1, (float)plugin->config.block_x) { this->plugin = plugin; this->gui = gui; @@ -542,7 +671,7 @@ int MotionBlockXText::handle_event() MotionBlockYText::MotionBlockYText(MotionMain *plugin, MotionWindow *gui, int x, int y) - : BC_TextBox(x, y, 75, 1, (float)plugin->config.block_y) + : BC_TextBox(x, y, xS(75), 1, (float)plugin->config.block_y) { this->plugin = plugin; this->gui = gui; @@ -558,6 +687,89 @@ int MotionBlockYText::handle_event() } +MotionNoiseLevel::MotionNoiseLevel(MotionMain *plugin, + MotionWindow *gui, int x, int y) + : BC_FPot(x, y, plugin->config.noise_level, (float)0, (float)100) +{ + this->plugin = plugin; + this->gui = gui; +} + +int MotionNoiseLevel::handle_event() +{ + float level = plugin->config.noise_level; + level = get_value(); + if (level < 0) level = 0; + if (level > 100) level = 100; + plugin->config.noise_level = level; + gui->noise_level_text->update((float)plugin->config.noise_level); + plugin->send_configure_change(); + return 1; +} + +MotionNoiseLevelText::MotionNoiseLevelText(MotionMain *plugin, + MotionWindow *gui, int x, int y) + : BC_TextBox(x, y, xS(75), 1, (float)plugin->config.noise_level) +{ + this->plugin = plugin; + this->gui = gui; + set_precision(4); +} + +int MotionNoiseLevelText::handle_event() +{ + float level = plugin->config.noise_level; + level = atof(get_text()); + if (level < 0) level = 0; + if (level > 100) level = 100; + plugin->config.noise_level = level; + gui->noise_level->update(plugin->config.noise_level); + plugin->send_configure_change(); + return 1; +} + +MotionNoiseRotation::MotionNoiseRotation(MotionMain *plugin, + MotionWindow *gui, int x, int y) + : BC_FPot(x, y, plugin->config.noise_rotation, (float)0, (float)100) +{ + this->plugin = plugin; + this->gui = gui; +} + +int MotionNoiseRotation::handle_event() +{ + float level = plugin->config.noise_rotation; + level = get_value(); + if (level < 0) level = 0; + if (level > 100) level = 100; + plugin->config.noise_rotation = level; + gui->noise_rotation_text->update((float)plugin->config.noise_rotation); + plugin->send_configure_change(); + return 1; +} + +MotionNoiseRotationText::MotionNoiseRotationText(MotionMain *plugin, + MotionWindow *gui, int x, int y) + : BC_TextBox(x, y, xS(75), 1, (float)plugin->config.noise_rotation) +{ + this->plugin = plugin; + this->gui = gui; + set_precision(4); +} + +int MotionNoiseRotationText::handle_event() +{ + float level = plugin->config.noise_rotation; + level = atof(get_text()); + if (level < 0) level = 0; + if (level > 100) level = 100; + plugin->config.noise_rotation = level; + gui->noise_rotation->update(plugin->config.noise_rotation); + plugin->send_configure_change(); + return 1; +} + + MotionDrawVectors::MotionDrawVectors(MotionMain *plugin, MotionWindow *gui, int x, int y) : BC_CheckBox(x, @@ -596,6 +808,7 @@ int TrackSingleFrame::handle_event() gui->track_previous->update(0); gui->previous_same->update(0); gui->track_frame_number->enable(); + gui->frame_current->enable(); plugin->send_configure_change(); return 1; } @@ -604,7 +817,7 @@ TrackFrameNumber::TrackFrameNumber(MotionMain *plugin, MotionWindow *gui, int x, int y) - : BC_TextBox(x, y, 100, 1, plugin->config.track_frame) + : BC_TextBox(x, y, xS(100), 1, plugin->config.track_frame) { this->plugin = plugin; this->gui = gui; @@ -636,6 +849,7 @@ int TrackPreviousFrame::handle_event() gui->track_single->update(0); gui->previous_same->update(0); gui->track_frame_number->disable(); + gui->frame_current->disable(); plugin->send_configure_change(); return 1; } @@ -659,6 +873,7 @@ int PreviousFrameSameBlock::handle_event() gui->track_single->update(0); gui->track_previous->update(0); gui->track_frame_number->disable(); + gui->frame_current->disable(); plugin->send_configure_change(); return 1; } @@ -703,7 +918,7 @@ int MasterLayer::calculate_w(MotionWindow *gui) int result = 0; result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1))); - return result + 50; + return result + xS(80); } @@ -769,7 +984,7 @@ int ActionType::calculate_w(MotionWindow *gui) result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::STABILIZE_PIXEL))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::NOTHING))); - return result + 50; + return result + xS(80); } @@ -826,7 +1041,7 @@ int TrackingType::calculate_w(MotionWindow *gui) result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::CALCULATE))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::SAVE))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionScan::LOAD))); - return result + 50; + return result + xS(80); } @@ -875,6 +1090,6 @@ int TrackDirection::calculate_w(MotionWindow *gui) result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1))); result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0))); - return result + 50; + return result + xS(80); }