[Multimedia] Modified a constructor of the Display class not to check the raw video...
[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
17 using System;
18 using Native = Interop.AudioEffect;
19
20 namespace Tizen.Multimedia
21 {
22     /// <summary>
23     /// Provides the ability to control the audio effects for <see cref="Multimedia.Player"/>.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class AudioEffect
27     {
28         private readonly EqualizerBand[] _bands;
29
30         internal AudioEffect(Player owner)
31         {
32             Player = owner;
33
34             bool available = false;
35
36             Native.EqualizerIsAvailable(Player.Handle, out available).
37                 ThrowIfFailed("Failed to initialize the AudioEffect");
38
39             IsAvailable = available;
40
41             if (IsAvailable == false)
42             {
43                 return;
44             }
45
46             int count = 0;
47             Native.GetEqualizerBandsCount(Player.Handle, out count).
48                 ThrowIfFailed("Failed to initialize the AudioEffect");
49
50             int min = 0;
51             int max = 0;
52             Native.GetEqualizerLevelRange(Player.Handle, out min, out max).
53                 ThrowIfFailed("Failed to initialize the AudioEffect");
54
55             Count = count;
56             BandLevelRange = new Range(min, max);
57
58             _bands = new EqualizerBand[count];
59         }
60
61         /// <summary>
62         /// Gets a <see cref="EqualizerBand"/> at the specified index.
63         /// </summary>
64         /// <param name="index">The index of the band to get.</param>
65         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
66         /// <exception cref="ArgumentOutOfRangeException">
67         ///     <pramref name="index"/> is less than zero.<br/>
68         ///     -or-<br/>
69         ///     <paramref name="index"/> is equal to or greater than <see cref="Count"/>.
70         /// </exception>
71         /// <since_tizen> 3 </since_tizen>
72         public EqualizerBand this[int index]
73         {
74             get
75             {
76                 Player.ValidateNotDisposed();
77
78                 if (index < 0 || Count <= index)
79                 {
80                     throw new ArgumentOutOfRangeException(nameof(index), index,
81                         $"Valid index is 0 <= x < { nameof(Count) } ");
82                 }
83
84                 if (_bands[index] == null)
85                 {
86                     _bands[index] = new EqualizerBand(this, index);
87                 }
88                 Log.Info(PlayerLog.Tag, "get equalizer band : " + _bands[index]);
89                 return _bands[index];
90             }
91         }
92
93         /// <summary>
94         /// Clears the equalizer effect.
95         /// </summary>
96         /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
97         /// <since_tizen> 3 </since_tizen>
98         public void Clear()
99         {
100             Player.ValidateNotDisposed();
101
102             Native.EqualizerClear(Player.Handle).
103                 ThrowIfFailed("Failed to clear equalizer effect");
104         }
105
106         /// <summary>
107         /// Gets the number of items.
108         /// </summary>
109         /// <since_tizen> 3 </since_tizen>
110         public int Count { get; }
111
112         /// <summary>
113         /// Gets the band level range of the bands in the dB.
114         /// </summary>
115         /// <since_tizen> 3 </since_tizen>
116         public Range BandLevelRange { get; }
117
118         /// <summary>
119         /// Gets the value whether the AudioEffect is available or not.
120         /// </summary>
121         /// <since_tizen> 3 </since_tizen>
122         public bool IsAvailable { get; }
123
124         /// <summary>
125         /// Gets the player that this AudioEffect belongs to.
126         /// </summary>
127         /// <since_tizen> 3 </since_tizen>
128         public Player Player { get; }
129     }
130 }