2009-01-17 17:12:11 +01:00
|
|
|
/*
|
|
|
|
|
timeline-track.cpp - Implementation of the timeline track object
|
|
|
|
|
|
|
|
|
|
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 "playback-controller.hpp"
|
2009-01-17 17:53:01 +01:00
|
|
|
#include "../gtk-lumiera.hpp"
|
2009-01-17 17:12:11 +01:00
|
|
|
|
|
|
|
|
namespace gui {
|
|
|
|
|
namespace controller {
|
|
|
|
|
|
2009-01-18 17:17:39 +01:00
|
|
|
PlaybackController::PlaybackController() :
|
|
|
|
|
finish_playback_thread(false),
|
|
|
|
|
playing(false)
|
|
|
|
|
{
|
|
|
|
|
start_playback_thread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlaybackController::~PlaybackController()
|
|
|
|
|
{
|
|
|
|
|
mutex.lock();
|
|
|
|
|
finish_playback_thread = true;
|
|
|
|
|
mutex.unlock();
|
|
|
|
|
thread->join();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-17 17:12:11 +01:00
|
|
|
void
|
|
|
|
|
PlaybackController::play()
|
|
|
|
|
{
|
2009-01-18 17:17:39 +01:00
|
|
|
Glib::Mutex::Lock lock(mutex);
|
|
|
|
|
playing = true;
|
2009-01-17 18:37:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-01-18 17:17:39 +01:00
|
|
|
PlaybackController::pause()
|
2009-01-17 18:37:06 +01:00
|
|
|
{
|
2009-01-18 17:17:39 +01:00
|
|
|
Glib::Mutex::Lock lock(mutex);
|
|
|
|
|
playing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlaybackController::stop()
|
|
|
|
|
{
|
|
|
|
|
Glib::Mutex::Lock lock(mutex);
|
|
|
|
|
playing = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
PlaybackController::is_playing()
|
|
|
|
|
{
|
|
|
|
|
Glib::Mutex::Lock lock(mutex);
|
|
|
|
|
return playing;
|
2009-01-17 17:12:11 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-18 17:17:39 +01:00
|
|
|
void
|
|
|
|
|
PlaybackController::start_playback_thread()
|
2009-01-17 17:53:01 +01:00
|
|
|
{
|
2009-01-18 17:17:39 +01:00
|
|
|
dispatcher.connect(sigc::mem_fun(this, &PlaybackController::on_frame));
|
|
|
|
|
thread = Glib::Thread::create (sigc::mem_fun(
|
|
|
|
|
this, &PlaybackController::playback_thread), true);
|
2009-01-17 17:53:01 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-18 17:17:39 +01:00
|
|
|
void
|
|
|
|
|
PlaybackController::attach_viewer(
|
|
|
|
|
const sigc::slot<void, void*>& on_frame)
|
2009-01-17 17:53:01 +01:00
|
|
|
{
|
2009-01-18 17:17:39 +01:00
|
|
|
frame_signal.connect(on_frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlaybackController::playback_thread()
|
|
|
|
|
{
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
Glib::Mutex::Lock lock(mutex);
|
|
|
|
|
if(finish_playback_thread)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(is_playing())
|
|
|
|
|
pull_frame();
|
|
|
|
|
|
|
|
|
|
Glib::Thread::yield();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-17 18:37:06 +01:00
|
|
|
|
2009-01-18 17:17:39 +01:00
|
|
|
void
|
|
|
|
|
PlaybackController::pull_frame()
|
|
|
|
|
{
|
2009-01-17 18:37:06 +01:00
|
|
|
for(int i = 0; i < 320*240*4; i++)
|
|
|
|
|
buffer[i] = rand();
|
2009-01-18 17:17:39 +01:00
|
|
|
|
|
|
|
|
dispatcher.emit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PlaybackController::on_frame()
|
|
|
|
|
{
|
2009-01-17 18:37:06 +01:00
|
|
|
frame_signal.emit(buffer);
|
2009-01-17 17:53:01 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-17 17:12:11 +01:00
|
|
|
} // namespace controller
|
|
|
|
|
} // namespace gui
|
|
|
|
|
|