initialize method

  1. @override
Future<void> initialize({
  1. required double masterVolume,
  2. String? toneJsUrl,
})
override

Implementation

@override
Future<void> initialize({
  required double masterVolume,
  String? toneJsUrl,
}) async {
  _masterVolume = masterVolume.clamp(0.0, 1.0).toDouble();
  await _ensureToneLoaded(toneJsUrl ?? _defaultToneJsUrl);
  final tone = _tone;
  if (tone == null) {
    throw StateError('Tone.js did not register a global Tone object.');
  }

  final startPromise = tone.callMethod<JSPromise<JSAny?>>('start'.toJS);
  await startPromise.toDart;

  if (_masterGain == null) {
    final gainCtor = tone.getProperty<JSFunction>('Gain'.toJS);
    final gain = gainCtor.callAsConstructor<JSObject>(_masterVolume.toJS);
    gain.callMethod<JSAny?>('toDestination'.toJS);
    _masterGain = gain;
  } else {
    _setGainValue(_masterGain!, _masterVolume);
  }
}