Exemplo n.º 1
0
    def __init__(self, name="", uri=None, **kwargs):
        """
        @param name: the name of the project
        @param uri: the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-added", self._sourceAddedCb)
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
        self.seeker = Seeker(80)

        self.settings = ExportSettings()
        self._videocaps = self.settings.getVideoCaps()
Exemplo n.º 2
0
    def __init__(self, name="", uri=None, **kwargs):
        """
        name : the name of the project
        uri : the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self.settingssigid = 0
        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
Exemplo n.º 3
0
 def _viewFactory(self, factory):
     # FIXME: we change the viewer pipeline unconditionally for now
     # we need a pipeline for playback
     pipeline = Pipeline()
     action = ViewAction()
     action.addProducers(factory)
     self.viewer.setPipeline(None)
     # FIXME: why do I have to call viewer.setAction ?
     self.viewer.setAction(action)
     self.viewer.setPipeline(pipeline)
     self.viewer.play()
Exemplo n.º 4
0
 def _viewFactory(self, factory):
     # FIXME: we change the viewer pipeline unconditionally for now
     # we need a pipeline for playback
     pipeline = Pipeline()
     action = ViewAction()
     action.addProducers(factory)
     self.viewer.setPipeline(None)
     self.viewer.showSlider()
     # FIXME: why do I have to call viewer.setAction ?
     self.viewer.setAction(action)
     self.viewer.setPipeline(pipeline)
     self.viewer.play()
Exemplo n.º 5
0
    def __init__(self, name="", uri=None, **kwargs):
        """
        @param name: the name of the project
        @param uri: the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-added", self._sourceAddedCb)
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
        self.seeker = Seeker(80)

        self.settings = ExportSettings()
        self._videocaps = self.settings.getVideoCaps()
Exemplo n.º 6
0
    def addAction(self):
        self.debug("action %r", self.action)
        if self.action == None:
            if self.actioner == self.RENDERER:
                self.pipeline.connect('position', self._positionCb)
            self.pipeline.connect('eos', self._eosCb)
            self.pipeline.connect('error', self._errorCb)
            self.debug("Setting pipeline to STOP")
            self.pipeline.stop()
            self.debug("Creating action")
            if len(self.pipeline.factories) == 0:
                sources = [self.project.factory]
            else:
                sources = [
                    factory for factory in self.pipeline.factories
                    if isinstance(factory, SourceFactory)
                ]
            if self.actioner == self.PREVIEWER:
                self.action = ViewAction()
                self.action.addProducers(*sources)
                self.ui.setAction(self.action)
                self.ui.setPipeline(self.pipeline)
            elif self.actioner == self.RENDERER:
                settings = export_settings_to_render_settings(
                    self.settings, self.have_video, self.have_audio)
                self.action = render_action_for_uri(self.outfile, settings,
                                                    *sources)
            #else:
            # BIG FAT ERROR HERE

            self.debug("setting action on pipeline")
            self.pipeline.addAction(self.action)
            self.debug("Activating action")
            self.action.activate()
            if self.actioner == self.RENDERER:
                self.debug("Setting all active ViewAction to sync=False")
                for ac in self.pipeline.actions:
                    if isinstance(ac, ViewAction) and ac.isActive():
                        ac.setSync(False)
            self.debug("Updating all sources to render settings")
            self._changeSourceSettings(self.settings)
            self.debug("setting pipeline to PAUSE")
            self.pipeline.pause()
            self.debug("done")
Exemplo n.º 7
0
    def addAction(self):
        self.debug("action %r", self.action)
        if self.action == None:
            if self.actioner == self.RENDERER:
                self.pipeline.connect('position', self._positionCb)
            self.pipeline.connect('eos', self._eosCb)
            self.pipeline.connect('error', self._errorCb)
            self.debug("Setting pipeline to STOP")
            self.pipeline.stop()
            self.debug("Creating action")
            if len(self.pipeline.factories) == 0:
                sources = [self.project.factory]
            else:
                sources = [factory for factory in self.pipeline.factories
                        if isinstance(factory, SourceFactory)]
            if self.actioner == self.PREVIEWER:
                self.action = ViewAction()
                self.action.addProducers(*sources)
                self.ui.setAction(self.action)
                self.ui.setPipeline(self.pipeline)
            elif self.actioner == self.RENDERER:
                settings = export_settings_to_render_settings(self.settings,
                        self.have_video, self.have_audio)
                self.action = render_action_for_uri(self.outfile,
                        settings, *sources)
            #else:
                # BIG FAT ERROR HERE

            self.debug("setting action on pipeline")
            self.pipeline.addAction(self.action)
            self.debug("Activating action")
            self.action.activate()
            if self.actioner == self.RENDERER:
                self.debug("Setting all active ViewAction to sync=False")
                for ac in self.pipeline.actions:
                    if isinstance(ac, ViewAction) and ac.isActive():
                        ac.setSync(False)
            self.debug("Updating all sources to render settings")
            self._changeSourceSettings(self.settings)
            self.debug("setting pipeline to PAUSE")
            self.pipeline.pause()
            self.debug("done")
Exemplo n.º 8
0
 def _getDefaultAction(self):
     return ViewAction()
Exemplo n.º 9
0
class Actioner(Loggable, Signallable):
    """ Previewer/Renderer helper methods """

    __signals__ = {
        "eos" : None,
        "error" : None
        }

    RENDERER = 0
    PREVIEWER = 1

    def __init__(self, project, pipeline=None):
        Loggable.__init__(self)
        # grab the Pipeline and settings
        self.project = project
        if pipeline != None:
            self.pipeline = pipeline
        else:
            self.pipeline = self.project.pipeline
        self.acting = False
        self.action = None
        self.settings = project.getSettings()

    def _eosCb(self, unused_pipeline):
        self.debug("eos !")
        if self.actioner != self.PREVIEWER:
            self.shutdown()
        self.emit("eos")

    def shutdown(self):
        self.acting = False
        self.updateUIOnEOS()
        self.removeAction()

    def updateUIOnEOS(self):
        pass

    def _errorCb(self, pipeline, error, detail):
        self.debug("error !")
        self.acting = False
        self.updateUIOnError()
        self.removeAction()
        self.emit("error")

    def updateUIOnError(self):
        pass

    def _changeSourceSettings(self, settings):
        videocaps = settings.getVideoCaps()
        for source in self.project.sources.getSources():
            source.setFilterCaps(videocaps)

    def addAction(self):
        self.debug("action %r", self.action)
        if self.action == None:
            if self.actioner == self.RENDERER:
                self.pipeline.connect('position', self._positionCb)
            self.pipeline.connect('eos', self._eosCb)
            self.pipeline.connect('error', self._errorCb)
            self.debug("Setting pipeline to STOP")
            self.pipeline.stop()
            self.debug("Creating action")
            if len(self.pipeline.factories) == 0:
                sources = [self.project.factory]
            else:
                sources = [factory for factory in self.pipeline.factories
                        if isinstance(factory, SourceFactory)]
            if self.actioner == self.PREVIEWER:
                self.action = ViewAction()
                self.action.addProducers(*sources)
                self.ui.setAction(self.action)
                self.ui.setPipeline(self.pipeline)
            elif self.actioner == self.RENDERER:
                settings = export_settings_to_render_settings(self.settings,
                        self.have_video, self.have_audio)
                self.action = render_action_for_uri(self.outfile,
                        settings, *sources)
            #else:
                # BIG FAT ERROR HERE

            self.debug("setting action on pipeline")
            self.pipeline.addAction(self.action)
            self.debug("Activating action")
            self.action.activate()
            if self.actioner == self.RENDERER:
                self.debug("Setting all active ViewAction to sync=False")
                for ac in self.pipeline.actions:
                    if isinstance(ac, ViewAction) and ac.isActive():
                        ac.setSync(False)
            self.debug("Updating all sources to render settings")
            self._changeSourceSettings(self.settings)
            self.debug("setting pipeline to PAUSE")
            self.pipeline.pause()
            self.debug("done")


    def removeAction(self):
        self.debug("action %r", self.action)
        if self.action:
            self.pipeline.stop()
            self.action.deactivate()
            self.pipeline.removeAction(self.action)
            self.debug("putting all active ViewActions back to sync=True")
            for ac in self.pipeline.actions:
                if isinstance(ac, ViewAction) and ac.isActive():
                    ac.setSync(True)
            self._changeSourceSettings(self.project.getSettings())
            self.pipeline.pause()
            if self.actioner == self.RENDERER:
                self.pipeline.disconnect_by_function(self._positionCb)
            self.pipeline.disconnect_by_function(self._eosCb)
            self.pipeline.disconnect_by_function(self._errorCb)
            self.action = None

    def _startAction(self):
        self.addAction()
        self.pipeline.play()
        self.timestarted = time.time()
        self.acting = True
Exemplo n.º 10
0
class Project(Signallable, Loggable):
    """The base class for PiTiVi projects

    @ivar name: The name of the project
    @type name: C{str}
    @ivar description: A description of the project
    @type description: C{str}
    @ivar sources: The sources used by this project
    @type sources: L{SourceList}
    @ivar timeline: The timeline
    @type timeline: L{Timeline}
    @ivar pipeline: The timeline's pipeline
    @type pipeline: L{Pipeline}
    @ivar factory: The timeline factory
    @type factory: L{TimelineSourceFactory}
    @ivar format: The format under which the project is currently stored.
    @type format: L{FormatterClass}
    @ivar loaded: Whether the project is fully loaded or not.
    @type loaded: C{bool}

    Signals:
     - C{loaded} : The project is now fully loaded.
    """

    __signals__ = {
        "settings-changed" : ['old', 'new'],
        "project-changed" : [],
        }

    def __init__(self, name="", uri=None, **kwargs):
        """
        @param name: the name of the project
        @param uri: the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-added", self._sourceAddedCb)
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
        self.seeker = Seeker(80)

        self.settings = ExportSettings()
        self._videocaps = self.settings.getVideoCaps()

    def release(self):
        self.pipeline.release()
        self.pipeline = None

    #{ Settings methods

    def getSettings(self):
        """
        return the currently configured settings.
        """
        self.debug("self.settings %s", self.settings)
        return self.settings

    def setSettings(self, settings):
        """
        Sets the given settings as the project's settings.
        @param settings: The new settings for the project.
        @type settings: ExportSettings
        """
        assert settings
        self.log("Setting %s as the project's settings", settings)
        oldsettings = self.settings
        self.settings = settings
        self._projectSettingsChanged()
        self.emit('settings-changed', oldsettings, settings)

    #}

    #{ Save and Load features

    def setModificationState(self, state):
        self._dirty = state
        if state:
            self.emit('project-changed')

    def hasUnsavedModifications(self):
        return self._dirty

    def _projectSettingsChanged(self):
        settings = self.getSettings()
        self._videocaps = settings.getVideoCaps()
        if self.timeline:
            self.timeline.updateVideoCaps(self._videocaps)

        for fact in self.sources.getSources():
            fact.setFilterCaps(self._videocaps)
        if self.pipeline.getState() != gst.STATE_NULL:
            self.pipeline.stop()
            self.pipeline.pause()

    def _sourceAddedCb(self, sourcelist, factory):
        factory.setFilterCaps(self._videocaps)

    def _sourceRemovedCb(self, sourclist, uri, factory):
        self.timeline.removeFactory(factory)
Exemplo n.º 11
0
class Project(Signallable, Loggable):
    """The base class for PiTiVi projects

    @ivar name: The name of the project
    @type name: C{str}
    @ivar description: A description of the project
    @type description: C{str}
    @ivar sources: The sources used by this project
    @type sources: L{SourceList}
    @ivar timeline: The timeline
    @type timeline: L{Timeline}
    @ivar pipeline: The timeline's pipeline
    @type pipeline: L{Pipeline}
    @ivar factory: The timeline factory
    @type factory: L{TimelineSourceFactory}
    @ivar format: The format under which the project is currently stored.
    @type format: L{FormatterClass}
    @ivar loaded: Whether the project is fully loaded or not.
    @type loaded: C{bool}

    Signals:
     - C{loaded} : The project is now fully loaded.
    """

    __signals__ = {
        "settings-changed" : ['old', 'new'],
        }

    def __init__(self, name="", uri=None, **kwargs):
        """
        name : the name of the project
        uri : the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-added", self._sourceAddedCb)
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
        self.seeker = Seeker(80)

        self.getCapsFromSettings()

    def getCapsFromSettings(self):
        settings = self.getSettings()
        #formatstr = "video/x-raw-rgb,width=(int)%d,height=(int)%d;"\
        #    "video/x-raw-yuv,width=(int)%d,height=(int)%d"
        #capstr = formatstr % (
        #    settings.videowidth,
        #    settings.videoheight,
        #    settings.videowidth,
        #    settings.videoheight)
        #self._videocaps = gst.Caps(capstr)
        self._videocaps = settings.getVideoCaps()

    def release(self):
        self.pipeline.release()
        self.pipeline = None

    #{ Settings methods

    def getSettings(self):
        """
        return the currently configured settings.
        If no setting have been explicitely set, some smart settings will be
        chosen.
        """
        self.debug("self.settings %s", self.settings)
        return self.settings or self.getAutoSettings()

    def setSettings(self, settings):
        """
        Sets the given settings as the project's settings.
        If settings is None, the current settings will be unset
        """
        self.log("Setting %s as the project's settings", settings)
        oldsettings = self.settings
        self.settings = settings
        self._projectSettingsChanged()
        self.emit('settings-changed', oldsettings, settings)

    def unsetSettings(self, unused_settings):
        """ Remove the currently configured settings."""
        self.setSettings(None)

    def getAutoSettings(self):
        """
        Computes and returns smart settings for the project.
        If the project only has one source, it will be that source's settings.
        If it has more than one, it will return the largest setting that suits
        all contained sources.
        """
        settings = ExportSettings()
        if not self.timeline:
            self.warning("project doesn't have a timeline, returning default settings")
            return settings

        # FIXME: this is ugly, but rendering for now assumes at most one audio
        # and one video tracks
        have_audio = have_video = False
        for track in self.timeline.tracks:
            if isinstance(track.stream, VideoStream) and track.duration != 0:
                have_video = True
            elif isinstance(track.stream, AudioStream) and track.duration != 0:
                have_audio = True

        if not have_audio:
            settings.aencoder = None

        if not have_video:
            settings.vencoder = None

        return settings

    #}

    #{ Save and Load features

    def save(self, location=None, overwrite=False):
        """
        Save the project to the given location.

        @param location: The location to write to. If not specified, the
        current project location will be used (if set).
        @type location: C{URI}
        @param overwrite: Whether to overwrite existing location.
        @type overwrite: C{bool}
        """
        # import here to break circular import
        from pitivi.formatters.format import save_project
        from pitivi.formatters.base import FormatterError

        self.log("saving...")
        location = location or self.uri

        if location == None:
            raise FormatterError("Location unknown")

        save_project(self, location or self.uri, self.format,
                     overwrite)

        self.uri = location

    def setModificationState(self, state):
        self._dirty = state

    def hasUnsavedModifications(self):
        return self._dirty

    def _projectSettingsChanged(self):
        self.getCapsFromSettings()
        for fact in self.sources.getSources():
            fact.setFilterCaps(self._videocaps)
        if self.pipeline.getState() != gst.STATE_NULL:
            self.pipeline.stop()
            self.pipeline.pause()

    def _sourceAddedCb(self, sourcelist, factory):
        factory.setFilterCaps(self._videocaps)

    def _sourceRemovedCb(self, sourclist, uri, factory):
        self.timeline.removeFactory(factory)
Exemplo n.º 12
0
class Project(Signallable, Loggable):
    """The base class for PiTiVi projects

    @ivar name: The name of the project
    @type name: C{str}
    @ivar description: A description of the project
    @type description: C{str}
    @ivar sources: The sources used by this project
    @type sources: L{SourceList}
    @ivar timeline: The timeline
    @type timeline: L{Timeline}
    @ivar pipeline: The timeline's pipeline
    @type pipeline: L{Pipeline}
    @ivar factory: The timeline factory
    @type factory: L{TimelineSourceFactory}
    @ivar format: The format under which the project is currently stored.
    @type format: L{FormatterClass}
    @ivar loaded: Whether the project is fully loaded or not.
    @type loaded: C{bool}

    Signals:
     - C{loaded} : The project is now fully loaded.
    """

    __signals__ = {
        "settings-changed": ['old', 'new'],
        "project-changed": [],
    }

    def __init__(self, name="", uri=None, **kwargs):
        """
        @param name: the name of the project
        @param uri: the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-added", self._sourceAddedCb)
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)
        self.seeker = Seeker(80)

        self.settings = ExportSettings()
        self._videocaps = self.settings.getVideoCaps()

    def release(self):
        self.pipeline.release()
        self.pipeline = None

    #{ Settings methods

    def getSettings(self):
        """
        return the currently configured settings.
        """
        self.debug("self.settings %s", self.settings)
        return self.settings

    def setSettings(self, settings):
        """
        Sets the given settings as the project's settings.
        @param settings: The new settings for the project.
        @type settings: ExportSettings
        """
        assert settings
        self.log("Setting %s as the project's settings", settings)
        oldsettings = self.settings
        self.settings = settings
        self._projectSettingsChanged()
        self.emit('settings-changed', oldsettings, settings)

    #}

    #{ Save and Load features

    def setModificationState(self, state):
        self._dirty = state
        if state:
            self.emit('project-changed')

    def hasUnsavedModifications(self):
        return self._dirty

    def _projectSettingsChanged(self):
        settings = self.getSettings()
        self._videocaps = settings.getVideoCaps()
        if self.timeline:
            self.timeline.updateVideoCaps(self._videocaps)

        for fact in self.sources.getSources():
            fact.setFilterCaps(self._videocaps)
        if self.pipeline.getState() != gst.STATE_NULL:
            self.pipeline.stop()
            self.pipeline.pause()

    def _sourceAddedCb(self, sourcelist, factory):
        factory.setFilterCaps(self._videocaps)

    def _sourceRemovedCb(self, sourclist, uri, factory):
        self.timeline.removeFactory(factory)
Exemplo n.º 13
0
 def _createAction(self, sources):
     action = ViewAction()
     action.addProducers(*sources)
     self.ui.setAction(action)
     self.ui.setPipeline(self.pipeline)
     return action
Exemplo n.º 14
0
class Actioner(Loggable, Signallable):
    """ Previewer/Renderer helper methods """

    __signals__ = {"eos": None, "error": None}

    RENDERER = 0
    PREVIEWER = 1

    def __init__(self, project, pipeline=None):
        Loggable.__init__(self)
        # grab the Pipeline and settings
        self.project = project
        if pipeline != None:
            self.pipeline = pipeline
        else:
            self.pipeline = self.project.pipeline
        self.acting = False
        self.action = None
        self.settings = project.getSettings()

    def _eosCb(self, unused_pipeline):
        self.debug("eos !")
        if self.actioner != self.PREVIEWER:
            self.shutdown()
        self.emit("eos")

    def shutdown(self):
        self.acting = False
        self.updateUIOnEOS()
        self.removeAction()

    def updateUIOnEOS(self):
        pass

    def _errorCb(self, pipeline, error, detail):
        self.debug("error !")
        self.acting = False
        self.updateUIOnError()
        self.removeAction()
        self.emit("error")

    def updateUIOnError(self):
        pass

    def _changeSourceSettings(self, settings):
        videocaps = settings.getVideoCaps()
        for source in self.project.sources.getSources():
            source.setFilterCaps(videocaps)

    def addAction(self):
        self.debug("action %r", self.action)
        if self.action == None:
            if self.actioner == self.RENDERER:
                self.pipeline.connect('position', self._positionCb)
            self.pipeline.connect('eos', self._eosCb)
            self.pipeline.connect('error', self._errorCb)
            self.debug("Setting pipeline to STOP")
            self.pipeline.stop()
            self.debug("Creating action")
            if len(self.pipeline.factories) == 0:
                sources = [self.project.factory]
            else:
                sources = [
                    factory for factory in self.pipeline.factories
                    if isinstance(factory, SourceFactory)
                ]
            if self.actioner == self.PREVIEWER:
                self.action = ViewAction()
                self.action.addProducers(*sources)
                self.ui.setAction(self.action)
                self.ui.setPipeline(self.pipeline)
            elif self.actioner == self.RENDERER:
                settings = export_settings_to_render_settings(
                    self.settings, self.have_video, self.have_audio)
                self.action = render_action_for_uri(self.outfile, settings,
                                                    *sources)
            #else:
            # BIG FAT ERROR HERE

            self.debug("setting action on pipeline")
            self.pipeline.addAction(self.action)
            self.debug("Activating action")
            self.action.activate()
            if self.actioner == self.RENDERER:
                self.debug("Setting all active ViewAction to sync=False")
                for ac in self.pipeline.actions:
                    if isinstance(ac, ViewAction) and ac.isActive():
                        ac.setSync(False)
            self.debug("Updating all sources to render settings")
            self._changeSourceSettings(self.settings)
            self.debug("setting pipeline to PAUSE")
            self.pipeline.pause()
            self.debug("done")

    def removeAction(self):
        self.debug("action %r", self.action)
        if self.action:
            self.pipeline.stop()
            self.action.deactivate()
            self.pipeline.removeAction(self.action)
            self.debug("putting all active ViewActions back to sync=True")
            for ac in self.pipeline.actions:
                if isinstance(ac, ViewAction) and ac.isActive():
                    ac.setSync(True)
            self._changeSourceSettings(self.project.getSettings())
            self.pipeline.pause()
            if self.actioner == self.RENDERER:
                self.pipeline.disconnect_by_function(self._positionCb)
            self.pipeline.disconnect_by_function(self._eosCb)
            self.pipeline.disconnect_by_function(self._errorCb)
            self.action = None

    def _startAction(self):
        self.addAction()
        self.pipeline.play()
        self.timestarted = time.time()
        self.acting = True
Exemplo n.º 15
0
 def _createAction(self, sources):
     action = ViewAction()
     action.addProducers(*sources)
     self.ui.setAction(action)
     self.ui.setPipeline(self.pipeline)
     return action
Exemplo n.º 16
0
class Project(Signallable, Loggable):
    """The base class for PiTiVi projects

    @ivar name: The name of the project
    @type name: C{str}
    @ivar description: A description of the project
    @type description: C{str}
    @ivar sources: The sources used by this project
    @type sources: L{SourceList}
    @ivar timeline: The timeline
    @type timeline: L{Timeline}
    @ivar pipeline: The timeline's pipeline
    @type pipeline: L{Pipeline}
    @ivar factory: The timeline factory
    @type factory: L{TimelineSourceFactory}
    @ivar format: The format under which the project is currently stored.
    @type format: L{FormatterClass}
    @ivar loaded: Whether the project is fully loaded or not.
    @type loaded: C{bool}

    Signals:
     - C{loaded} : The project is now fully loaded.
    """

    __signals__ = {
        "settings-changed": None,
    }

    def __init__(self, name="", uri=None, **kwargs):
        """
        name : the name of the project
        uri : the uri of the project
        """
        Loggable.__init__(self)
        self.log("name:%s, uri:%s", name, uri)
        self.name = name
        self.settings = None
        self.description = ""
        self.uri = uri
        self.urichanged = False
        self.format = None
        self.sources = SourceList()
        self.sources.connect("source-removed", self._sourceRemovedCb)

        self.settingssigid = 0
        self._dirty = False

        self.timeline = Timeline()

        self.factory = TimelineSourceFactory(self.timeline)
        self.pipeline = Pipeline()
        self.view_action = ViewAction()
        self.view_action.addProducers(self.factory)

    def release(self):
        self.pipeline.release()
        self.pipeline = None

    #{ Settings methods

    def _settingsChangedCb(self, unused_settings):
        self.emit('settings-changed')

    def getSettings(self):
        """
        return the currently configured settings.
        If no setting have been explicitely set, some smart settings will be
        chosen.
        """
        self.debug("self.settings %s", self.settings)
        return self.settings or self.getAutoSettings()

    def setSettings(self, settings):
        """
        Sets the given settings as the project's settings.
        If settings is None, the current settings will be unset
        """
        self.log("Setting %s as the project's settings", settings)
        if self.settings:
            self.settings.disconnect(self.settingssigid)
        self.settings = settings
        self.emit('settings-changed')
        self.settingssigid = self.settings.connect('settings-changed',
                                                   self._settingsChangedCb)

    def unsetSettings(self, unused_settings):
        """ Remove the currently configured settings."""
        self.setSettings(None)

    def getAutoSettings(self):
        """
        Computes and returns smart settings for the project.
        If the project only has one source, it will be that source's settings.
        If it has more than one, it will return the largest setting that suits
        all contained sources.
        """
        settings = ExportSettings()
        if not self.timeline:
            self.warning(
                "project doesn't have a timeline, returning default settings")
            return settings

        # FIXME: this is ugly, but rendering for now assumes at most one audio
        # and one video tracks
        have_audio = have_video = False
        for track in self.timeline.tracks:
            if isinstance(track.stream, VideoStream) and track.duration != 0:
                have_video = True
            elif isinstance(track.stream, AudioStream) and track.duration != 0:
                have_audio = True

        if not have_audio:
            settings.aencoder = None

        if not have_video:
            settings.vencoder = None

        return settings

    #}

    #{ Save and Load features

    def save(self, location=None, overwrite=False):
        """
        Save the project to the given location.

        @param location: The location to write to. If not specified, the
        current project location will be used (if set).
        @type location: C{URI}
        @param overwrite: Whether to overwrite existing location.
        @type overwrite: C{bool}
        """
        # import here to break circular import
        from pitivi.formatters.format import save_project
        from pitivi.formatters.base import FormatterError

        self.log("saving...")
        location = location or self.uri

        if location == None:
            raise FormatterError("Location unknown")

        save_project(self, location or self.uri, self.format, overwrite)

        self.uri = location

    def setModificationState(self, state):
        self._dirty = state

    def hasUnsavedModifications(self):
        return self._dirty

    def _sourceRemovedCb(self, sourclist, uri, factory):
        self.timeline.removeFactory(factory)