Splitted the project into multiple module level projects.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / AudioEffect.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 using System;
17 using static Interop;
18
19 namespace Tizen.Multimedia
20 {
21     /// <summary>
22     /// Provides the ability to control the audio effects for <see cref="Multimedia.Player"/>.
23     /// </summary>
24     public class AudioEffect
25     {
26         private readonly EqualizerBand[] _bands;
27
28         internal AudioEffect(Player owner)
29         {
30             Player = owner;
31
32             bool available = false;
33
34             NativePlayer.AudioEffectEqualizerIsAvailable(Player.Handle, out available).
35                 ThrowIfFailed("Failed to initialize the AudioEffect");
36
37             IsAvailable = available;
38
39             if (IsAvailable == false)
40             {
41                 return;
42             }
43
44             int count = 0;
45             NativePlayer.AudioEffectGetEqualizerBandsCount(Player.Handle, out count).
46                 ThrowIfFailed("Failed to initialize the AudioEffect");
47
48             int min = 0;
49             int max = 0;
50             NativePlayer.AudioEffectGetEqualizerLevelRange(Player.Handle, out min, out max).
51                 ThrowIfFailed("Failed to initialize the AudioEffect");
52
53             Count = count;
54             MinBandLevel = min;
55             MaxBandLevel = max;
56
57             _bands = new EqualizerBand[count];
58         }
59
60         /// <summary>
61         /// Gets a <see cref="EqualizerBand"/> at the specified index.
62         /// </summary>
63         /// <param name="index">The index of the band to get</param>
64         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
65         /// <exception cref="ArgumentOutOfRangeException">
66         ///     index is less than zero.
67         ///     <para>-or-</para>
68         ///     index is equal to or greater than <see cref="Count"/>.
69         /// </exception>
70         public EqualizerBand this[int index]
71         {
72             get
73             {
74                 Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
75                 Player.ValidateNotDisposed();
76
77                 if (index < 0 || Count <= index)
78                 {
79                     throw new ArgumentOutOfRangeException(nameof(index), index,
80                         $"Valid index is 0 <= x < { nameof(Count) } ");
81                 }
82
83                 if (_bands[index] == null)
84                 {
85                     _bands[index] = new EqualizerBand(this, index);
86                 }
87                 Log.Info(PlayerLog.Tag, "get equalizer band : " + _bands[index]);
88                 return _bands[index];
89             }
90         }
91
92         /// <summary>
93         /// Clears the equalizer effect.
94         /// </summary>
95         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
96         public void Clear()
97         {
98             Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
99             Player.ValidateNotDisposed();
100
101             NativePlayer.AudioEffectEqualizerClear(Player.Handle).
102                 ThrowIfFailed("Failed to clear equalizer effect");
103             Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
104         }
105
106         public int Count{ get; }
107
108         // TODO replace with range struct
109         /// <summary>
110         /// Get the minimum band level of the bands in dB.
111         /// </summary>
112         public int MinBandLevel { get; }
113
114         /// <summary>
115         /// Gets the maximum band level of the bands in dB.
116         /// </summary>
117         public int MaxBandLevel { get; }
118
119         /// <summary>
120         /// Gets the value whether the AudioEffect is available or not.
121         /// </summary>
122         public bool IsAvailable { get; }
123
124         /// <summary>
125         /// Gets the player that this AudioEffect belongs to.
126         /// </summary>
127         public Player Player { get; }
128     }
129 }