fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / animationnodes / animationaudionode.cxx
blob5e953a977f5997cd158a4a58b243b9ee6af1f51b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // must be first
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
25 #include "eventqueue.hxx"
26 #include "animationaudionode.hxx"
27 #include "delayevent.hxx"
28 #include "tools.hxx"
29 #include "nodetools.hxx"
30 #include "boost/bind.hpp"
32 using namespace com::sun::star;
34 namespace slideshow {
35 namespace internal {
37 AnimationAudioNode::AnimationAudioNode(
38 const uno::Reference< animations::XAnimationNode >& xNode,
39 const BaseContainerNodeSharedPtr& rParent,
40 const NodeContext& rContext )
41 : BaseNode( xNode, rParent, rContext ),
42 mxAudioNode( xNode, uno::UNO_QUERY_THROW ),
43 maSoundURL(),
44 mpPlayer()
46 mxAudioNode->getSource() >>= maSoundURL;
48 OSL_ENSURE( !maSoundURL.isEmpty(),
49 "could not extract sound source URL/empty URL string" );
51 ENSURE_OR_THROW( getContext().mxComponentContext.is(),
52 "Invalid component context" );
55 void AnimationAudioNode::dispose()
57 resetPlayer();
58 mxAudioNode.clear();
59 BaseNode::dispose();
62 void AnimationAudioNode::activate_st()
64 createPlayer();
66 AnimationEventHandlerSharedPtr aHandler(
67 boost::dynamic_pointer_cast<AnimationEventHandler>( getSelf() ) );
68 OSL_ENSURE( aHandler,
69 "could not cast self to AnimationEventHandler?" );
70 getContext().mrEventMultiplexer.addCommandStopAudioHandler( aHandler );
72 if (mpPlayer && mpPlayer->startPlayback())
74 // TODO(F2): Handle end time attribute, too
75 if( getXAnimationNode()->getDuration().hasValue() )
77 scheduleDeactivationEvent();
79 else
81 // no node duration. Take inherent media time, then
82 scheduleDeactivationEvent(
83 makeDelay( boost::bind( &AnimationNode::deactivate, getSelf() ),
84 mpPlayer->getDuration(),
85 "AnimationAudioNode::deactivate with delay") );
88 else
90 // deactivate ASAP:
91 scheduleDeactivationEvent(
92 makeEvent( boost::bind( &AnimationNode::deactivate, getSelf() ),
93 "AnimationAudioNode::deactivate without delay") );
97 // TODO(F2): generate deactivation event, when sound
98 // is over
100 void AnimationAudioNode::deactivate_st( NodeState /*eDestState*/ )
102 AnimationEventHandlerSharedPtr aHandler(
103 boost::dynamic_pointer_cast<AnimationEventHandler>( getSelf() ) );
104 OSL_ENSURE( aHandler,
105 "could not cas self to AnimationEventHandler?" );
106 getContext().mrEventMultiplexer.removeCommandStopAudioHandler( aHandler );
108 // force-end sound
109 if (mpPlayer)
111 mpPlayer->stopPlayback();
112 resetPlayer();
115 // notify _after_ state change:
116 getContext().mrEventQueue.addEvent(
117 makeEvent( boost::bind( &EventMultiplexer::notifyAudioStopped,
118 boost::ref(getContext().mrEventMultiplexer),
119 getSelf() ),
120 "AnimationAudioNode::notifyAudioStopped") );
123 bool AnimationAudioNode::hasPendingAnimation() const
125 // force slide to use the animation framework
126 // (otherwise, a single sound on the slide would
127 // not be played).
128 return true;
131 void AnimationAudioNode::createPlayer() const
133 if (mpPlayer)
134 return;
138 mpPlayer = SoundPlayer::create( getContext().mrEventMultiplexer,
139 maSoundURL,
140 getContext().mxComponentContext );
142 catch( lang::NoSupportException& )
144 // catch possible exceptions from SoundPlayer,
145 // since being not able to playback the sound
146 // is not a hard error here (remainder of the
147 // animations should still work).
151 void AnimationAudioNode::resetPlayer() const
153 if (mpPlayer)
155 mpPlayer->stopPlayback();
156 mpPlayer->dispose();
157 mpPlayer.reset();
161 bool AnimationAudioNode::handleAnimationEvent(
162 const AnimationNodeSharedPtr& /*rNode*/ )
164 // TODO(F2): for now we support only STOPAUDIO events.
165 deactivate();
166 return true;
169 } // namespace internal
170 } // namespace presentation
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */