#include "bcsignals.h"
#include "bctimer.h"
#include "clip.h"
-#include "colors.h"
+#include "bccolors.h"
#include "cplayback.h"
#include "cursors.h"
#include "cwindowgui.h"
#include "keyframepopup.h"
#include "keyframes.h"
#include "keys.h"
+#include "labels.h"
#include "localsession.h"
#include "mainclock.h"
#include "maincursor.h"
render_timer = new Timer;
hourglass_enabled = 0;
timebar_position = -1;
+ snapped = 0;
}
TrackCanvas::~TrackCanvas()
int cursor_y = get_relative_cursor_y();
if( get_cursor_over_window() &&
- cursor_x >= 0 && cursor_y >= 0 &&
+ cursor_x >= 0 && cursor_y >= 0 &&
cursor_x < get_w() && cursor_y < get_h() )
{
//printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
// will be deleted by Edits::optimize if not used
double length = mwindow->edl->session->default_transition_length;
int64_t start = edit->startproject+edit->length;
- int64_t units = track->to_units(length, 1);
+ int64_t units = track->to_units(length, 1);
track->edits->create_silence(start, start+units);
continue;
}
double asset_duration = 0;
int64_t asset_length_units = 0;
int64_t position = 0;
-
+
if(mwindow->session->current_operation == DRAG_ASSET &&
mwindow->session->drag_assets->total) {
Indexable *indexable = mwindow->session->drag_assets->values[0];
if (video_length < 0) {
if(mwindow->edl->session->si_useduration)
video_length = mwindow->edl->session->si_duration;
- else
- video_length = 1.0 / mwindow->edl->session->frame_rate ;
+ else
+ video_length = 1.0 / mwindow->edl->session->frame_rate ;
}
asset_duration = video_length / indexable->get_frame_rate();
}
else {
printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
}
-
+
asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
position = drop_edit_position (&insertion, NULL, asset_length_units);
if( position == -1 ) {
result = 1;
break; // Do not do anything
}
-
+
double position_f = mwindow->session->track_highlighted->from_units(position);
Track *track = mwindow->session->track_highlighted;
// // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
// // Unfortunately, this is _a lot_ of work to do right
// printf("Problematic insertion\n");
-// mwindow->edl->tracks->clear(position_f,
+// mwindow->edl->tracks->clear(position_f,
// position_f + asset_duration, 0);
// }
mwindow->paste_assets(position_f, track, !insertion);
result = 1;
break; // Do not do anything
}
-
+
double position_f = mwindow->session->track_highlighted->from_units(position);
Track *track = mwindow->session->track_highlighted;
mwindow->move_edits(mwindow->session->drag_edits,
}
// Get the x coordinate
- x = Units::to_int64(position *
+ x = Units::to_int64(position *
mwindow->edl->session->sample_rate /
- mwindow->edl->local_session->zoom_sample) -
+ mwindow->edl->local_session->zoom_sample) -
mwindow->edl->local_session->view_start[pane->number];
double paste_position = -1.;
h = MIN(h, get_h() + 20);
if(w > 0 && h > 0)
{
- set_color(WHITE);
+ set_color(mwindow->preferences->highlight_inverse);
set_inverse();
//draw_rectangle(x, y, w, h);
draw_rectangle(x + 1, y + 1, w - 2, h - 2);
}
w = MIN(w, get_w() + 20);
h = MIN(h, get_h() + 20);
- set_color(WHITE);
+ set_color(mwindow->preferences->highlight_inverse);
set_inverse();
draw_rectangle(x, y, w, h);
draw_rectangle(x + 1, y + 1, w - 2, h - 2);
mwindow->edl->local_session->zoom_sample -
mwindow->edl->local_session->view_start[pane->number]);
//printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
- set_color(GREEN);
+ set_color(!snapped ? GREEN : (snapped=0, YELLOW));
set_inverse();
//printf("TrackCanvas::draw_drag_handle 3\n");
draw_line(pixel1, 0, pixel1, get_h());
//printf("TrackCanvas::draw_loop_points 7\n");
}
-void TrackCanvas::draw_brender_start()
+void TrackCanvas::draw_brender_range()
{
- if(mwindow->preferences->use_brender)
+ if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
+ if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
+ if( mwindow->edl->session->brender_end > 0 )
{
- int64_t x = Units::round(mwindow->edl->session->brender_start *
+ int64_t x1 = Units::round(mwindow->edl->session->brender_start *
+ mwindow->edl->session->sample_rate /
+ mwindow->edl->local_session->zoom_sample -
+ mwindow->edl->local_session->view_start[pane->number]);
+ if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
+ {
+ set_color(RED);
+ draw_line(x1, 0, x1, get_h());
+ }
+ int64_t x2 = Units::round(mwindow->edl->session->brender_end *
mwindow->edl->session->sample_rate /
mwindow->edl->local_session->zoom_sample -
mwindow->edl->local_session->view_start[pane->number]);
- if(MWindowGUI::visible(x, x + 1, 0, get_w()))
+ if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
{
set_color(RED);
- draw_line(x, 0, x, get_h());
+ draw_line(x2, 0, x2, get_h());
}
}
}
int grouptype = automation.autogrouptype(i, track);
if(draw) // Do dropshadow
result = do_float_autos(track, autos,
- cursor_x, cursor_y, draw,
+ cursor_x, cursor_y, draw,
buttonpress, 1, 1, MDGREY,
auto_keyframe, grouptype);
case Autos::AUTOMATION_TYPE_INT: {
if(draw) // Do dropshadow
result = do_int_autos(track, autos,
- cursor_x, cursor_y, draw,
+ cursor_x, cursor_y, draw,
buttonpress, 1, 1, MDGREY,
auto_keyframe);
result = do_int_autos(track, autos,
}
-void TrackCanvas::draw_floatauto(FloatAuto *current,
- int x,
- int y,
- int in_x,
- int in_y,
- int out_x,
- int out_y,
- int center_pixel,
+void TrackCanvas::draw_floatauto(FloatAuto *current,
+ int x,
+ int y,
+ int in_x,
+ int in_y,
+ int out_x,
+ int out_y,
+ int center_pixel,
int zoom_track,
int color)
{
draw_box(x1, y1, x2 - x1, y2 - y1);
}
-// show bezier control points (only) if this
+// show bezier control points (only) if this
// floatauto doesn't adjust it's tangents automatically
if(current->curve_mode != FloatAuto::FREE &&
current->curve_mode != FloatAuto::TFREE)
y += center_pixel;
cp_y += center_pixel;
-
+
// drawing the tangent as a dashed line...
int const dash = HANDLE_W;
int const gap = HANDLE_W / 2;
float sx = 3 * (cp_x - x) / 4.;
float ex = 0;
-
+
// q is the x displacement for a unit line of slope
float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
-
+
float dist = 1/q * sx;
if( dist > dash )
ex = sx - q * dash;
-
+
set_color(color);
- do {
+ do {
float sy = slope * sx, ey = slope * ex;
draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
sx = ex - q * gap;
}
-inline
+inline
float levered_position(float position, float ref_pos)
{
- if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
+ if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
return 0.0;
return ref_pos / position;
}
int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
- int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
+ int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
{
int result = 0;
if( WITHIN(x1,x2,y1,y2))
{ // cursor hits node
result = 1;
-
+
if(buttonpress && (buttonpress != 3))
{
INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
// could be ctrl-click or ctrl-drag
// click would cycle through tangent modes
((FloatAuto*)current)->toggle_curve_mode();
-
+
// drag will start dragging the tangent, if applicable
INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
mwindow->session->drag_handle = 0;
}
}
-
+
float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
// Test in control
#undef WITHIN
#undef INIT_DRAG
-// if(buttonpress)
-// printf("TrackCanvas::test_floatauto 2 drag_handle=%d ctrl_down=%d cursor_x=%d cursor_y=%d x1=%d x2=%d y1=%d y2=%d\n",
+// if(buttonpress)
+// printf("TrackCanvas::test_floatauto 2 drag_handle=%d ctrl_down=%d cursor_x=%d cursor_y=%d x1=%d x2=%d y1=%d y2=%d\n",
// mwindow->session->drag_handle,
// ctrl_down(),
// cursor_x,
{
Auto *current;
mwindow->undo->update_undo_before();
- current = mwindow->session->drag_auto = autos->insert_auto(position1);
+ double position = autos->track->from_units(position1);
+ position = mwindow->edl->align_to_frame(position, 0);
+ int64_t new_position = autos->track->to_units(position,0);
+ current = mwindow->session->drag_auto = autos->insert_auto(new_position);
((FloatAuto*)current)->set_value(value);
mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
mwindow->session->drag_start_position = current->position;
(int)ax, (int)ax2, cursor_x, cursor_y,
buttonpress, autogrouptype);
}
- if( draw )
+ if( draw )
draw_floatline(center_pixel,
(FloatAuto*)previous, (FloatAuto*)current,
(FloatAutos*)autos, unit_start, zoom_units, yscale,
// Loop points
draw_loop_points();
- draw_brender_start();
+ draw_brender_range();
// Highlighted areas
draw_highlighting();
void TrackCanvas::update_drag_handle()
{
double new_position;
+ int cursor_x = get_cursor_x();
new_position =
- (double)(get_cursor_x() +
+ (double)(cursor_x +
mwindow->edl->local_session->view_start[pane->number]) *
mwindow->edl->local_session->zoom_sample /
mwindow->edl->session->sample_rate;
+
new_position =
mwindow->edl->align_to_frame(new_position, 0);
+ if( ctrl_down() && alt_down() ) {
+#define snapper(v) do { \
+ double pos = (v); \
+ if( pos < 0 ) break; \
+ double dist = fabs(new_position - pos); \
+ if( dist >= snap_min ) break; \
+ snap_position = pos; snap_min = dist; \
+} while(0)
+ double snap_position = new_position;
+ double snap_min = DBL_MAX;
+ if( mwindow->edl->local_session->inpoint_valid() )
+ snapper(mwindow->edl->local_session->get_inpoint());
+ if( mwindow->edl->local_session->outpoint_valid() )
+ snapper(mwindow->edl->local_session->get_outpoint());
+ snapper(mwindow->edl->prev_edit(new_position));
+ snapper(mwindow->edl->next_edit(new_position));
+ Label *prev_label = mwindow->edl->labels->prev_label(new_position);
+ if( prev_label ) snapper(prev_label->position);
+ Label *next_label = mwindow->edl->labels->next_label(new_position);
+ if( next_label ) snapper(next_label->position);
+ int snap_x = snap_position * mwindow->edl->session->sample_rate /
+ mwindow->edl->local_session->zoom_sample -
+ mwindow->edl->local_session->view_start[pane->number];
+ if( abs(snap_x - cursor_x) < HANDLE_W ) {
+ snapped = 1;
+ new_position = snap_position;
+ }
+#undef snapper
+ }
if(new_position != mwindow->session->drag_position)
{
// not really editing the node, rather start editing the curve
// tangent is editable and drag movement is significant
if( (FloatAuto::FREE == current->curve_mode ||
- FloatAuto::TFREE==current->curve_mode) &&
+ FloatAuto::TFREE==current->curve_mode) &&
(fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
mwindow->session->drag_handle = x < 0 ? 1 : 2;
}
if(value != old_value || position != current->position) {
result = 1;
- float change = value - old_value;
+ float change = value - old_value;
current->adjust_to_new_coordinates(position, value);
synchronize_autos(change, current->autos->track, current, 0);
show_message(current, 1,", %.2f", current->get_value());
double position_f = current->autos->track->from_units(current->position);
double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
- mwindow->edl->local_session->get_selectionend(1)) /
+ mwindow->edl->local_session->get_selectionend(1)) /
2;
if(!shift_down())
{
//PluginAutos *pluginautos = (PluginAutos *)current->autos;
PluginSet *pluginset;
Plugin *plugin = 0;
-// figure out the correct pluginset & correct plugin
+// figure out the correct pluginset & correct plugin
int found = 0;
for(int i = 0; i < track->plugin_set.total; i++)
{
currentkeyframe;
currentkeyframe = (KeyFrame *) currentkeyframe->next)
{
- if (currentkeyframe == current)
+ if (currentkeyframe == current)
{
found = 1;
break;
}
-
+
}
- if (found) break;
+ if (found) break;
}
- if (found) break;
+ if (found) break;
}
mwindow->session->plugin_highlighted = plugin;
double position_f = current->autos->track->from_units(current->position);
double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
- mwindow->edl->local_session->get_selectionend(1)) /
+ mwindow->edl->local_session->get_selectionend(1)) /
2;
if(!shift_down())
{
switch(mwindow->session->current_operation)
{
case DRAG_FADE:
-
+
break;
}
}
int64_t track_x, track_y, track_w, track_h;
track_dimensions(track, track_x, track_y, track_w, track_h);
- if(button_press && get_buttonpress() == 3 &&
+ if(button_press && get_buttonpress() == RIGHT_BUTTON &&
cursor_y >= track_y && cursor_y < track_y + track_h) {
gui->edit_menu->update(track, 0);
gui->edit_menu->activate_menu();
mwindow->edl->local_session->zoom_sample /
mwindow->edl->session->sample_rate;
+ int cx, cy;
+ get_abs_cursor_xy(cx, cy);
+ cx -= mwindow->theme->get_image("clip_icon")->get_w() / 2,
+ cy -= mwindow->theme->get_image("clip_icon")->get_h() / 2;
gui->drag_popup = new BC_DragWindow(gui,
- mwindow->theme->get_image("clip_icon") /*,
- get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
- get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
+ mwindow->theme->get_image("clip_icon"), cx, cy);
result = 1;
}
frame = mwindow->theme->get_image("veffect_icon");
}
}
-
- gui->drag_popup = new BC_DragWindow(gui, frame /*,
- get_abs_cursor_x(0) - frame->get_w() / 2,
- get_abs_cursor_y(0) - frame->get_h() / 2 */);
+ int cx, cy;
+ get_abs_cursor_xy(cx, cy);
+ cx -= frame->get_w() / 2;
+ cy -= frame->get_h() / 2;
+ gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
break; }
case PLUGIN_SHAREDPLUGIN:
- case PLUGIN_SHAREDMODULE:
- gui->drag_popup = new BC_DragWindow(gui,
- mwindow->theme->get_image("clip_icon") /*,
- get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
- get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
- break;
+ case PLUGIN_SHAREDMODULE: {
+ VFrame *frame = mwindow->theme->get_image("clip_icon");
+ int cx, cy;
+ get_abs_cursor_xy(cx, cy);
+ cx -= frame->get_w() / 2;
+ cy -= frame->get_h() / 2;
+ gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
+ break; }
}
result = 1;
activate();
}
- if( get_buttonpress() == LEFT_BUTTON ) {
+ if( get_buttonpress() == LEFT_BUTTON &&
+ gui->mbuttons->transport->engine->command->command != STOP ) {
gui->unlock_window();
gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
gui->lock_window("TrackCanvas::button_press_event");
gui->flash_canvas(1);
}
}
+
return result;
}
int TrackCanvas::start_selection(double position)
{
int rerender = 0;
- position = mwindow->edl->align_to_frame(position, 0);
+ position = mwindow->edl->align_to_frame(position, 1);
// Extend a border
if(shift_down())
{
- double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
+ double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
mwindow->edl->local_session->get_selectionend(1)) / 2;
if(position < midpoint)
// Que the CWindow
rerender = 1;
}
-
+
return rerender;
}
double TrackCanvas::time_visible()
{
- return (double)get_w() *
- mwindow->edl->local_session->zoom_sample /
+ return (double)get_w() *
+ mwindow->edl->local_session->zoom_sample /
mwindow->edl->session->sample_rate;
}
FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
}
char string2[BCTEXTLEN];
- Units::totext(string2,
+ Units::totext(string2,
current->autos->track->from_units(current->position),
mwindow->edl->session->time_format,
mwindow->edl->session->sample_rate,
// else
// return gui->pane[BOTTOM_LEFT_PANE]->patchbay;
// }
-//
+//
// return 0;
// }