Move Clips for ClipTracks to the GUI model.

This commit is contained in:
Stefan Kangas 2011-01-02 10:40:17 +01:00 committed by Stefan Kangas
parent 3f4c7a5e46
commit 7500732976
7 changed files with 222 additions and 76 deletions

View file

@ -22,22 +22,39 @@
#include "clip-track.hpp"
#include "clip.hpp"
#include <boost/shared_ptr.hpp>
namespace gui {
namespace model {
ClipTrack::ClipTrack()
{
}
std::string
ClipTrack::print_track()
{
std::ostringstream os;
os << "ClipTrack\t\"" << get_name() << "\"";
return os.str();
}
ClipTrack::ClipTrack()
{
// TEST CODE: add a clip to the track
boost::shared_ptr<model::Clip> model_clip(new model::Clip());
model_clip->setName("Clip Name");
clips.push_back(model_clip);
// END TEST CODE
}
std::string
ClipTrack::print_track()
{
std::ostringstream os;
os << "ClipTrack\t\"" << get_name() << "\"";
return os.str();
}
lumiera::observable_list< boost::shared_ptr<Clip> >&
ClipTrack::getClipList()
{
return clips;
}
} // namespace model
} // namespace gui

View file

@ -29,24 +29,38 @@
#define CLIP_TRACK_HPP
#include "track.hpp"
#include "lib/observable-list.hpp"
namespace gui {
namespace model {
class Clip;
class ClipTrack : public Track
{
public:
ClipTrack();
std::string print_track();
private:
std::vector<Clip*> clips;
};
class Clip;
class ClipTrack : public Track
{
public:
/**
* Constructor
**/
ClipTrack();
/**
* Gets a string representation of the track that is suitable for debugging
**/
std::string
print_track();
/**
* Gets the list of clips associated with this track.
**/
lumiera::observable_list< boost::shared_ptr<Clip> >&
getClipList(void);
private:
lumiera::observable_list< boost::shared_ptr<Clip> > clips;
};
} // namespace timeline
} // namespace gui

View file

@ -315,7 +315,7 @@ TimelineWidget::create_timeline_track_from_model_track(
// class
if(typeid(*model_track) == typeid(model::ClipTrack))
return shared_ptr<timeline::Track>(new timeline::ClipTrack(
*this, model_track));
*this, dynamic_pointer_cast<model::ClipTrack>(model_track)));
else if(typeid(*model_track) == typeid(model::GroupTrack))
return shared_ptr<timeline::Track>(new timeline::GroupTrack(
*this, dynamic_pointer_cast<model::GroupTrack>(model_track)));

View file

@ -241,9 +241,9 @@ protected:
/**
* The trackMap maps model tracks to timeline widget tracks which are
* responsible for the UI representation of a track.
* @remarks The tree structure is maintianed by the model, and as the
* @remarks The tree structure is maintained by the model, and as the
* widget is updated with update_tracks, timeline tracks are added and
* removed from the map in correspondance with the tree.
* removed from the map in correspondence with the tree.
**/
std::map<boost::shared_ptr<model::Track>,
boost::shared_ptr<timeline::Track> >

View file

@ -27,47 +27,117 @@
#include "timeline-view-window.hpp"
using namespace Gtk;
using boost::dynamic_pointer_cast;
using boost::shared_ptr;
using util::contains;
namespace gui {
namespace widgets {
namespace timeline {
ClipTrack::ClipTrack(TimelineWidget &timelineWidget,
boost::shared_ptr<model::Track> track) :
Track(timelineWidget, track)
{
// TEST CODE: add a clip to the track
boost::shared_ptr<model::Clip> model_clip(new model::Clip());
model_clip->setName("Clip Name");
boost::shared_ptr<timeline::Clip> timeline_clip(new timeline::Clip(model_clip));
clips.push_back(timeline_clip);
// END TEST CODE
}
ClipTrack::ClipTrack (TimelineWidget &timelineWidget,
shared_ptr<model::ClipTrack> track) :
Track(timelineWidget, track)
{
REQUIRE (track);
void
ClipTrack::draw_track(Cairo::RefPtr<Cairo::Context> cairo,
// Connect signals
track->getClipList().signal_changed().connect(
sigc::mem_fun(this, &ClipTrack::onClipListChanged));
updateClips();
}
void
ClipTrack::draw_track (
Cairo::RefPtr<Cairo::Context> cairo,
TimelineViewWindow* const window) const
{
REQUIRE(cairo);
REQUIRE(window);
{
REQUIRE (cairo);
REQUIRE (window);
// Draw a rectangle to let us know it works? :-)
cairo->rectangle(window->time_to_x(0), 1,
window->time_to_x(500000) - window->time_to_x(0),
get_height() - 2);
cairo->set_source_rgb(0.5, 0.5, 0.5);
cairo->fill_preserve();
cairo->set_source_rgb(0.25, 0.25, 0.25);
cairo->stroke();
// Draw a rectangle to let us know it works? :-)
cairo->rectangle(window->time_to_x(0), 1,
window->time_to_x(500000) - window->time_to_x(0),
get_height() - 2);
// Draw all clips
BOOST_FOREACH(boost::shared_ptr<timeline::Clip> c, clips)
{
c->draw_clip(cairo, window);
}
}
cairo->set_source_rgb(0.5, 0.5, 0.5);
cairo->fill_preserve();
cairo->set_source_rgb(0.25, 0.25, 0.25);
cairo->stroke();
// Draw all clips
std::pair<shared_ptr<model::Clip>, shared_ptr<timeline::Clip> >
pair;
BOOST_FOREACH (pair, clipMap)
{
pair.second->draw_clip(cairo, window);
}
}
//// private methods
void
ClipTrack::createTimelineClips()
{
BOOST_FOREACH (shared_ptr<model::Clip> modelClip, getModelTrack()->getClipList())
{
// Is a timeline UI clip present in the map already?
if (!contains (clipMap, modelClip))
{
// The timeline UI clip is not present
// We will need to create one
clipMap[modelClip] = shared_ptr<timeline::Clip>(
new timeline::Clip (modelClip));
}
}
}
shared_ptr<model::ClipTrack>
ClipTrack::getModelTrack ()
{
return dynamic_pointer_cast<model::ClipTrack>(model_track);
}
void
ClipTrack::onClipListChanged ()
{
updateClips ();
}
void
ClipTrack::removeOrphanedClips ()
{
std::map< shared_ptr<model::Clip>,
shared_ptr<timeline::Clip> >
orphanClipMap (clipMap);
// Remove all clips which are still present in the sequence
BOOST_FOREACH (shared_ptr<model::Clip> modelClip, getModelTrack()->getClipList())
if (contains (orphanClipMap, modelClip))
orphanClipMap.erase(modelClip);
// orphanClipMap now contains all the orphaned clips
// Remove them
std::pair< shared_ptr<model::Clip>, shared_ptr<timeline::Clip> >
pair;
BOOST_FOREACH (pair, orphanClipMap)
{
ENSURE (pair.first);
clipMap.erase (pair.first);
}
}
void
ClipTrack::updateClips()
{
// Remove any clips which are no longer present in the model
removeOrphanedClips ();
// Create timeline clips from all the model clips
createTimelineClips ();
}
} // namespace timeline
} // namespace widgets

View file

@ -37,21 +37,66 @@ namespace gui {
namespace widgets {
namespace timeline {
class Clip;
class TimelineViewWindow;
class Clip;
class TimelineViewWindow;
class ClipTrack : public timeline::Track
{
public:
ClipTrack(TimelineWidget &timelineWidget,
boost::shared_ptr<model::Track> track);
class ClipTrack : public timeline::Track
{
public:
/**
* Constructor.
**/
ClipTrack(TimelineWidget &timelineWidget,
boost::shared_ptr<model::ClipTrack> track);
void draw_track(Cairo::RefPtr<Cairo::Context> cairo,
TimelineViewWindow* const window) const;
/**
*
**/
void draw_track(Cairo::RefPtr<Cairo::Context> cairo,
TimelineViewWindow* const window) const;
private:
std::vector<boost::shared_ptr<timeline::Clip> > clips;
};
private:
/**
* Ensures timeline UI clips have been created for every model clip in track.
**/
void
createTimelineClips();
/**
* Gets the modelTrack as a ClipTrack.
**/
boost::shared_ptr<model::ClipTrack>
getModelTrack ();
/**
* An event handler that receives notifications for when the models clip list has been
* changed.
**/
void
onClipListChanged();
/**
* Removes any UI clips which no longer have corresponding model clips present in the
* sequence.
**/
void
removeOrphanedClips();
/**
* Update the attached timeline clips.
**/
void
updateClips();
/**
* The clipMap maps model clips to timeline widget clips which are responsible for the
* UI representation of a clip.
**/
std::map<boost::shared_ptr<model::Clip>,
boost::shared_ptr<timeline::Clip> >
clipMap;
};
} // namespace timeline
} // namespace widgets

View file

@ -35,7 +35,7 @@ GroupTrack::GroupTrack(TimelineWidget &timeline_widget,
shared_ptr<model::GroupTrack> track) :
Track(timeline_widget, track)
{
REQUIRE(track);
REQUIRE (track);
// Receive notifications of changes to the tracks
track->get_child_track_list().signal_changed().connect(