Skip to content

Commit

Permalink
Added Equalizer & EqualizerMode to Dart
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed May 19, 2021
1 parent 60b72cb commit 5c499a6
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/dart_vlc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

export 'package:dart_vlc/src/player.dart';
export 'package:dart_vlc/src/equalizer.dart';
export 'package:dart_vlc/src/broadcast.dart';
export 'package:dart_vlc/src/record.dart';
export 'package:dart_vlc/src/chromecast.dart';
Expand All @@ -18,6 +19,7 @@ export 'package:dart_vlc/src/playerState/playerState.dart';
export 'package:dart_vlc/src/mediaSource/mediaSource.dart';
export 'package:dart_vlc/src/mediaSource/media.dart';
export 'package:dart_vlc/src/mediaSource/playlist.dart';
export 'package:dart_vlc/src/enums/equalizerMode.dart';
export 'package:dart_vlc/src/enums/mediaSourceType.dart';
export 'package:dart_vlc/src/enums/mediaType.dart';
export 'package:dart_vlc/src/enums/playlistMode.dart';
23 changes: 23 additions & 0 deletions lib/src/enums/equalizerMode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


/// Predefined presets for [Equalizer].
enum EqualizerMode {
flat,
classical,
club,
dance,
fullBass,
fullBassAndTreble,
fullTreble,
headphones,
largeHall,
live,
party,
pop,
reggae,
rock,
ska,
soft,
softRock,
techno
}
93 changes: 93 additions & 0 deletions lib/src/equalizer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'package:dart_vlc/src/channel.dart';
import 'package:dart_vlc/src/enums/equalizerMode.dart';


/// Internally used class to avoid direct creation of the object of a [Equalizer] class.
class _Equalizer extends Equalizer {}


/// Defines an [Equalizer] instance for usage in a [Player].
///
/// Use [Equalizer.createEmpty] for creating a default equalizer & [Equalizer.createMode] for creating an equalizer using a preset from [EqualizerMode].
///
/// Example
///
/// ```dart
/// Player player = new Player(id: 0);
/// Equalizer equalizer = Equalizer.createMode(EqualizerMode.party);
/// player.setEqualizer(equalizer);
/// ```
///
class Equalizer {
/// Unique Id associated with this [Equalizer].
late int id;
/// Preamp value of the [Equalizer]. Use [Equalizer.setPreAmp] to change value.
double preAmp = 0.0;
/// Values of amps of various bands in [Equalizer]. Use [Equalizer.setBandAmp] to change values.
Map<double, double> bandAmps = {};
/// Preset if [Equalizer] is initialized using [Equalizer.createMode], else `null`.
EqualizerMode? mode;

/// Creates a default [Equalizer] instance with all values set to `0.0`.
static Future<Equalizer> createEmpty() async {
Equalizer equalizer = new _Equalizer();
dynamic _equalizer = await channel.invokeMethod(
'Equalizer.createEmpty',
{},
);
equalizer.id = _equalizer['id'];
equalizer.preAmp = _equalizer['preAmp'];
equalizer.bandAmps = Map<double, double>.from(_equalizer['bandAmps']);
return equalizer;
}

/// Creates an [Equalizer] instance with any preset from [EqualizerMode].
static Future<Equalizer> createMode(EqualizerMode mode) async {
Equalizer equalizer = new _Equalizer();
dynamic _equalizer = await channel.invokeMethod(
'Equalizer.createMode',
{
'mode': mode.index,
},
);
equalizer.id = _equalizer['id'];
equalizer.mode = mode;
equalizer.preAmp = _equalizer['preAmp'];
equalizer.bandAmps = Map<double, double>.from(_equalizer['bandAmps']);
return equalizer;
}

/// Sets value of [Equalizer.preAmp].
///
/// Constraints:
/// `-20.0 < amp < 20.0`
///
Future<void> setPreAmp(double amp) async {
await channel.invokeMethod(
'Equalizer.setPreAmp',
{
'id': this.id,
'preAmp': amp,
},
);
this.preAmp = amp;
}

/// Sets value of any particular band from [Equalizer.bandAmps].
/// Band whose `amp` needs to be changed, must be present in [Equalizer.bandAmps].
///
/// Constraints:
/// `-20.0 < amp < 20.0`
///
Future<void> setBandAmp(double band, double amp) async {
await channel.invokeMethod(
'Equalizer.setBandAmp',
{
'id': this.id,
'band': band,
'amp': amp,
},
);
this.bandAmps[band] = amp;
}
}
13 changes: 13 additions & 0 deletions lib/src/player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:dart_vlc/dart_vlc.dart';
import 'package:dart_vlc/src/channel.dart';
import 'package:dart_vlc/src/equalizer.dart';
import 'package:dart_vlc/src/playerState/playerState.dart';
import 'package:dart_vlc/src/mediaSource/media.dart';
import 'package:dart_vlc/src/mediaSource/mediaSource.dart';
Expand Down Expand Up @@ -350,6 +351,18 @@ class Player {
);
}

/// Sets [Equalizer] for the [Player].
Future<void> setEqualizer(Equalizer equalizer) async {
await this._isInstanceCreated.future;
await channel.invokeMethod(
'Player.setEqualizer',
{
'id': this.id,
'equalizerId': equalizer.id,
},
);
}

/// Destroys the instance of [Player] & closes all [StreamController]s in it.
Future<void> dispose() async {
await this.currentController.close();
Expand Down
4 changes: 2 additions & 2 deletions windows/dart_vlc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ namespace {
*
*/
else if (method->name == "Equalizer.setBandAmp") {
float id = method->getArgument<float>("id");
int id = method->getArgument<int>("id");
float band = method->getArgument<float>("band");
float amp = method->getArgument<float>("amp");
equalizers->get(id)->setBandAmp(band, amp);
Expand All @@ -1292,7 +1292,7 @@ namespace {
*
*/
else if (method->name == "Equalizer.setPreAmp") {
float id = method->getArgument<float>("id");
int id = method->getArgument<int>("id");
float preAmp = method->getArgument<float>("preAmp");
equalizers->get(id)->setPreAmp(preAmp);
return method->returnNull();
Expand Down

0 comments on commit 5c499a6

Please sign in to comment.