lumiera_/src/gui/panels/timeline-panel.cpp

358 lines
8.3 KiB
C++
Raw Normal View History

/*
2008-04-19 21:31:27 +02:00
timeline-panel.cpp - Implementation of the timeline panel
Copyright (C) Lumiera.org
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include <boost/foreach.hpp>
2008-05-17 19:12:07 +02:00
#include "../gtk-lumiera.hpp"
2008-04-19 21:31:27 +02:00
#include "timeline-panel.hpp"
2009-01-17 17:12:11 +01:00
#include "../workspace/workspace-window.hpp"
#include "../model/project.hpp"
2009-01-17 17:12:11 +01:00
#include "../controller/controller.hpp"
2008-08-16 23:06:46 +02:00
extern "C" {
#include "../../lib/time.h"
}
2008-05-22 20:19:04 +02:00
using namespace Gtk;
using namespace sigc;
2008-11-22 20:08:12 +01:00
using namespace std;
using namespace boost;
using namespace gui::widgets;
using namespace gui::model;
2008-05-22 20:19:04 +02:00
namespace gui {
namespace panels {
const int TimelinePanel::ZoomToolSteps = 2; // 2 seems comfortable
2009-01-17 17:12:11 +01:00
TimelinePanel::TimelinePanel(workspace::WorkspaceWindow
&workspace_window) :
Panel(workspace_window, "timeline", _("Timeline"), "panel_timeline"),
2008-12-30 13:35:58 +01:00
timeIndicator(),
2008-09-12 21:55:54 +02:00
previousButton(Stock::MEDIA_PREVIOUS),
rewindButton(Stock::MEDIA_REWIND),
playPauseButton(Stock::MEDIA_PLAY),
2008-10-07 22:17:29 +02:00
stopButton(Stock::MEDIA_STOP),
2008-09-12 21:55:54 +02:00
forwardButton(Stock::MEDIA_FORWARD),
nextButton(Stock::MEDIA_NEXT),
arrowTool(Gtk::StockID("tool_arrow")),
iBeamTool(Gtk::StockID("tool_i_beam")),
zoomIn(Stock::ZOOM_IN),
zoomOut(Stock::ZOOM_OUT),
updatingToolbar(false),
currentTool(timeline::IBeam)
2008-11-22 20:08:12 +01:00
{
//timelineWidget.mouse_hover_signal().connect(
// mem_fun(this, &TimelinePanel::on_mouse_hover));
//timelineWidget.playback_period_drag_released_signal().connect(
// mem_fun(this, &TimelinePanel::on_playback_period_drag_released));
2008-11-22 17:43:24 +01:00
2008-11-22 20:08:12 +01:00
// Hook up notifications
2009-01-17 17:12:11 +01:00
workspace.get_project().get_sequences().signal_changed().connect(
2008-11-22 20:08:12 +01:00
mem_fun(this, &TimelinePanel::on_sequence_list_changed));
2008-11-22 17:43:24 +01:00
// Setup the notebook
notebook.signal_switch_page().connect(
mem_fun(this, &TimelinePanel::on_page_switched));
2008-11-22 17:43:24 +01:00
notebook.popup_enable();
// Setup the toolbar
2008-08-30 15:00:47 +02:00
timeIndicatorButton.set_label_widget(timeIndicator);
2008-09-12 21:55:54 +02:00
//toolbar.append(timeIndicatorButton);
2008-10-07 22:17:29 +02:00
2008-09-12 21:55:54 +02:00
toolbar.append(previousButton);
toolbar.append(rewindButton);
2008-10-07 22:17:29 +02:00
toolbar.append(playPauseButton,
mem_fun(this, &TimelinePanel::on_play_pause));
toolbar.append(stopButton,
mem_fun(this, &TimelinePanel::on_stop));
2008-09-12 21:55:54 +02:00
toolbar.append(forwardButton);
toolbar.append(nextButton);
2008-08-30 15:00:47 +02:00
toolbar.append(seperator1);
2008-10-07 22:17:29 +02:00
toolbar.append(arrowTool,
mem_fun(this, &TimelinePanel::on_arrow_tool));
toolbar.append(iBeamTool,
mem_fun(this, &TimelinePanel::on_ibeam_tool));
2008-09-12 21:55:54 +02:00
2008-08-30 15:00:47 +02:00
toolbar.append(seperator2);
2008-09-12 21:55:54 +02:00
toolbar.append(zoomIn, mem_fun(this, &TimelinePanel::on_zoom_in));
toolbar.append(zoomOut, mem_fun(this, &TimelinePanel::on_zoom_out));
2009-03-09 21:45:50 +01:00
toolbar.show_all();
panelBar.pack_start(toolbar, PACK_EXPAND_WIDGET);
// Add the notebook
pack_start(notebook, PACK_EXPAND_WIDGET);
2008-08-30 15:00:47 +02:00
// Set the initial UI state
update_notebook();
update_tool_buttons();
update_zoom_buttons();
2008-08-30 15:00:47 +02:00
show_time(0);
}
TimelinePanel::~TimelinePanel()
{
}
2008-10-07 22:17:29 +02:00
void
TimelinePanel::on_play_pause()
2009-01-17 17:12:11 +01:00
{
2008-10-07 22:17:29 +02:00
if(!is_playing())
{
play();
}
else
{
pause();
2008-10-07 22:17:29 +02:00
}
update_playback_buttons();
}
void
TimelinePanel::on_stop()
{
workspace.get_controller().get_playback_controller().stop();
update_playback_buttons();
2008-10-07 22:17:29 +02:00
}
void
TimelinePanel::on_arrow_tool()
{
set_tool(timeline::Arrow);
}
void
TimelinePanel::on_ibeam_tool()
{
set_tool(timeline::IBeam);
}
void
TimelinePanel::on_zoom_in()
{
TimelineWidget *const widget = get_current_page();
2008-12-26 19:58:29 +01:00
REQUIRE(widget != NULL);
widget->zoom_view(ZoomToolSteps);
update_zoom_buttons();
}
void
TimelinePanel::on_zoom_out()
{
TimelineWidget *const widget = get_current_page();
2008-12-26 19:58:29 +01:00
REQUIRE(widget != NULL);
widget->zoom_view(-ZoomToolSteps);
update_zoom_buttons();
}
void
TimelinePanel::on_page_switched(GtkNotebookPage*, guint)
{
// The page has changed. Update the UI for this new page
// Set the tool in the new page to be the same as the tool in the last
// page
set_tool(currentTool);
update_zoom_buttons();
}
2008-08-16 23:06:46 +02:00
void
TimelinePanel::on_mouse_hover(gavl_time_t time)
{
2008-12-30 13:35:58 +01:00
(void)time;
2008-10-07 22:17:29 +02:00
}
void
TimelinePanel::on_playback_period_drag_released()
{
//----- TEST CODE - this needs to set the playback point via the
// real backend
TimelineWidget *const widget = get_current_page();
2008-12-26 19:58:29 +01:00
REQUIRE(widget != NULL);
widget->get_state()->set_playback_point(
widget->get_state()->get_playback_period_start());
2008-10-07 22:17:29 +02:00
//----- END TEST CODE
play();
}
2008-11-22 20:08:12 +01:00
void
TimelinePanel::on_sequence_list_changed()
{
update_notebook();
}
void
TimelinePanel::update_notebook()
{
std::map<const model::Sequence*, shared_ptr<TimelineWidget> >
2008-12-06 19:15:08 +01:00
old_pages;
old_pages.swap(notebook_pages);
BOOST_FOREACH( shared_ptr< model::Sequence > sequence,
2009-01-17 17:12:11 +01:00
workspace.get_project().get_sequences() )
{
std::map<const model::Sequence*, shared_ptr<TimelineWidget> >::
iterator iterator = old_pages.find(sequence.get());
2008-11-22 20:08:12 +01:00
if(iterator != old_pages.end())
{
// This sequence has not been changed
// leave it in the new list
notebook_pages[iterator->first] = iterator->second;
old_pages.erase(iterator->first);
}
else
{
// This is a new sequence, add it in
shared_ptr< timeline::TimelineState > state(
new timeline::TimelineState(sequence));
shared_ptr< TimelineWidget > widget(
new TimelineWidget(state));
notebook_pages[sequence.get()] = widget;
notebook.append_page(*widget.get(), sequence->get_name());
notebook.set_tab_reorderable(*widget.get());
2008-11-22 20:08:12 +01:00
}
}
2008-11-22 20:08:12 +01:00
notebook.show_all_children();
}
2008-10-07 22:17:29 +02:00
void
TimelinePanel::update_playback_buttons()
{
playPauseButton.set_stock_id(is_playing() ?
Stock::MEDIA_PAUSE : Stock::MEDIA_PLAY);
2008-08-16 23:06:46 +02:00
}
void
TimelinePanel::update_tool_buttons()
{
if(!updatingToolbar)
2008-12-06 20:12:18 +01:00
{
updatingToolbar = true;
arrowTool.set_active(currentTool == timeline::Arrow);
iBeamTool.set_active(currentTool == timeline::IBeam);
updatingToolbar = false;
}
}
void
TimelinePanel::update_zoom_buttons()
{
TimelineWidget *const widget = get_current_page();
if(widget != NULL)
{
timeline::TimelineViewWindow &viewWindow =
widget->get_state()->get_view_window();
zoomIn.set_sensitive(viewWindow.get_time_scale() != 1);
zoomOut.set_sensitive(viewWindow.get_time_scale()
!= TimelineWidget::MaxScale);
}
}
2008-10-07 22:17:29 +02:00
void
TimelinePanel::play()
{
workspace.get_controller().get_playback_controller().play();
}
void
TimelinePanel::pause()
2008-10-07 22:17:29 +02:00
{
workspace.get_controller().get_playback_controller().pause();
2008-10-07 22:17:29 +02:00
}
bool
TimelinePanel::is_playing() const
{
return workspace.get_controller().get_playback_controller().
is_playing();
2008-10-07 22:17:29 +02:00
}
void
TimelinePanel::set_tool(timeline::ToolType tool)
{
if(updatingToolbar) return;
TimelineWidget *const widget = get_current_page();
if(widget != NULL)
{
currentTool = tool;
widget->set_tool(tool);
update_tool_buttons();
}
}
2008-08-30 15:00:47 +02:00
void
TimelinePanel::show_time(gavl_time_t time)
{
timeIndicator.set_text(lumiera_tmpbuf_print_time(time));
}
TimelineWidget*
TimelinePanel::get_current_page()
{
Notebook::PageList::iterator page_iterator = notebook.get_current();
if(!page_iterator) return NULL;
Widget* const widget = (*page_iterator).get_child();
REQUIRE(widget != NULL);
return (TimelineWidget*)widget;
}
2008-10-07 22:17:29 +02:00
bool
TimelinePanel::on_frame()
{
// TEST CODE!
/*const gavl_time_t point = timelineWidget.get_playback_point()
2008-10-07 22:17:29 +02:00
+ GAVL_TIME_SCALE / 25;
if(point < timelineWidget.get_playback_period_end())
{
show_time(point);
timelineWidget.set_playback_point(point);
}
else
on_stop();*/
2008-10-07 22:17:29 +02:00
return true;
}
} // namespace panels
} // namespace gui