1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
use super::{MonoTrack,TrackSet};

/// Команды аудио системы.
/// 
/// Audio system commands.
pub enum AudioEngineCommand{
// ХРАНИЛИЩЕ \\
    /// Добавляет одноканальный трек в ячейку хранилища.
    /// 
    /// Если нет такой ячейки, то ничего не происходит.
    /// 
    /// Adds a mono-channel track to a storage slot.
    /// 
    /// If there is no such slot, nothing happens.
    AddMono(MonoTrack,usize),

    /// Добавляет несколько одноканальных треков в ячейки хранилища.
    /// 
    /// Если нет таких ячеек, то ничего не происходит.
    /// 
    /// Adds some mono-channel tracks to the storage.
    /// 
    /// If there is no such slots, nothing happens.
    AddMonos(Vec<(MonoTrack,usize)>),

    /// Убирает одноканальный трек из хранилища.
    /// 
    /// Если нет такого трека, то ничего не происходит.
    /// 
    /// Removes a mono-channel track from the storage.
    /// 
    /// If there is no such track, nothing happens.
    RemoveMono(usize),

    /// Убирает несколько одноканальных треков из хранилища.
    /// 
    /// Если нет таких треков, то ничего не происходит.
    /// 
    /// Removes some mono-channel tracks from the storage.
    /// 
    /// If there are no such tracks, nothing happens.
    RemoveMonos(Vec<usize>),

    /// Снимает паузу с треков из плейлиста,
    /// привязанных к треку из хранилища.
    /// 
    /// Unpauses tracks from the playlist
    /// attached to a track from the storage.
    UnpauseMonoFromStorage(usize),

    /// Снимает паузу с треков из плейлиста,
    /// привязанных к трекам из хранилища.
    /// 
    /// Unpauses tracks from the playlist
    /// attached to tracks from the storage.
    UnpauseMonosFromStorage(Vec<usize>),

    /// Ставит на паузу треки из плейлиста,
    /// привязанные к треку из хранилища.
    /// 
    /// Pauses tracks from the playlist
    /// attached to a track from the storage.
    PauseMonoFromStorage(usize),

    /// Ставит на паузу треки из плейлиста,
    /// привязанные к трекам из хранилища.
    /// 
    /// Stops tracks from the playlist
    /// attached to tracks from the storage.
    PauseMonosFromStorage(Vec<usize>),

    /// Останавливает треки из плейлиста,
    /// привязанные к треку из хранилища.
    /// 
    /// Stops tracks from the playlist
    /// attached to a track from the storage.
    StopMonoFromStorage(usize),

    /// Останавливает треки из плейлиста,
    /// привязанные к трекам из хранилища.
    /// 
    /// Stops tracks from the playlist
    /// attached to tracks from the storage.
    StopMonosFromStorage(Vec<usize>),

    /// Устанавливает громкость треков из плейлиста,
    /// привязанных к треку из хранилища.
    /// 
    /// Sets a volume of tracks from the playlist
    /// attached to a track from the storage.
    SetMonoVolumeFromStorage(usize,f32),

    /// Устанавливает громкость треков из плейлиста,
    /// привязанных к трекам из хранилища.
    /// 
    /// Sets a volume of tracks from the playlist
    /// attached to tracks from the storage.
    SetMonosVolumeFromStorage(Vec<usize>,f32),

    /// Устанавливает громкости треков из плейлиста,
    /// привязанных к трекам из хранилища.
    /// 
    /// Sets volumes of tracks from the playlist
    /// attached to tracks from the storage.
    SetMonosVolumesFromStorage(Vec<(usize,f32)>),

// ПЛЕЙЛИСТ \\
    /// Проигрывает одноканальный трек на данных каналах.
    /// 
    /// Plays a mono-channel track on the given channels.
    PlayMonoOnChannels(TrackSet),

    /// Проигрывает несколько одноканальных треков на данных каналах.
    /// 
    /// Plays some mono-channel tracks on the given channels.
    PlayMonosOnChannels(Vec<TrackSet>),

    /// Снимает с паузы трек из плейлиста.
    /// 
    /// Если уже проигрывается, ничего не происходит.
    UnpauseMonoFromPlaylist(usize),

    /// Снимает с паузы трек из плейлиста.
    /// 
    /// Если уже проигрывается, ничего не происходит.
    UnpauseMonosFromPlaylist(Vec<usize>),

    /// Ставит трек из плейлиста на паузу.
    /// 
    /// Если уже на паузе, ничего не происходит.
    PauseMonoFromPlaylist(usize),

    PauseMonosFromPlaylist(Vec<usize>),

    /// Убирает одноканальный трек из плейлиста.
    /// 
    /// Removes a mono-channel track from the playlist.
    RemoveMonoFromPlaylist(usize),

    RemoveMonosFromPlaylist(Vec<usize>),

    /// Отчищает плейлист (список текущих играющих треков).
    /// 
    /// Clears a playlist (the list of currently playing tracks).
    ClearPlaylist,

// Параметры \\
    /// Устанавливает громкость трека в плейлисте.
    /// 
    /// Sets a volume to a track in the playlist.
    SetMonoVolume(usize,f32),

    /// Устанавливает громкость треков в плейлисте.
    /// 
    /// Sets a volume to tracks in the playlist.
    SetMonosVolume(Vec<usize>,f32),

    /// Устанавливает громкости треков в плейлисте.
    /// 
    /// Sets volumes to tracks in the playlist.
    SetMonosVolumes(Vec<(usize,f32)>),

    /// Устанавливает общую громкость.
    /// 
    /// Sets the general volume.
    SetGeneralVolume(f32),

// Остальное \\
    /// Закрывает аудио поток.
    /// 
    /// Closes the audio thead.
    Close,
}

unsafe impl std::marker::Sync for AudioEngineCommand{}
unsafe impl std::marker::Send for AudioEngineCommand{}

/// Результат выполнения команды. The result of command accomplishing.
#[derive(Clone,Debug,PartialEq)]
pub enum AudioCommandResult{
    /// Команда отправлена.
    /// 
    /// A command is sent.
    Sent,

    Index(usize),
    Indices(Vec<usize>),

    /// Аудио поток остановлен.
    /// 
    /// The audio thread is closed.
    ThreadClosed,
    /// Хранилище треков переполнено.
    /// 
    /// The track storage is overflown.
    StorageOverflow,
    // /// Хранилище треков пусто.
    // /// 
    // /// The track storage is empty.
    // StorageIsEmpty,

    /// Нет такого трека (в хранилище или плейлисте).
    /// 
    /// No such track (in the storage or playlist).
    NoSuchTrack,
}


impl AudioCommandResult{
    /// Паникует, если результат не `Ok`.
    /// 
    /// Panics if the result isn't `Ok`.
    pub fn unwrap(self){
        match self{
            AudioCommandResult::ThreadClosed |
                AudioCommandResult::StorageOverflow |
                    AudioCommandResult::NoSuchTrack=>
                        panic!("{:?}",self),
            _=>{}
        }
    }

    /// Паникует и выводит сообщение, если результат не `Ok`.
    /// 
    /// Panics и prints the message if the result isn't `Ok`.
    pub fn expect(self,msg:&str){
        if self!=AudioCommandResult::Sent{
            panic!("{} {:?}",msg,self)
        }
    }
}