1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <canvas/debug.hxx>
23 #include <canvas/verbosetrace.hxx>
25 #include "eventqueue.hxx"
26 #include "animationaudionode.hxx"
27 #include "delayevent.hxx"
29 #include "nodetools.hxx"
30 #include "boost/bind.hpp"
32 using namespace com::sun::star
;
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
),
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()
62 void AnimationAudioNode::activate_st()
66 AnimationEventHandlerSharedPtr
aHandler(
67 boost::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
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();
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") );
91 scheduleDeactivationEvent(
92 makeEvent( boost::bind( &AnimationNode::deactivate
, getSelf() ),
93 "AnimationAudioNode::deactivate without delay") );
97 // TODO(F2): generate deactivation event, when sound
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
);
111 mpPlayer
->stopPlayback();
115 // notify _after_ state change:
116 getContext().mrEventQueue
.addEvent(
117 makeEvent( boost::bind( &EventMultiplexer::notifyAudioStopped
,
118 boost::ref(getContext().mrEventMultiplexer
),
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
131 void AnimationAudioNode::createPlayer() const
138 mpPlayer
= SoundPlayer::create( getContext().mrEventMultiplexer
,
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
155 mpPlayer
->stopPlayback();
161 bool AnimationAudioNode::handleAnimationEvent(
162 const AnimationNodeSharedPtr
& /*rNode*/ )
164 // TODO(F2): for now we support only STOPAUDIO events.
169 } // namespace internal
170 } // namespace presentation
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */