Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 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 : #pragma once
24 :
25 : #include "async/channel.h"
26 : #include "async/notification.h"
27 : #include "async/promise.h"
28 : #include "audio/common/audiotypes.h"
29 : #include "global/progress.h"
30 : #include "modularity/imoduleinterface.h"
31 :
32 : #include "engraving/dom/noteval.h"
33 :
34 : #include "notation/inotation_fwd.h"
35 : #include "notation/inotationsolomutestate.h"
36 : #include "notation/types/tempo.h"
37 :
38 : #include "playbacktypes.h"
39 :
40 : namespace mu::engraving {
41 : class EngravingItem;
42 : class Segment;
43 : }
44 :
45 : namespace mu::playback {
46 : //! NOTE We need to get the current state: playing position, status
47 : //! But direct manage (play, seek..) is bad idea, need send commands (to playback controller)
48 : //! So, this interface limits the playback controller interface so that it cannot be misused.
49 : class IPlaybackState : MODULE_CONTEXT_INTERFACE
50 : {
51 0 : INTERFACE_ID(IPlaybackState)
52 :
53 : public:
54 34 : virtual ~IPlaybackState() = default;
55 :
56 : virtual bool isPlaying() const = 0;
57 : virtual muse::async::Channel<bool> isPlayingChanged() const = 0;
58 :
59 : virtual muse::audio::secs_t playbackPosition() const = 0;
60 : virtual muse::async::Channel<muse::audio::secs_t> playbackPositionChanged() const = 0;
61 : };
62 :
63 : class IPlaybackController : public IPlaybackState
64 : {
65 0 : INTERFACE_ID(IPlaybackController)
66 :
67 : public:
68 21 : virtual ~IPlaybackController() = default;
69 :
70 : virtual bool isPlaybackInited() const = 0;
71 : virtual muse::async::Channel<bool> playbackInitedChanged() const = 0;
72 :
73 : virtual bool isPlayAllowed() const = 0;
74 : virtual muse::async::Channel<bool> isPlayAllowedChanged() const = 0;
75 :
76 : virtual muse::Ret togglePlay() = 0;
77 : virtual muse::Ret play(bool showErrors = true) = 0;
78 : virtual muse::Ret playFromSelection(bool showErrors = true) = 0;
79 : virtual muse::Ret pause(bool select = false) = 0;
80 : virtual muse::Ret stop() = 0;
81 : virtual muse::Ret rewind(muse::secs_t secs) = 0;
82 :
83 : virtual bool isLoopEnabled() const = 0;
84 : virtual muse::async::Channel<bool> loopEnabledChanged() const = 0;
85 : virtual muse::Ret toggleLoopPlayback() = 0;
86 : virtual muse::Ret addLoopBoundary(LoopBoundaryType type) = 0;
87 :
88 : virtual muse::Ret toggleMetronome() = 0;
89 :
90 : virtual muse::Ret toggleMidiInput() = 0;
91 : virtual muse::Ret setMidiUseWrittenPitch(bool useWrittenPitch) = 0;
92 :
93 : virtual muse::Ret togglePlayRepeats() = 0;
94 : virtual muse::Ret togglePlayChordSymbols() = 0;
95 : virtual muse::Ret toggleAutomaticallyPan() = 0;
96 : virtual muse::Ret toggleCountIn() = 0;
97 : virtual muse::Ret toggleHearPlaybackWhenEditing() = 0;
98 :
99 : virtual muse::Ret reloadPlaybackCache() = 0;
100 :
101 : using InstrumentTrackIdMap = std::unordered_map<engraving::InstrumentTrackId, muse::audio::TrackId>;
102 : virtual const InstrumentTrackIdMap& instrumentTrackIdMap() const = 0;
103 :
104 : using AuxTrackIdMap = std::map<muse::audio::aux_channel_idx_t, muse::audio::TrackId>;
105 : virtual const AuxTrackIdMap& auxTrackIdMap() const = 0;
106 :
107 : virtual muse::async::Channel<muse::audio::TrackId> trackAdded() const = 0;
108 : virtual muse::async::Channel<muse::audio::TrackId> trackRemoved() const = 0;
109 :
110 : virtual std::string auxChannelName(muse::audio::aux_channel_idx_t index) const = 0;
111 : virtual muse::async::Channel<muse::audio::aux_channel_idx_t, std::string> auxChannelNameChanged() const = 0;
112 :
113 : virtual muse::async::Promise<muse::audio::SoundPresetList>
114 : availableSoundPresets(const engraving::InstrumentTrackId& instrumentTrackId) const = 0;
115 :
116 : using SoloMuteState = notation::INotationSoloMuteState::SoloMuteState;
117 :
118 : virtual const SoloMuteState& trackSoloMuteState(const engraving::InstrumentTrackId& trackId) const = 0;
119 : virtual void setTrackSoloMuteState(const engraving::InstrumentTrackId& trackId, const SoloMuteState& state) = 0;
120 :
121 : struct PlayParams {
122 15 : PlayParams() {}
123 :
124 : std::optional<muse::mpe::duration_t> duration; // no duration -> use default
125 : bool flushSound = true;
126 : };
127 :
128 : virtual void playElements(const std::vector<const engraving::EngravingItem*>& elements,
129 : const PlayParams& params = PlayParams(), bool isMidi = false) = 0;
130 : virtual void playNotes(const engraving::NoteValList& notes, engraving::staff_idx_t staffIdx, const engraving::Segment* segment,
131 : const PlayParams& params = PlayParams()) = 0;
132 : virtual void playMetronome(int tick) = 0;
133 :
134 : virtual void triggerControllers(const muse::mpe::ControllerChangeEventList& list, engraving::staff_idx_t staffIdx, int tick) = 0;
135 :
136 : virtual void seekElement(const engraving::EngravingItem* element, bool flushSound = true) = 0;
137 : virtual void seekBeat(int measureIndex, int beatIndex, bool flushSound = true) = 0;
138 :
139 : virtual muse::secs_t totalPlayTime() const = 0;
140 : virtual muse::async::Notification totalPlayTimeChanged() const = 0;
141 :
142 : virtual const notation::Tempo& currentTempo() const = 0;
143 : virtual muse::async::Notification currentTempoChanged() const = 0;
144 :
145 : virtual engraving::MeasureBeat currentBeat() const = 0;
146 : virtual muse::audio::secs_t beatToSecs(int measureIndex, int beatIndex) const = 0;
147 :
148 : virtual double tempoMultiplier() const = 0;
149 : virtual void setTempoMultiplier(double multiplier) = 0;
150 :
151 : virtual muse::Progress loadingProgress() const = 0;
152 :
153 : virtual void applyProfile(const SoundProfileName& profileName) = 0;
154 :
155 : virtual void setNotation(notation::INotationPtr notation) = 0;
156 : virtual void setIsExportingAudio(bool exporting) = 0;
157 :
158 : virtual const std::map<muse::audio::TrackId, muse::audio::AudioResourceMeta>& onlineSounds() const = 0;
159 : virtual muse::async::Notification onlineSoundsChanged() const = 0;
160 : virtual muse::Progress onlineSoundsProcessingProgress() const = 0;
161 : };
162 : }
|