Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2024 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #ifndef MUSE_AUDIO_PLAYER_H
24 : #define MUSE_AUDIO_PLAYER_H
25 :
26 : #include "../iplayer.h"
27 :
28 : #include "global/async/asyncable.h"
29 :
30 : #include "modularity/ioc.h"
31 : #include "audio/common/rpc/irpcchannel.h"
32 :
33 : namespace muse::audio {
34 : class Player : public IPlayer, public Contextable, public async::Asyncable
35 : {
36 : GlobalInject<rpc::IRpcChannel> channel;
37 :
38 : public:
39 5 : Player(const muse::modularity::ContextPtr& ctx)
40 5 : : Contextable(ctx) {}
41 :
42 : void init();
43 : void deinit();
44 :
45 : async::Promise<Ret> prepareToPlay() override;
46 :
47 : void play(const secs_t delay = 0) override;
48 : void seek(const secs_t newPosition, const bool flushSound = true) override;
49 : void stop() override;
50 : void pause() override;
51 : void resume(const secs_t delay = 0) override;
52 :
53 : PlaybackStatus playbackStatus() const override;
54 : async::Channel<PlaybackStatus> playbackStatusChanged() const override;
55 :
56 : void setDuration(const secs_t duration) override;
57 : async::Promise<bool> setLoop(const secs_t from, const secs_t to) override;
58 : void resetLoop() override;
59 :
60 : secs_t playbackPosition() const override;
61 : async::Channel<secs_t> playbackPositionChanged() const override;
62 :
63 : private:
64 :
65 : rpc::CtxId ctxId() const;
66 :
67 : PlaybackStatus m_playbackStatus = PlaybackStatus::Stopped;
68 : async::Channel<PlaybackStatus> m_playbackStatusChanged;
69 :
70 : secs_t m_playbackPosition = 0.0;
71 : async::Channel<secs_t> m_playbackPositionChanged;
72 : };
73 : }
74 :
75 : #endif // MUSE_AUDIO_PLAYER_H
|