X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fvwindowgui.C;h=bc423328da44ebbc7c42b767fdd12c8837439a13;hp=6bd71b1f5a6c307478d70b1a83f048b295be1a7c;hb=d60a59baa6cfe24c0fb153ed9e150a834ba29feb;hpb=30bdb85eb33a8ee7ba675038a86c6be59c43d7bd diff --git a/cinelerra-5.1/cinelerra/vwindowgui.C b/cinelerra-5.1/cinelerra/vwindowgui.C index 6bd71b1f..bc423328 100644 --- a/cinelerra-5.1/cinelerra/vwindowgui.C +++ b/cinelerra-5.1/cinelerra/vwindowgui.C @@ -19,10 +19,12 @@ * */ +#include "arender.h" #include "asset.h" #include "assets.h" #include "awindowgui.h" #include "awindow.h" +#include "cache.h" #include "canvas.h" #include "clip.h" #include "clipedit.h" @@ -44,9 +46,12 @@ #include "mwindow.h" #include "playtransport.h" #include "preferences.h" +#include "renderengine.h" +#include "samples.h" #include "theme.h" #include "timebar.h" #include "tracks.h" +#include "transportque.h" #include "vframe.h" #include "vplayback.h" #include "vtimebar.h" @@ -76,6 +81,7 @@ VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow) meters = 0; // source = 0; strcpy(loaded_title, ""); + highlighted = 0; } VWindowGUI::~VWindowGUI() @@ -90,6 +96,48 @@ VWindowGUI::~VWindowGUI() // delete source; } +void VWindowGUI::draw_wave() +{ + TransportCommand command; + command.command = NORMAL_FWD; + command.get_edl()->copy_all(vwindow->get_edl()); + command.change_type = CHANGE_ALL; + command.realtime = 0; + RenderEngine *render_engine = new RenderEngine(0, mwindow->preferences, 0, 0); + CICache *cache = new CICache(mwindow->preferences); + render_engine->set_acache(cache); + render_engine->arm_command(&command); + + double duration = 1.; + int w = mwindow->edl->session->output_w; + int h = mwindow->edl->session->output_h; + VFrame *vframe = new VFrame(w, h, BC_RGB888); + vframe->clear_frame(); + int sample_rate = mwindow->edl->get_sample_rate(); + int channels = mwindow->edl->session->audio_channels; + if( channels > 2 ) channels = 2; + int64_t bfrsz = sample_rate * duration; + Samples *samples[MAXCHANNELS]; + int ch = 0; + while( ch < channels ) samples[ch++] = new Samples(bfrsz); + while( ch < MAXCHANNELS ) samples[ch++] = 0; + render_engine->arender->process_buffer(samples, bfrsz, 0); + + static int line_colors[2] = { GREEN, YELLOW }; + static int base_colors[2] = { RED, PINK }; + for( int i=channels; --i>=0; ) { + AssetPicon::draw_wave(vframe, samples[i]->get_data(), bfrsz, + base_colors[i], line_colors[i]); + } + + for( int i=channels; --i>=0; ) delete samples[i]; + delete render_engine; + delete cache; + delete canvas->refresh_frame; + canvas->refresh_frame = vframe; + canvas->draw_refresh(1); +} + void VWindowGUI::change_source(EDL *edl, const char *title) { //printf("VWindowGUI::change_source %d\n", __LINE__); @@ -103,6 +151,11 @@ void VWindowGUI::change_source(EDL *edl, const char *title) sprintf(string, _(PROGRAM_NAME ": Viewer")); lock_window("VWindowGUI::change_source"); + canvas->clear(); + if( edl && + !edl->tracks->playable_video_tracks() && + edl->tracks->playable_audio_tracks() ) + draw_wave(); timebar->update(0); set_title(string); unlock_window(); @@ -113,70 +166,44 @@ void VWindowGUI::change_source(EDL *edl, const char *title) void VWindowGUI::update_sources(const char *title) { lock_window("VWindowGUI::update_sources"); - -//printf("VWindowGUI::update_sources 1\n"); sources.remove_all_objects(); -//printf("VWindowGUI::update_sources 2\n"); - - - for(int i = 0; - i < mwindow->edl->clips.total; - i++) - { + for( int i=0; iedl->clips.size(); ++i ) { char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title; int exists = 0; - for(int j = 0; j < sources.total; j++) - { - if(!strcasecmp(sources.values[j]->get_text(), clip_title)) - { + for( int j=0; !exists && jget_text(), clip_title) ) exists = 1; - } } - if(!exists) - { + if( !exists ) sources.append(new BC_ListBoxItem(clip_title)); - } } -//printf("VWindowGUI::update_sources 3\n"); FileSystem fs; - for(Asset *current = mwindow->edl->assets->first; - current; - current = NEXT) - { + for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) { char clip_title[BCTEXTLEN]; fs.extract_name(clip_title, current->path); int exists = 0; - for(int j = 0; j < sources.total; j++) - { - if(!strcasecmp(sources.values[j]->get_text(), clip_title)) - { + for( int j=0; !exists && jget_text(), clip_title) ) exists = 1; - } } - if(!exists) - { + if( !exists ) sources.append(new BC_ListBoxItem(clip_title)); - } } -//printf("VWindowGUI::update_sources 4\n"); - -// source->update_list(&sources); -// source->update(title); unlock_window(); } void VWindowGUI::create_objects() { + lock_window("VWindowGUI::create_objects"); in_point = 0; out_point = 0; - lock_window("VWindowGUI::create_objects"); set_icon(mwindow->theme->get_image("vwindow_icon")); //printf("VWindowGUI::create_objects 1\n"); @@ -346,12 +373,45 @@ int VWindowGUI::keypress_event() break; } if(!result) result = transport->keypress_event(); - return result; } +void VWindowGUI::stop_transport(const char *lock_msg) +{ + if( !transport->is_stopped() ) { + if( lock_msg ) unlock_window(); + transport->handle_transport(STOP, 1, 0, 0); + if( lock_msg ) lock_window(lock_msg); + } +} + int VWindowGUI::button_press_event() { + if( vwindow->get_edl() != 0 && canvas->get_canvas() && + mwindow->edl->session->vwindow_click2play && + canvas->get_canvas()->get_cursor_over_window() ) { + switch( get_buttonpress() ) { + case LEFT_BUTTON: + if( !vwindow->playback_engine->is_playing_back ) { + double length = vwindow->get_edl()->tracks->total_playable_length(); + double position = vwindow->playback_engine->get_tracking_position(); + if( position >= length ) transport->goto_start(); + } + return transport->forward_play->handle_event(); + case MIDDLE_BUTTON: + if( !vwindow->playback_engine->is_playing_back ) { + double position = vwindow->playback_engine->get_tracking_position(); + if( position <= 0 ) transport->goto_end(); + } + return transport->reverse_play->handle_event(); + case RIGHT_BUTTON: // activates popup + break; + case WHEEL_UP: + return transport->frame_forward_play->handle_event(); + case WHEEL_DOWN: + return transport->frame_reverse_play->handle_event(); + } + } if(canvas->get_canvas()) return canvas->button_press_event_base(canvas->get_canvas()); return 0; @@ -394,48 +454,31 @@ void VWindowGUI::drag_motion() // Window hidden if(get_hidden()) return; if(mwindow->session->current_operation != DRAG_ASSET) return; - - int old_status = mwindow->session->vcanvas_highlighted; - - int cursor_x = get_relative_cursor_x(); - int cursor_y = get_relative_cursor_y(); - - mwindow->session->vcanvas_highlighted = (get_cursor_over_window() && - cursor_x >= canvas->x && - cursor_x < canvas->x + canvas->w && - cursor_y >= canvas->y && - cursor_y < canvas->y + canvas->h); - - -//printf("VWindowGUI::drag_motion 1 %d %d %d %d %d\n", __LINE__, -// mwindow->session->vcanvas_highlighted, get_cursor_over_window(), cursor_x, cursor_y); - - if(old_status != mwindow->session->vcanvas_highlighted) - canvas->draw_refresh(); + int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0; + if( highlighted == need_highlight ) return; + highlighted = need_highlight; + canvas->draw_refresh(); } int VWindowGUI::drag_stop() { - if(get_hidden()) return 0; + if( get_hidden() ) return 0; - if(mwindow->session->vcanvas_highlighted && - mwindow->session->current_operation == DRAG_ASSET) - { - mwindow->session->vcanvas_highlighted = 0; + if( highlighted && + mwindow->session->current_operation == DRAG_ASSET ) { + highlighted = 0; canvas->draw_refresh(); - - Indexable *indexable = mwindow->session->drag_assets->size() ? - mwindow->session->drag_assets->get(0) : - 0; - EDL *edl = mwindow->session->drag_clips->size() ? - mwindow->session->drag_clips->get(0) : - 0; - - if(indexable) + unlock_window(); + + Indexable *indexable = + mwindow->session->drag_assets->size() > 0 ? + (Indexable *)mwindow->session->drag_assets->get(0) : + mwindow->session->drag_clips->size() > 0 ? + (Indexable *)mwindow->session->drag_clips->get(0) : 0; + if( indexable ) vwindow->change_source(indexable); - else - if(edl) - vwindow->change_source(edl); + + lock_window("VWindowGUI::drag_stop"); return 1; } @@ -488,34 +531,28 @@ int VWindowMeters::change_status_event(int new_status) } - - - - - VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow) - : EditPanel(mwindow, - vwindow->gui, - mwindow->theme->vedit_x, - mwindow->theme->vedit_y, + : EditPanel(mwindow, vwindow->gui, VWINDOW_ID, + mwindow->theme->vedit_x, mwindow->theme->vedit_y, EDITING_ARROW, - 0, - 0, - 1, - 1, - 0, - 0, - 1, - 0, - 0, - 0, + 0, // use_editing_mode + 0, // use_keyframe + 1, // use_splice + 1, // use_overwrite + 0, // use_lift + 0, // use_extract + 1, // use_copy + 0, // use_paste + 0, // use_undo + 0, // use_fit 0, // locklabels - 1, - 1, - 1, - 0, - 0, - 0) + 1, // use_labels + 1, // use_toclip + 1, // use_meters + 0, // use_cut + 0, // use_commerical + 0, // use_goto + 1) // use_clk2play { this->mwindow = mwindow; this->vwindow = vwindow; @@ -527,7 +564,7 @@ VWindowEditing::~VWindowEditing() void VWindowEditing::copy_selection() { - vwindow->copy(); + vwindow->copy(subwindow->shift_down()); } void VWindowEditing::splice_selection() @@ -535,7 +572,7 @@ void VWindowEditing::splice_selection() if(vwindow->get_edl()) { mwindow->gui->lock_window("VWindowEditing::splice_selection"); - mwindow->splice(vwindow->get_edl()); + mwindow->splice(vwindow->get_edl(), subwindow->shift_down()); mwindow->gui->unlock_window(); } } @@ -545,7 +582,7 @@ void VWindowEditing::overwrite_selection() if(vwindow->get_edl()) { mwindow->gui->lock_window("VWindowEditing::overwrite_selection"); - mwindow->overwrite(vwindow->get_edl()); + mwindow->overwrite(vwindow->get_edl(), subwindow->shift_down()); mwindow->gui->unlock_window(); } } @@ -561,7 +598,7 @@ void VWindowEditing::toggle_label() } } -void VWindowEditing::prev_label() +void VWindowEditing::prev_label(int cut) { if(vwindow->get_edl()) { @@ -591,7 +628,7 @@ void VWindowEditing::prev_label() } } -void VWindowEditing::next_label() +void VWindowEditing::next_label(int cut) { if(vwindow->get_edl()) { @@ -627,17 +664,15 @@ void VWindowEditing::next_label() double VWindowEditing::get_position() { EDL *edl = vwindow->get_edl(); - double position = !edl ? 0 : edl->local_session->get_selectionstart(1) + - edl->session->get_frame_offset() / edl->session->frame_rate; + double position = !edl ? 0 : edl->local_session->get_selectionstart(1); return position; } void VWindowEditing::set_position(double position) { EDL *edl = vwindow->get_edl(); - if( edl ) return; + if( !edl ) return; if( get_position() != position ) { - position -= edl->session->get_frame_offset() / edl->session->frame_rate; if( position < 0 ) position = 0; edl->local_session->set_selectionstart(position); edl->local_session->set_selectionend(position); @@ -655,73 +690,19 @@ void VWindowEditing::set_outpoint() vwindow->set_outpoint(); } -void VWindowEditing::clear_inpoint() +void VWindowEditing::unset_inoutpoint() { - vwindow->clear_inpoint(); + vwindow->unset_inoutpoint(); } -void VWindowEditing::clear_outpoint() -{ - vwindow->clear_outpoint(); -} void VWindowEditing::to_clip() { - if(vwindow->get_edl()) - { - FileXML file; - EDL *edl = vwindow->get_edl(); - double start = edl->local_session->get_selectionstart(); - double end = edl->local_session->get_selectionend(); - - if(EQUIV(start, end)) - { - end = edl->tracks->total_length(); - start = 0; - } - - - - edl->copy(start, - end, - 1, - 0, - 0, - &file, - "", - 1); - - - - - EDL *new_edl = new EDL(mwindow->edl); - new_edl->create_objects(); - new_edl->load_xml(&file, LOAD_ALL); - sprintf(new_edl->local_session->clip_title, - _("Clip %d"), mwindow->session->clip_number++); - char string[BCTEXTLEN]; - Units::totext(string, - end - start, - edl->session->time_format, - edl->session->sample_rate, - edl->session->frame_rate, - edl->session->frames_per_foot); - - sprintf(new_edl->local_session->clip_notes, - _("%s\n Created from:\n%s"), string, vwindow->gui->loaded_title); - - new_edl->local_session->set_selectionstart(0); - new_edl->local_session->set_selectionend(0); - - -//printf("VWindowEditing::to_clip 1 %s\n", edl->local_session->clip_title); - new_edl->local_session->set_selectionstart(0.0); - new_edl->local_session->set_selectionend(0.0); - vwindow->clip_edit->create_clip(new_edl); - } + EDL *edl = vwindow->get_edl(); + if( !edl ) return; + mwindow->to_clip(edl, _("viewer window: "), subwindow->shift_down()); } - VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y) : BC_PopupTextBox(vwindow, &vwindow->sources, @@ -876,9 +857,15 @@ void VWindowCanvas::draw_refresh(int flush) } } +int VWindowCanvas::need_overlays() +{ + if( gui->highlighted ) return 1; + return 0; +} + void VWindowCanvas::draw_overlays() { - if(mwindow->session->vcanvas_highlighted) + if( gui->highlighted ) { get_canvas()->set_color(WHITE); get_canvas()->set_inverse(); @@ -898,262 +885,3 @@ void VWindowCanvas::set_fullscreen(int value) mwindow->session->vwindow_fullscreen = value; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#if 0 -void VWindowGUI::update_points() -{ - EDL *edl = vwindow->get_edl(); - -//printf("VWindowGUI::update_points 1\n"); - if(!edl) return; - -//printf("VWindowGUI::update_points 2\n"); - long pixel = (long)((double)edl->local_session->in_point / - edl->tracks->total_playable_length() * - (mwindow->theme->vtimebar_w - - 2 * - mwindow->theme->in_point[0]->get_w())) + - mwindow->theme->in_point[0]->get_w(); - -//printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point); - if(in_point) - { -//printf("VWindowGUI::update_points 3.1\n"); - if(edl->local_session->in_point >= 0) - { -//printf("VWindowGUI::update_points 4\n"); - if(edl->local_session->in_point != in_point->position || - in_point->pixel != pixel) - { - in_point->pixel = pixel; - in_point->reposition(); - } - -//printf("VWindowGUI::update_points 5\n"); - in_point->position = edl->local_session->in_point; - -//printf("VWindowGUI::update_points 6\n"); - if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) || - edl->equivalent(in_point->position, edl->local_session->get_selectionend(1))) - in_point->update(1); - else - in_point->update(0); -//printf("VWindowGUI::update_points 7\n"); - } - else - { - delete in_point; - in_point = 0; - } - } - else - if(edl->local_session->in_point >= 0) - { -//printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point); - add_subwindow(in_point = - new VWindowInPoint(mwindow, - 0, - this, - pixel, - edl->local_session->in_point)); -//printf("VWindowGUI::update_points 9\n"); - } -//printf("VWindowGUI::update_points 10\n"); - - pixel = (long)((double)edl->local_session->out_point / - (edl->tracks->total_playable_length() + 0.5) * - (mwindow->theme->vtimebar_w - - 2 * - mwindow->theme->in_point[0]->get_w())) + - mwindow->theme->in_point[0]->get_w() * - 2; - - if(out_point) - { - if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w) - { - if(edl->local_session->out_point != out_point->position || - out_point->pixel != pixel) - { - out_point->pixel = pixel; - out_point->reposition(); - } - out_point->position = edl->local_session->out_point; - - if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) || - edl->equivalent(out_point->position, edl->local_session->get_selectionend(1))) - out_point->update(1); - else - out_point->update(0); - } - else - { - delete out_point; - out_point = 0; - } - } - else - if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w) - { - add_subwindow(out_point = - new VWindowOutPoint(mwindow, - 0, - this, - pixel, - edl->local_session->out_point)); - } -} - - -void VWindowGUI::update_labels() -{ - EDL *edl = vwindow->get_edl(); - int output = 0; - - for(Label *current = edl->labels->first; - current; - current = NEXT) - { - long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample); - - if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w) - { -// Create new label - if(output >= labels.total) - { - LabelGUI *new_label; - add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position)); - labels.append(new_label); - } - else -// Reposition old label - if(labels.values[output]->pixel != pixel) - { - labels.values[output]->pixel = pixel; - labels.values[output]->position = current->position; - labels.values[output]->reposition(); - } - - if(mwindow->edl->local_session->get_selectionstart(1) <= current->position && - mwindow->edl->local_session->get_selectionend(1) >= current->position) - labels.values[output]->update(1); - else - if(labels.values[output]->get_value()) - labels.values[output]->update(0); - output++; - } - } - -// Delete excess labels - while(labels.total > output) - { - labels.remove_object(); - } -} - - - -VWindowInPoint::VWindowInPoint(MWindow *mwindow, - TimeBar *timebar, - VWindowGUI *gui, - long pixel, - double position) - : InPointGUI(mwindow, - timebar, - pixel, - position) -{ - this->gui = gui; -} - -int VWindowInPoint::handle_event() -{ - EDL *edl = gui->vwindow->get_edl(); - - if(edl) - { - double position = edl->align_to_frame(this->position, 0); - - edl->local_session->set_selectionstart(position); - edl->local_session->set_selectionend(position); - gui->timebar->update(1); - -// Que the VWindow - mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0); - } - return 1; -} - - - -VWindowOutPoint::VWindowOutPoint(MWindow *mwindow, - TimeBar *timebar, - VWindowGUI *gui, - long pixel, - double position) - : OutPointGUI(mwindow, - timebar, - pixel, - position) -{ - this->gui = gui; -} - -int VWindowOutPoint::handle_event() -{ - EDL *edl = gui->vwindow->get_edl(); - - if(edl) - { - double position = edl->align_to_frame(this->position, 0); - - edl->local_session->set_selectionstart(position); - edl->local_session->set_selectionend(position); - gui->timebar->update(1); - -// Que the VWindow - mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0); - } - - return 1; -} - - - -#endif -