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 .
21 #include "eventqueue.hxx"
22 #include "animationaudionode.hxx"
23 #include "delayevent.hxx"
25 #include "nodetools.hxx"
27 using namespace com::sun::star
;
32 AnimationAudioNode::AnimationAudioNode(
33 const uno::Reference
< animations::XAnimationNode
>& xNode
,
34 const BaseContainerNodeSharedPtr
& rParent
,
35 const NodeContext
& rContext
)
36 : BaseNode( xNode
, rParent
, rContext
),
37 mxAudioNode( xNode
, uno::UNO_QUERY_THROW
),
41 mxAudioNode
->getSource() >>= maSoundURL
;
43 OSL_ENSURE( !maSoundURL
.isEmpty(),
44 "could not extract sound source URL/empty URL string" );
46 ENSURE_OR_THROW( getContext().mxComponentContext
.is(),
47 "Invalid component context" );
50 void AnimationAudioNode::dispose()
57 void AnimationAudioNode::activate_st()
61 AnimationEventHandlerSharedPtr
aHandler(
62 std::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
64 "could not cast self to AnimationEventHandler?" );
65 getContext().mrEventMultiplexer
.addCommandStopAudioHandler( aHandler
);
67 if (mpPlayer
&& mpPlayer
->startPlayback())
69 // TODO(F2): Handle end time attribute, too
70 if( getXAnimationNode()->getDuration().hasValue() )
72 scheduleDeactivationEvent();
76 // no node duration. Take inherent media time, then
78 scheduleDeactivationEvent(
79 makeDelay( [self
] () { self
->deactivate(); },
80 mpPlayer
->getDuration(),
81 "AnimationAudioNode::deactivate with delay") );
88 scheduleDeactivationEvent(
89 makeEvent( [self
] () { self
->deactivate(); },
90 "AnimationAudioNode::deactivate without delay") );
94 // TODO(F2): generate deactivation event, when sound
97 // libc++ and MSVC std::bind doesn't cut it here, and it's not possible to use
98 // a lambda because the preprocessor thinks that comma in capture list
99 // separates macro parameters
100 struct NotifyAudioStopped
102 EventMultiplexer
& m_rEventMultiplexer
;
103 ::std::shared_ptr
<BaseNode
> m_pSelf
;
104 NotifyAudioStopped(EventMultiplexer
& rEventMultiplexer
,
105 ::std::shared_ptr
<BaseNode
> const& pSelf
)
106 : m_rEventMultiplexer(rEventMultiplexer
), m_pSelf(pSelf
) { }
110 m_rEventMultiplexer
.notifyAudioStopped(m_pSelf
);
114 void AnimationAudioNode::deactivate_st( NodeState
/*eDestState*/ )
116 AnimationEventHandlerSharedPtr
aHandler(
117 std::dynamic_pointer_cast
<AnimationEventHandler
>( getSelf() ) );
118 OSL_ENSURE( aHandler
,
119 "could not cas self to AnimationEventHandler?" );
120 getContext().mrEventMultiplexer
.removeCommandStopAudioHandler( aHandler
);
125 mpPlayer
->stopPlayback();
129 // notify _after_ state change:
130 getContext().mrEventQueue
.addEvent(
131 makeEvent( NotifyAudioStopped(getContext().mrEventMultiplexer
, getSelf()),
132 "AnimationAudioNode::notifyAudioStopped") );
135 bool AnimationAudioNode::hasPendingAnimation() const
137 // force slide to use the animation framework
138 // (otherwise, a single sound on the slide would
143 void AnimationAudioNode::createPlayer() const
150 mpPlayer
= SoundPlayer::create( getContext().mrEventMultiplexer
,
152 getContext().mxComponentContext
);
154 catch( lang::NoSupportException
& )
156 // catch possible exceptions from SoundPlayer,
157 // since being not able to playback the sound
158 // is not a hard error here (remainder of the
159 // animations should still work).
163 void AnimationAudioNode::resetPlayer() const
167 mpPlayer
->stopPlayback();
173 bool AnimationAudioNode::handleAnimationEvent(
174 const AnimationNodeSharedPtr
& /*rNode*/ )
176 // TODO(F2): for now we support only STOPAUDIO events.
181 } // namespace internal
182 } // namespace presentation
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */