Skip to content

Commit

Permalink
Merge pull request #63 from alnitak/unique-effect
Browse files Browse the repository at this point in the history
finer throws from addGlobalFilter()
  • Loading branch information
alnitak authored Mar 20, 2024
2 parents 81c7e05 + 1eb20a5 commit feb3d48
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 34 deletions.
17 changes: 12 additions & 5 deletions lib/src/bindings_player_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,18 @@ class FlutterSoLoudFfi {

/// Add the filter [filterType].
///
/// [filterType] filter to add
/// Returns [PlayerErrors.noError] if no errors
///
int addGlobalFilter(int filterType) {
return _addGlobalFilter(filterType);
/// [filterType] filter to add.
/// Returns:
/// [PlayerErrors.noError] if no errors
/// [PlayerErrors.filterNotFound] if the [filterType] does not exits
/// [PlayerErrors.filterAlreadyAdded] when trying to add an already
/// added filter
/// [PlayerErrors.maxNumberOfFiltersReached] when the maximum number of
/// filters has been reached (default is 8)
///
PlayerErrors addGlobalFilter(int filterType) {
final e = _addGlobalFilter(filterType);
return PlayerErrors.values[e];
}

late final _addGlobalFilterPtr =
Expand Down
34 changes: 22 additions & 12 deletions lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ enum PlayerErrors {
filterNotFound(12),

/// asking for wave and FFT is not enabled
visualizationNotEnabled(13);
visualizationNotEnabled(13),

/// The maximum number of filters has been reached (default is 8).
maxNumberOfFiltersReached(14),

/// The filter has already been added.
filterAlreadyAdded(15);

const PlayerErrors(this.value);

Expand All @@ -109,34 +115,38 @@ enum PlayerErrors {
case PlayerErrors.noError:
return 'No error';
case PlayerErrors.invalidParameter:
return 'Some parameter is invalid';
return 'Some parameters are invalid!';
case PlayerErrors.fileNotFound:
return 'File not found';
return 'File not found!';
case PlayerErrors.fileLoadFailed:
return 'File found, but could not be loaded';
return 'File found, but could not be loaded!';
case PlayerErrors.fileAlreadyLoaded:
return 'The sound file has already been loaded';
return 'The sound file has already been loaded!';
case PlayerErrors.dllNotFound:
return 'DLL not found, or wrong DLL';
return 'DLL not found, or wrong DLL!';
case PlayerErrors.outOfMemory:
return 'Out of memory';
return 'Out of memory!';
case PlayerErrors.notImplemented:
return 'Feature not implemented';
return 'Feature not implemented!';
case PlayerErrors.unknownError:
return 'Unknown error';
return 'Unknown error!';
case PlayerErrors.nullPointer:
return 'Capture null pointer error. Could happens when passing a non '
'initialized pointer (with calloc()) to retrieve FFT or wave data. '
'Or, setVisualization has not been enabled.';
case PlayerErrors.soundHashNotFound:
return 'The sound with specified hash is not found';
return 'The sound with specified hash is not found!';
case PlayerErrors.backendNotInited:
return 'Player not initialized';
return 'Player not initialized!';
case PlayerErrors.filterNotFound:
return 'Filter not found';
return 'Filter not found!';
case PlayerErrors.visualizationNotEnabled:
return 'Asking for audio data is not enabled! Please use '
'`setVisualizationEnabled(true);` to enable!';
case PlayerErrors.maxNumberOfFiltersReached:
return 'The maximum number of filters has been reached (default is 8)!';
case PlayerErrors.filterAlreadyAdded:
return 'Filter not found!';
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/exceptions/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ abstract class SoLoudCppException extends SoLoudException {
return const SoLoudFilterNotFoundException();
case PlayerErrors.visualizationNotEnabled:
return const SoLoudVisualizationNotEnabledException();
case PlayerErrors.maxNumberOfFiltersReached:
return const SoLoudMaxFilterNumberReachedException();
case PlayerErrors.filterAlreadyAdded:
return const SoLoudFilterAlreadyAddedException();
}
}
}
22 changes: 22 additions & 0 deletions lib/src/exceptions/exceptions_from_cpp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,25 @@ class SoLoudVisualizationNotEnabledException extends SoLoudCppException {
'(on the C++ side). '
'Please use `setVisualizationEnabled(true);` to enable.';
}

/// An exception that is thrown when SoLoud (C++) cannot add another filter.
/// The max number of concurrent filter is set to 8.
class SoLoudMaxFilterNumberReachedException extends SoLoudCppException {
/// Creates a new [SoLoudMaxFilterNumberReachedException].
const SoLoudMaxFilterNumberReachedException([super.message]);

@override
String get description => 'Askind to add another filter, but no more then 8 '
'is allowed (on the C++ side).';
}

/// An exception that is thrown when SoLoud (C++) cannot add a filter
/// that has already been added.
class SoLoudFilterAlreadyAddedException extends SoLoudCppException {
/// Creates a new [SoLoudFilterAlreadyAddedException].
const SoLoudFilterAlreadyAddedException([super.message]);

@override
String get description => 'Askind to add a filter that is already been added. '
'Only one of each type is allowed (on the C++ side).';
}
13 changes: 8 additions & 5 deletions lib/src/soloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1794,12 +1794,15 @@ interface class SoLoud {
/// Add a filter to all sounds.
/// [filterType] filter to add.
///
/// Throws [SoLoudMaxFilterNumberReachedException] when the max number of
/// concurrent filter is reached (default max filter is 8).
/// Throws [SoLoudFilterAlreadyAddedException] when trying to add a filter
/// that has already been added.
void addGlobalFilter(FilterType filterType) {
final ret = SoLoudController().soLoudFFI.addGlobalFilter(filterType.index);
final error = PlayerErrors.values[ret];
if (error != PlayerErrors.noError) {
_log.severe(() => 'addGlobalFilter(): $error');
throw SoLoudCppException.fromPlayerError(error);
final e = SoLoudController().soLoudFFI.addGlobalFilter(filterType.index);
if (e != PlayerErrors.noError) {
_log.severe(() => 'addGlobalFilter(): $e');
throw SoLoudCppException.fromPlayerError(e);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,7 @@ extern "C"
{
if (!player.isInited())
return backendNotInited;
if (!player.mFilters.addGlobalFilter(filterType))
return filterNotFound;
return noError;
return player.mFilters.addGlobalFilter(filterType);
}

/// Remove the filter [filterType].
Expand Down
6 changes: 5 additions & 1 deletion src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ typedef enum PlayerErrors
backendNotInited = 11,
/// Filter not found
filterNotFound = 12,
/// asking for wave and FFT is not enabled
/// Asking for wave and FFT is not enabled
visualizationNotEnabled = 13,
/// The maximum number of filters has been reached (default is 8).
maxNumberOfFiltersReached = 14,
/// The filter has already been added.
filterAlreadyAdded = 15,
} PlayerErrors_t;

/// Possible capture errors
Expand Down
14 changes: 7 additions & 7 deletions src/filters/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ std::vector<std::string> Filters::getFilterParamNames(FilterType filterType)
return ret;
}

bool Filters::addGlobalFilter(FilterType filterType)
PlayerErrors Filters::addGlobalFilter(FilterType filterType)
{
if (filters.size() >= FILTERS_PER_STREAM)
return false;
return maxNumberOfFiltersReached;

// Check if the new filter is already be here.
// Only one kind of filter allowed
// Check if the new filter is already here.
// Only one kind of filter allowed.
if (isFilterActive(filterType) >= 0)
return false;
return filterAlreadyAdded;

const unsigned int filtersSize = static_cast<unsigned int>(filters.size());
switch (filterType)
Expand Down Expand Up @@ -189,9 +189,9 @@ bool Filters::addGlobalFilter(FilterType filterType)
filters.push_back({filterType, static_cast<SoLoud::Filter *>(mFreeverbFilter.get())});
break;
default:
return false;
return filterNotFound;
}
return true;
return noError;
}
/// TODO remove all filters FilterType.none
bool Filters::removeGlobalFilter(FilterType filterType)
Expand Down
4 changes: 3 additions & 1 deletion src/filters/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "soloud_robotizefilter.h"
#include "soloud_freeverbfilter.h"

#include "../enums.h"

#include <vector>
#include <string>
#include <memory>
Expand Down Expand Up @@ -53,7 +55,7 @@ class Filters {
~Filters();

int isFilterActive(FilterType filter);
bool addGlobalFilter(FilterType filterType);
PlayerErrors addGlobalFilter(FilterType filterType);
bool removeGlobalFilter(FilterType filterType);
std::vector<std::string> getFilterParamNames(FilterType filterType);
void setFxParams(FilterType filterType, int attributeId, float value);
Expand Down

0 comments on commit feb3d48

Please sign in to comment.