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 .
20 #include <sal/config.h>
22 #include <com/sun/star/lang/NoSupportException.hpp>
24 #include <eventqueue.hxx>
25 #include "animationaudionode.hxx"
26 #include <delayevent.hxx>
28 #include "nodetools.hxx"
30 using namespace com::sun::star
;
35 AnimationAudioNode::AnimationAudioNode(
36 const uno::Reference
< animations::XAnimationNode
>& xNode
,
37 const BaseContainerNodeSharedPtr
& rParent
,
38 const NodeContext
& rContext
)
39 : BaseNode( xNode
, rParent
, rContext
),
40 mxAudioNode( xNode
, uno::UNO_QUERY_THROW
),
44 mxAudioNode
->getSource() >>= maSoundURL
;
46 OSL_ENSURE( !maSoundURL
.isEmpty(),
47 "could not extract sound source URL/empty URL string" );
49 ENSURE_OR_THROW( getContext().mxComponentContext
.is(),
50 "Invalid component context" );
53 void AnimationAudioNode::dispose()
60 void AnimationAudioNode::activate_st()
64 AnimationEventHandlerSharedPtr
aHandler(
65 std::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
67 "could not cast self to AnimationEventHandler?" );
68 getContext().mrEventMultiplexer
.addCommandStopAudioHandler( aHandler
);
70 if (mpPlayer
&& mpPlayer
->startPlayback())
72 // TODO(F2): Handle end time attribute, too
73 if( getXAnimationNode()->getDuration().hasValue() )
75 scheduleDeactivationEvent();
79 // no node duration. Take inherent media time, then
81 scheduleDeactivationEvent(
82 makeDelay( [self
] () { self
->deactivate(); },
83 mpPlayer
->getDuration(),
84 "AnimationAudioNode::deactivate with delay") );
91 scheduleDeactivationEvent(
92 makeEvent( [self
] () { self
->deactivate(); },
93 "AnimationAudioNode::deactivate without delay") );
97 // TODO(F2): generate deactivation event, when sound
100 // libc++ and MSVC std::bind doesn't cut it here, and it's not possible to use
101 // a lambda because the preprocessor thinks that comma in capture list
102 // separates macro parameters
103 struct NotifyAudioStopped
105 EventMultiplexer
& m_rEventMultiplexer
;
106 ::std::shared_ptr
<BaseNode
> m_pSelf
;
107 NotifyAudioStopped(EventMultiplexer
& rEventMultiplexer
,
108 ::std::shared_ptr
<BaseNode
> const& pSelf
)
109 : m_rEventMultiplexer(rEventMultiplexer
), m_pSelf(pSelf
) { }
113 m_rEventMultiplexer
.notifyAudioStopped(m_pSelf
);
117 void AnimationAudioNode::deactivate_st( NodeState
/*eDestState*/ )
119 AnimationEventHandlerSharedPtr
aHandler(
120 std::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
121 OSL_ENSURE( aHandler
,
122 "could not cast self to AnimationEventHandler?" );
123 getContext().mrEventMultiplexer
.removeCommandStopAudioHandler( aHandler
);
128 mpPlayer
->stopPlayback();
132 // notify _after_ state change:
133 getContext().mrEventQueue
.addEvent(
134 makeEvent( NotifyAudioStopped(getContext().mrEventMultiplexer
, getSelf()),
135 "AnimationAudioNode::notifyAudioStopped") );
138 bool AnimationAudioNode::hasPendingAnimation() const
140 // force slide to use the animation framework
141 // (otherwise, a single sound on the slide would
146 void AnimationAudioNode::createPlayer() const
153 mpPlayer
= SoundPlayer::create( getContext().mrEventMultiplexer
,
155 getContext().mxComponentContext
);
157 catch( lang::NoSupportException
& )
159 // catch possible exceptions from SoundPlayer,
160 // since being not able to playback the sound
161 // is not a hard error here (remainder of the
162 // animations should still work).
166 void AnimationAudioNode::resetPlayer() const
170 mpPlayer
->stopPlayback();
176 bool AnimationAudioNode::handleAnimationEvent(
177 const AnimationNodeSharedPtr
& /*rNode*/ )
179 // TODO(F2): for now we support only STOPAUDIO events.
184 } // namespace internal
185 } // namespace presentation
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */