WIP implementing Placement and MObject factory functions
This commit is contained in:
parent
be49b799a2
commit
d7e7d3d613
9 changed files with 265 additions and 103 deletions
|
|
@ -149,7 +149,9 @@ namespace util
|
|||
|
||||
} // namespace util
|
||||
|
||||
/* some common macro definitions */
|
||||
|
||||
|
||||
/* === some common macro definitions === */
|
||||
|
||||
/** supress "warning: unused variable" on vars, which
|
||||
* are introduced into a scope because of some sideeffect, i.e. Locking
|
||||
|
|
@ -160,5 +162,7 @@ namespace util
|
|||
#define STRINGIFY(TOKEN) __STRNGFY(TOKEN)
|
||||
#define __STRNGFY(TOKEN) #TOKEN
|
||||
|
||||
/** shortcut for subclass test, intended for assertions */
|
||||
#define INSTANCEOF(CLASS, EXPR) (dynamic_cast<CLASS*> (EXPR))
|
||||
|
||||
#endif /*UTIL_HPP_*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
EXPLICITPLACEMENT.hpp - special Placement yielding an absolute location (Time,Track)-location for a MObject
|
||||
EXPLICITPLACEMENT.hpp - special Placement yielding an absolute location (Time,Track) for a MObject
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
|
@ -31,18 +31,41 @@
|
|||
namespace mobject
|
||||
{
|
||||
|
||||
namespace session{ class Track; }
|
||||
|
||||
|
||||
// TODO: need Garbage Collector for this class!!!!!
|
||||
|
||||
class ExplicitPlacement : public Placement
|
||||
/**
|
||||
* Special kind of Placement, where the location of the
|
||||
* MObject has been nailed down to a fixed position.
|
||||
* The Session allways contains one special EDL, which
|
||||
* actually is a snapshot of all EDLs contents fixed
|
||||
* and reduced to simple positions. This so called Fixture
|
||||
* contains only ExplicitPlacement objects and is processed
|
||||
* by the Builder to create the render engine node network.
|
||||
*
|
||||
* @see Placement#resolve factory method for deriving an ExplicitPlacement
|
||||
*/
|
||||
class ExplicitPlacement : public Placement<MObject>
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
const Time time;
|
||||
const Track track;
|
||||
|
||||
Time time;
|
||||
Track* track;
|
||||
/** no need to resolve any further, as this ExplicitPlacement
|
||||
* already \i is the result of a resolve()-call.
|
||||
*/
|
||||
virtual const
|
||||
ExplicitPlacement resolve () const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
ExplicitPlacement (Placement<MObject>& base, Time ti, Track tra)
|
||||
: Placement(base),
|
||||
time(ti), track(tra)
|
||||
{ };
|
||||
|
||||
friend class session::LocatingPin;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "cinelerra.h"
|
||||
#include "proc/mobject/buildable.hpp"
|
||||
#include "proc/mobject/placement.hpp"
|
||||
#include "proc/asset.hpp" // TODO finally not needed?
|
||||
|
||||
|
||||
|
|
@ -43,7 +44,10 @@ using proc_interface::AssetManager;
|
|||
namespace mobject
|
||||
{
|
||||
|
||||
class Placement;
|
||||
namespace session
|
||||
{
|
||||
class MObjectFactory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -63,14 +67,16 @@ namespace mobject
|
|||
virtual ~MObject() {};
|
||||
|
||||
public:
|
||||
virtual shared_ptr<Placement>& getPlacement () =0;
|
||||
static session::MObjectFactory create;
|
||||
|
||||
virtual PAsset getMedia () =0; ///< @todo solve the reference/Interface problem concerning Placements, then push down
|
||||
virtual Time& getLength() =0; ///< @todo how to deal with the time/length field??
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef shared_ptr<MObject> PMO;
|
||||
typedef Placement<MObject> PMO;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
Placement - Key Abstraction: a way to place and locate a Media Object
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
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 "proc/mobject/placement.hpp"
|
||||
#include "proc/mobject/explicitplacement.hpp"
|
||||
|
||||
namespace mobject
|
||||
{
|
||||
|
||||
|
||||
/** factory for creating the corretct Placement subclass */
|
||||
PlacementFactory Placement::create;
|
||||
|
||||
|
||||
/** create an actual (explicit) placement while trying to
|
||||
* satisfy the network of adjacent objects and placements.
|
||||
*/
|
||||
ExplicitPlacement
|
||||
Placement::resolve ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** implements the logic for selecting the correct
|
||||
* Placement subclass.
|
||||
* @return smart ptr owning the created placement object
|
||||
*/
|
||||
PlacementFactory::PType
|
||||
PlacementFactory::operator() (Placement::Style, Time, PMO subject)
|
||||
{
|
||||
UNIMPLEMENTED ("create correct Placement subclass");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace mobject
|
||||
|
|
@ -23,22 +23,32 @@
|
|||
|
||||
/** @file placement.hpp
|
||||
** Placements are at the very core of all editing operations,
|
||||
** because they act as handles (smart pointers) to access the media objects
|
||||
** to be manipulated. Moreover, Placements are the actual content of the EDL(s)
|
||||
** and Fixture and thus are small objects with value semantics. Many editing tasks
|
||||
** include finding some Placement in the EDL or directly take a ref to some Placement.
|
||||
** because they act as handles to access the media objects to be manipulated.
|
||||
** Moreover, Placements are the actual content of the EDL(s) and Fixture and thus
|
||||
** are small objects with value semantics. Many editing tasks include locating some
|
||||
** Placement in the EDL or directly take a ref to a Placement.
|
||||
**
|
||||
** Placements are <b>smart pointers</b>: By acting on the Placement object, we can change
|
||||
** parameters of the way the media object is placed (e.g. adjust an offset), while by
|
||||
** dereferencing the Placement object, we access the "real" media object (e.g. for trimming).
|
||||
** Placements are <b>refcounting smart pointers</b>: By acting on the Placement object,
|
||||
** we can change parameters of the way the media object is placed (e.g. adjust an offset),
|
||||
** while by dereferencing the Placement object, we access the "real" media object.
|
||||
** Usually, any MObject is created by a factory and immediately wrapped into a Placement,
|
||||
** which takes ownership of the MObject.
|
||||
**
|
||||
** Besides being a handle, Placements define the logical position where some MObject is
|
||||
** supposed to be located within the EDL or Fixture. The way in which this placing happens
|
||||
** is controlled and parametrized by a collection (chain) of LocatingPin objects. By adding
|
||||
** to this chain, the position of the MObject is increasingly constrained. The simplest
|
||||
** case of such constraining is to add a FixedLocation, thus placing the MObject at one
|
||||
** absolute position (time, track).
|
||||
**
|
||||
** Placements are templated on the type of the actual MObject they refer to, so, sometimes
|
||||
** we rather use a Placement<Clip> to be able to use the more specific methods of the
|
||||
** session::Clip interface. But <i>please note the following detail:</i> this type
|
||||
** labeling is the <i>only</i> difference between this subclasses, besides that,
|
||||
** they can be replaced by one another (no slicing).
|
||||
** labeling and downcasting is the <i>only</i> difference between these subclasses,
|
||||
** besides that, they can be replaced literally by one another (slicing is accepted).
|
||||
**
|
||||
** @see ExplicitPlacement
|
||||
** @see LocatingPin interface for controlling the positioning parameters
|
||||
**
|
||||
*/
|
||||
|
||||
|
|
@ -47,39 +57,63 @@
|
|||
#ifndef MOBJECT_PLACEMENT_H
|
||||
#define MOBJECT_PLACEMENT_H
|
||||
|
||||
#include "common/time.hpp"
|
||||
#include "common/factory.hpp"
|
||||
#include "proc/mobject/mobject.hpp"
|
||||
#include "cinelerra.h"
|
||||
#include "proc/mobject/session/abstractmo.hpp"
|
||||
#include "proc/mobject/session/locatingpin.hpp"
|
||||
#include "proc/mobject/session/track.hpp"
|
||||
|
||||
#include <tr1/memory>
|
||||
using std::tr1::shared_ptr;
|
||||
|
||||
|
||||
namespace mobject
|
||||
{
|
||||
|
||||
|
||||
class MObject;
|
||||
class ExplicitPlacement;
|
||||
|
||||
|
||||
|
||||
template<class MO>
|
||||
class Placement : public shared_ptr<MO>
|
||||
class Placement : protected shared_ptr<MO>
|
||||
{
|
||||
protected:
|
||||
typedef cinelerra::Time Time;
|
||||
typedef session::Track Track;
|
||||
typedef session::Track* Track;
|
||||
|
||||
|
||||
public:
|
||||
LocatingPin chain;
|
||||
/** smart pointer: accessing the MObject,
|
||||
* which is subject to placement.
|
||||
* @note we don't provide operator*
|
||||
*/
|
||||
virtual MO *
|
||||
operator-> () const
|
||||
{
|
||||
return shared_ptr::operator-> ();
|
||||
}
|
||||
|
||||
/** resolve the network of placement and
|
||||
/** interface for defining the kind of placement
|
||||
* to employ, and for controling any additional
|
||||
* constraints and properties.
|
||||
*/
|
||||
session::LocatingPin chain;
|
||||
|
||||
/** combine and resolve all constraints defined
|
||||
* by the various LocatingPin (\see #chain) and
|
||||
* provide the resulting (explicit) placement.
|
||||
*/
|
||||
virtual ExplicitPlacement resolve () ;
|
||||
virtual const ExplicitPlacement
|
||||
resolve () const
|
||||
{
|
||||
return chain.resolve();
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
Placement ();
|
||||
virtual ~Placement() {};
|
||||
Placement (MO & subject)
|
||||
: shared_ptr (&subject, &session::AbstractMO::destroy) {};
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -92,20 +126,62 @@ namespace mobject
|
|||
class Meta;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
class Placement<session::Clip> : public Placement<MObject>
|
||||
{
|
||||
//TODO: overwirte shared_ptr's operator-> to return the correct subtype of MObject...
|
||||
Placement (session::Clip & c)
|
||||
: Placement<MObject>::Placement (c)
|
||||
{ };
|
||||
|
||||
public:
|
||||
virtual session::Clip*
|
||||
operator-> () const
|
||||
{
|
||||
ENSURE (INSTANCEOF(session::Clip, this.get()));
|
||||
return static_cast<session::Clip*> (shared_ptr::operator-> ());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class Placement<session::Effect> : public Placement<MObject>
|
||||
{ };
|
||||
{
|
||||
Placement (session::Effect & e)
|
||||
: Placement<MObject>::Placement (e)
|
||||
{ };
|
||||
|
||||
public:
|
||||
virtual session::Effect*
|
||||
operator-> () const
|
||||
{
|
||||
ENSURE (INSTANCEOF(session::Effect, this.get()));
|
||||
return static_cast<session::Effect*> (shared_ptr::operator-> ());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class Placement<session::Meta> : public Placement<MObject>
|
||||
{ };
|
||||
{
|
||||
Placement (session::Meta & m)
|
||||
: Placement<MObject>::Placement (m)
|
||||
{ };
|
||||
|
||||
public:
|
||||
virtual session::Meta*
|
||||
operator-> () const
|
||||
{
|
||||
ENSURE (INSTANCEOF(session::Meta, this.get()));
|
||||
return static_cast<session::Meta*> (shared_ptr::operator-> ());
|
||||
}
|
||||
};
|
||||
|
||||
/* a note to the maintainer: please don't add any fields or methods to
|
||||
* these subclasses which aren't also present in Placement<MObject>!
|
||||
* Placements are frequently treated like values and thus slicing
|
||||
* will happen, which in this special case is acceptable.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,15 @@ namespace mobject
|
|||
{
|
||||
UNIMPLEMENTED ("how to relate MObjects and media assets...");
|
||||
return AssetManager::instance().getAsset(IDA(0)); // KABOOM! (just to make it compile)
|
||||
}
|
||||
}
|
||||
protected:
|
||||
/** custom deleter func allowing class Placement
|
||||
* to take ownership of MObjct instances
|
||||
*/
|
||||
static void destroy (MObject* o) { delete o; }
|
||||
|
||||
friend class Placement;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@
|
|||
#define MOBJECT_SESSION_LOCATINGPIN_H
|
||||
|
||||
|
||||
#include "cinelerra.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
using boost::scoped_ptr;
|
||||
|
||||
|
||||
|
||||
namespace mobject
|
||||
|
|
@ -33,18 +38,24 @@ namespace mobject
|
|||
|
||||
namespace session
|
||||
{
|
||||
class FixedPlacement;
|
||||
class RelativePlacement;
|
||||
|
||||
|
||||
class FixedLocation;
|
||||
class RelativeLocation;
|
||||
|
||||
|
||||
struct LocatingPin
|
||||
{
|
||||
protected:
|
||||
typedef cinelerra::Time Time;
|
||||
typedef session::Track* Track;
|
||||
|
||||
/** next additional Pin, if any */
|
||||
LocatingPin * next;
|
||||
scoped_ptr<LocatingPin> next;
|
||||
public:
|
||||
|
||||
FixedPlacement& operator() (Time);
|
||||
/* Factory functions for adding LocationPins */
|
||||
|
||||
FixedLocation& operator() (Time, Track);
|
||||
RelativeLocation& operator() (PMO refObj, Time offset=0);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
64
src/proc/mobject/session/mobjectfactory.cpp
Normal file
64
src/proc/mobject/session/mobjectfactory.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
MObjectFactory - creating concrete MObject subclass instances
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
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 "proc/mobject/session/mobjectfactory.hpp"
|
||||
#include "proc/mobject/session/clip.hpp"
|
||||
#include "proc/mobject/session/effect.hpp"
|
||||
#include "proc/asset/clip.hpp"
|
||||
#include "proc/asset/effect.hpp"
|
||||
|
||||
namespace mobject
|
||||
{
|
||||
namespace session
|
||||
{
|
||||
|
||||
/** creating a Clip-MObject to be placed within
|
||||
* the EDL, based on a clip asset, which typically
|
||||
* is obtained by calling the createClip()-function
|
||||
* on some asset::Media. The newly created Clip-MO is
|
||||
* internally linked with this media Asset and wrapped
|
||||
* into a Placement, which takes ownership. So, when the
|
||||
* render engine gets across this Clip-MO, it is able to
|
||||
* obtain the media information contained in the corresponding
|
||||
* asset.
|
||||
*/
|
||||
Placement<Clip>
|
||||
MObjectFactory::operator() (shared_ptr<asset::Clip>& mediaDef)
|
||||
{
|
||||
//TODO sholdin't we rather store a ref to the underlying media assset??
|
||||
return Placement<Clip> (new Clip (mediaDef));
|
||||
}
|
||||
|
||||
|
||||
/** */
|
||||
Placement<Effect>
|
||||
MObjectFactory::operator() (asset::Effect processorDef)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace mobject::session
|
||||
|
||||
} // namespace mobject
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
ExplicitPlacement - special Placement yielding an absolute location (Time,Track)-location for a MObject
|
||||
MOBJECTFACTORY.hpp - creating concrete MObject subclass instances
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
|
@ -18,16 +18,43 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* *****************************************************/
|
||||
*/
|
||||
|
||||
|
||||
#include "proc/mobject/explicitplacement.hpp"
|
||||
#ifndef MOBJECT_SESSION_MOBJECTFACTORY_H
|
||||
#define MOBJECT_SESSION_MOBJECTFACTORY_H
|
||||
|
||||
#include "proc/mobject/mobject.hpp"
|
||||
|
||||
|
||||
|
||||
namespace asset
|
||||
{
|
||||
class Clip;
|
||||
class Effect;
|
||||
}
|
||||
|
||||
namespace mobject
|
||||
{
|
||||
|
||||
/** */
|
||||
namespace session
|
||||
{
|
||||
class Clip;
|
||||
class Effect;
|
||||
|
||||
|
||||
class MObjectFactory
|
||||
{
|
||||
public:
|
||||
typedef Placement PType;
|
||||
|
||||
PType<Clip> operator() (const asset::Clip);
|
||||
PType<Effect> operator() (const asset::Effect);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace mobject::session
|
||||
|
||||
} // namespace mobject
|
||||
#endif
|
||||
Loading…
Reference in a new issue