BNBEffectManager

Objective-C

@interface BNBEffectManager : NSObject

/**
 * Add callback to receive errors messages from Effect Player.
 * Thread-safe. May be called from any thread
 */
- (void)addErrorListener:(nullable id<BNBErrorListener>)errorListener;

/**
 * Remove callback to receive errors messages from Effect Player.
 * Thread-safe. May be called from any thread
 */
- (void)removeErrorListener:(nullable id<BNBErrorListener>)errorListener;

/**
 * Add callback to receive user-visible messages from effects.
 * You should display them on UI.
 * Thread-safe. May be called from any thread
 */
- (void)addHintListener:(nullable id<BNBHintListener>)hintListener;

/**
 * Remove callback to receive user-visible messages from effects.
 * Thread-safe. May be called from any thread
 */
- (void)removeHintListener:(nullable id<BNBHintListener>)hintListener;

/**
 * Add callback to receive events from effect.
 * Thread-safe. May be called from any thread
 */
- (void)addEffectEventListener:(nullable id<BNBEffectEventListener>)effectEventListener;

/**
 * Remove callback to receive events from effect.
 * Thread-safe. May be called from any thread
 */
- (void)removeEffectEventListener:(nullable id<BNBEffectEventListener>)effectEventListener;

/**
 * Add callback to receive notifications on effect change.
 * Thread-safe. May be called from any thread
 */
- (void)addEffectActivatedListener:(nullable id<BNBEffectActivatedListener>)effectActivatedListener;

/**
 * Remove callback to receive notifications on effect change.
 * Thread-safe. May be called from any thread
 */
- (void)removeEffectActivatedListener:(nullable id<BNBEffectActivatedListener>)effectActivatedListener;

/** Create empty effect. If working directory path is empty string then effect assumed as an in-memory effect. */
- (nullable BNBEffect *)createEffect:(nonnull NSString *)workDir;

/**
 * Set current effect.
 * Thread-safe. May be called from any thread
 */
- (void)setCurrentEffect:(nullable BNBEffect *)effect;

/**
 * Load and activate effect sync.
 * MUST be called from the render thread.
 */
- (nullable BNBEffect *)load:(nonnull NSString *)url;

/**
 * Load effect async, activate in the draw() call when it will be ready.
 * Thread-safe. May be called from any thread.
 */
- (nullable BNBEffect *)loadAsync:(nonnull NSString *)url;

/**
 * Reload current effect config from the string provided. If this reload
 * is possible without effect recreation, this method will return `hot_reload == true`,
 * otherwise `current` effect will be replaced and the method will return
 * `hot_reload == false`.
 *
 * Thread-safe. May be called from any thread. 
 */
- (nullable BNBReloadResult *)reloadConfig:(nonnull NSString *)config;

/**
 * Get effect info. May be called before loading effect
 * "render type" and "recognizer features" fields won't be filled
 * Thread-safe. May be called from any thread
 */
+ (nonnull BNBEffectInfo *)getEffectInfo:(nonnull NSString *)url;

/**
 * Unload effect from cache. if no currently loading effect -
 * works the same way as load(""); launches empty effect loading.
 * MUST be called from the render thread
 */
- (void)unload:(nullable BNBEffect *)effect;

/**
 * Get active effect
 * Thread-safe. May be called from any thread
 */
- (nullable BNBEffect *)current;

/**
 * Update effect loading state
 * @param sync syncronize effect manager, block until effect loaded
 * MUST be called from the render thread
 */
- (void)update:(BOOL)sync;

/**
 * Get current effect size
 * Thread-safe. May be called from any thread
 */
- (nonnull BNBSize *)effectSize;

/**
 * Get current surface size
 * Thread-safe. May be called from any thread
 */
- (nonnull BNBSize *)surfaceSize;

/**
 * Get effect audio volume.
 * Thread-safe. May be called from any thread
 * @return A volume in range `[0, 1]`, where `1` means maximum volume.
 */
- (float)effectVolume;

/**
 * Set effect audio volume.
 * Thread-safe. May be called from any thread
 * @param volume A value in range `[0, 1]`, where `1` means maximum volume.
 */
- (void)setEffectVolume:(float)volume;

/**
 * Changes effect player render size, should be called on render thread.
 * MUST be called from the render thread
 */
- (void)setEffectSize:(int32_t)fxWidth
             fxHeight:(int32_t)fxHeight;

/** set different render surfaces. Can be treated as void* */
- (void)setRenderSurface:(nonnull BNBSurfaceData *)data;

/** disable surface presentation. Needed for offscreen rendering */
- (void)disableSurfacePresentation;

@end

Swift

class BNBEffectManager : NSObject

Undocumented

  • Add callback to receive errors messages from Effect Player. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)addErrorListener:(nullable id<BNBErrorListener>)errorListener;

    Swift

    func add(_ errorListener: BNBErrorListener?)
  • Remove callback to receive errors messages from Effect Player. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)removeErrorListener:(nullable id<BNBErrorListener>)errorListener;

    Swift

    func remove(_ errorListener: BNBErrorListener?)
  • Add callback to receive user-visible messages from effects. You should display them on UI. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)addHintListener:(nullable id<BNBHintListener>)hintListener;

    Swift

    func add(_ hintListener: BNBHintListener?)
  • Remove callback to receive user-visible messages from effects. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)removeHintListener:(nullable id<BNBHintListener>)hintListener;

    Swift

    func remove(_ hintListener: BNBHintListener?)
  • Add callback to receive events from effect. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)addEffectEventListener:
        (nullable id<BNBEffectEventListener>)effectEventListener;

    Swift

    func add(_ effectEventListener: BNBEffectEventListener?)
  • Remove callback to receive events from effect. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)removeEffectEventListener:
        (nullable id<BNBEffectEventListener>)effectEventListener;

    Swift

    func remove(_ effectEventListener: BNBEffectEventListener?)
  • Add callback to receive notifications on effect change. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)addEffectActivatedListener:
        (nullable id<BNBEffectActivatedListener>)effectActivatedListener;

    Swift

    func add(_ effectActivatedListener: BNBEffectActivatedListener?)
  • Remove callback to receive notifications on effect change. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)removeEffectActivatedListener:
        (nullable id<BNBEffectActivatedListener>)effectActivatedListener;

    Swift

    func remove(_ effectActivatedListener: BNBEffectActivatedListener?)
  • Create empty effect. If working directory path is empty string then effect assumed as an in-memory effect.

    Declaration

    Objective-C

    - (nullable BNBEffect *)createEffect:(nonnull NSString *)workDir;

    Swift

    func createEffect(_ workDir: String) -> BNBEffect?
  • Set current effect. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)setCurrentEffect:(nullable BNBEffect *)effect;

    Swift

    func setCurrentEffect(_ effect: BNBEffect?)
  • Load and activate effect sync. MUST be called from the render thread.

    Declaration

    Objective-C

    - (nullable BNBEffect *)load:(nonnull NSString *)url;

    Swift

    func load(_ url: String) -> BNBEffect?
  • Load effect async, activate in the draw() call when it will be ready. Thread-safe. May be called from any thread.

    Declaration

    Objective-C

    - (nullable BNBEffect *)loadAsync:(nonnull NSString *)url;

    Swift

    func loadAsync(_ url: String) -> BNBEffect?
  • Reload current effect config from the string provided. If this reload is possible without effect recreation, this method will return hot_reload == true, otherwise current effect will be replaced and the method will return hot_reload == false.

    Thread-safe. May be called from any thread.

    Declaration

    Objective-C

    - (nullable BNBReloadResult *)reloadConfig:(nonnull NSString *)config;

    Swift

    func reloadConfig(_ config: String) -> BNBReloadResult?
  • Get effect info. May be called before loading effect “render type” and “recognizer features” fields won’t be filled Thread-safe. May be called from any thread

    Declaration

    Objective-C

    + (nonnull BNBEffectInfo *)getEffectInfo:(nonnull NSString *)url;

    Swift

    class func getEffectInfo(_ url: String) -> BNBEffectInfo
  • Unload effect from cache. if no currently loading effect - works the same way as load(“”); launches empty effect loading. MUST be called from the render thread

    Declaration

    Objective-C

    - (void)unload:(nullable BNBEffect *)effect;

    Swift

    func unload(_ effect: BNBEffect?)
  • Get active effect Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (nullable BNBEffect *)current;

    Swift

    func current() -> BNBEffect?
  • Update effect loading state

    Declaration

    Objective-C

    - (void)update:(BOOL)sync;

    Swift

    func update(_ sync: Bool)

    Parameters

    sync

    syncronize effect manager, block until effect loaded MUST be called from the render thread

  • Get current effect size Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (nonnull BNBSize *)effectSize;

    Swift

    func effectSize() -> BNBSize
  • Get current surface size Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (nonnull BNBSize *)surfaceSize;

    Swift

    func surfaceSize() -> BNBSize
  • Get effect audio volume. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (float)effectVolume;

    Swift

    func effectVolume() -> Float

    Return Value

    A volume in range [0, 1], where 1 means maximum volume.

  • Set effect audio volume. Thread-safe. May be called from any thread

    Declaration

    Objective-C

    - (void)setEffectVolume:(float)volume;

    Swift

    func setEffectVolume(_ volume: Float)

    Parameters

    volume

    A value in range [0, 1], where 1 means maximum volume.

  • Changes effect player render size, should be called on render thread. MUST be called from the render thread

    Declaration

    Objective-C

    - (void)setEffectSize:(int32_t)fxWidth fxHeight:(int32_t)fxHeight;

    Swift

    func setEffectSize(_ fxWidth: Int32, fxHeight: Int32)
  • set different render surfaces. Can be treated as void*

    Declaration

    Objective-C

    - (void)setRenderSurface:(nonnull BNBSurfaceData *)data;

    Swift

    func setRenderSurface(_ data: BNBSurfaceData)
  • disable surface presentation. Needed for offscreen rendering

    Declaration

    Objective-C

    - (void)disableSurfacePresentation;

    Swift

    func disableSurfacePresentation()