~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/timeline/timeline.py

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2007-01-31 15:32:37 UTC
  • mto: (3.2.1 hardy) (1.2.1 upstream) (6.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20070131153237-de4p8lipjv8x5x3b
Tags: upstream-0.10.2
ImportĀ upstreamĀ versionĀ 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# PiTiVi , Non-linear video editor
 
2
#
 
3
#       pitivi/timeline.py
 
4
#
 
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this program; if not, write to the
 
19
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
# Boston, MA 02111-1307, USA.
 
21
 
 
22
"""
 
23
Timeline and timeline objects
 
24
"""
 
25
 
 
26
import gobject
 
27
import gst
 
28
 
 
29
from pitivi.settings import ExportSettings
 
30
from composition import TimelineComposition
 
31
from objects import MEDIA_TYPE_AUDIO, MEDIA_TYPE_VIDEO
 
32
 
 
33
class Timeline(gobject.GObject):
 
34
    """
 
35
    Fully fledged timeline
 
36
    """
 
37
 
 
38
    # TODO make the compositions more versatile
 
39
    # for the time being we hardcode an audio and a video composition
 
40
    
 
41
    def __init__(self, project):
 
42
        gst.log("new Timeline for project %s" % project)
 
43
        gobject.GObject.__init__(self)
 
44
        self.project = project
 
45
 
 
46
        self.timeline = gst.Bin("timeline-" + project.name)
 
47
        self._fillContents()
 
48
 
 
49
    def _fillContents(self):
 
50
        # TODO create the initial timeline according to the project settings
 
51
        self.audiocomp = TimelineComposition(media_type = MEDIA_TYPE_AUDIO, name="audiocomp")
 
52
        self.videocomp = TimelineComposition(media_type = MEDIA_TYPE_VIDEO, name="videocomp")
 
53
        self.videocomp.linkObject(self.audiocomp)
 
54
 
 
55
        # add default audio/video sources
 
56
        defaultaudio = gst.element_factory_make("audiotestsrc")
 
57
        defaultaudio.props.volume = 0
 
58
        defaultaudiosource = gst.element_factory_make("gnlsource", "defaultaudiosource")
 
59
        defaultaudiosource.add(defaultaudio)
 
60
        self.audiocomp.setDefaultSource(defaultaudiosource)
 
61
 
 
62
        defaultvideo = gst.element_factory_make("videotestsrc")
 
63
        defaultvideo.props.pattern = 2
 
64
        defaultvideosource = gst.element_factory_make("gnlsource", "defaultvideosource")
 
65
        defaultvideosource.add(defaultvideo)
 
66
        self.videocomp.setDefaultSource(defaultvideosource)
 
67
 
 
68
        self.timeline.add(self.audiocomp.gnlobject,
 
69
                          self.videocomp.gnlobject)
 
70
        self.audiocomp.gnlobject.connect("pad-added", self._newAudioPadCb)
 
71
        self.videocomp.gnlobject.connect("pad-added", self._newVideoPadCb)
 
72
        self.audiocomp.gnlobject.connect("pad-removed", self._removedAudioPadCb)
 
73
        self.videocomp.gnlobject.connect("pad-removed", self._removedVideoPadCb)
 
74
 
 
75
    def _newAudioPadCb(self, unused_audiocomp, pad):
 
76
        asrc = gst.GhostPad("asrc", pad)
 
77
        asrc.set_active(True)
 
78
        self.timeline.add_pad(asrc)
 
79
 
 
80
    def _newVideoPadCb(self, unused_videocomp, pad):
 
81
        vsrc = gst.GhostPad("vsrc", pad)
 
82
        vsrc.set_active(True)
 
83
        self.timeline.add_pad(vsrc)
 
84
 
 
85
    def _removedAudioPadCb(self, unused_audiocomp, unused_pad):
 
86
        self.timeline.remove_pad(self.timeline.get_pad("asrc"))
 
87
 
 
88
    def _removedVideoPadCb(self, unused_audiocomp, unused_pad):
 
89
        self.timeline.remove_pad(self.timeline.get_pad("vsrc"))
 
90
 
 
91
    def getAutoSettings(self):
 
92
        v = self.videocomp._getAutoSettings()
 
93
        a = self.audiocomp._getAutoSettings()
 
94
        if not v and not a:
 
95
            return None
 
96
        # return an ExportSettings containing the combination of
 
97
        # the autosettings from the audio and video composition.
 
98
        s = ExportSettings()
 
99
        if v:
 
100
            s.videowidth = v.videowidth
 
101
            s.videoheight = v.videoheight
 
102
            s.videorate = v.videorate
 
103
            s.videopar = v.videopar
 
104
        if a:
 
105
            s.audiochannels = a.audiochannels
 
106
            s.audiorate = a.audiorate
 
107
            s.audiodepth = a.audiodepth
 
108
        return s
 
109
 
 
110