-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/android/connect-method' into feat/android/wavetype
- Loading branch information
Showing
11 changed files
with
225 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
#include "AudioContext.h" | ||
|
||
namespace audiocontext { | ||
|
||
using namespace facebook::jni; | ||
|
||
AudioContext::AudioContext(jni::alias_ref<AudioContext::jhybridobject> &jThis, | ||
jlong jsContext): javaObject_(make_global(jThis)), jsContext_(jsContext) { | ||
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext); | ||
auto hostObject = std::make_shared<AudioContextHostObject>(this); | ||
auto object = jsi::Object::createFromHostObject(*runtime, hostObject); | ||
runtime->global().setProperty(*runtime, "__AudioContextProxy", std::move(object)); | ||
} | ||
|
||
jsi::Object AudioContext::createOscillator() { | ||
static const auto method = javaClassLocal()->getMethod<OscillatorNode()>("createOscillator"); | ||
auto oscillator = method(javaObject_.get()); | ||
auto oscillatorCppInstance = oscillator->cthis(); | ||
|
||
return oscillatorCppInstance->createOscillatorNodeHostObject(); | ||
} | ||
|
||
jsi::Object AudioContext::getDestination() { | ||
static const auto method = javaClassLocal()->getMethod<AudioDestinationNode()>("getDestination"); | ||
auto destination = method(javaObject_.get()); | ||
auto destinationCppInstance = destination->cthis(); | ||
|
||
return destinationCppInstance->createAudioDestinationHostObject(); | ||
} | ||
namespace audiocontext | ||
{ | ||
|
||
using namespace facebook::jni; | ||
|
||
AudioContext::AudioContext(jni::alias_ref<AudioContext::jhybridobject> &jThis, | ||
jlong jsContext) : javaObject_(make_global(jThis)), jsContext_(jsContext) | ||
{ | ||
auto runtime = reinterpret_cast<jsi::Runtime *>(jsContext); | ||
auto hostObject = std::make_shared<AudioContextHostObject>(this); | ||
auto object = jsi::Object::createFromHostObject(*runtime, hostObject); | ||
runtime->global().setProperty(*runtime, "__AudioContextProxy", std::move(object)); | ||
} | ||
|
||
jsi::Object AudioContext::createOscillator() | ||
{ | ||
static const auto method = javaClassLocal()->getMethod<OscillatorNode()>("createOscillator"); | ||
auto oscillator = method(javaObject_.get()); | ||
auto oscillatorCppInstance = oscillator->cthis(); | ||
|
||
return oscillatorCppInstance->createOscillatorNodeHostObject(); | ||
} | ||
|
||
jsi::Object AudioContext::getDestination() | ||
{ | ||
static const auto method = javaClassLocal()->getMethod<AudioDestinationNode()>("getDestination"); | ||
auto destination = method(javaObject_.get()); | ||
auto destinationCppInstance = destination->cthis(); | ||
|
||
return destinationCppInstance->createAudioDestinationHostObject(); | ||
} | ||
|
||
} // namespace audiocontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,137 @@ | ||
#include "OscillatorNodeHostObject.h" | ||
#include <android/log.h> | ||
|
||
namespace audiocontext { | ||
using namespace facebook; | ||
|
||
std::vector<jsi::PropNameID> OscillatorNodeHostObject::getPropertyNames(jsi::Runtime& runtime) { | ||
std::vector<jsi::PropNameID> propertyNames; | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "start")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "stop")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "frequency")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "detune")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "type")); | ||
return propertyNames; | ||
namespace audiocontext | ||
{ | ||
using namespace facebook; | ||
|
||
std::vector<jsi::PropNameID> OscillatorNodeHostObject::getPropertyNames(jsi::Runtime &runtime) | ||
{ | ||
std::vector<jsi::PropNameID> propertyNames; | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "start")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "stop")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "frequency")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "detune")); | ||
propertyNames.push_back(jsi::PropNameID::forAscii(runtime, "type")); | ||
return propertyNames; | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::get(jsi::Runtime &runtime, const jsi::PropNameID &propNameId) | ||
{ | ||
auto propName = propNameId.utf8(runtime); | ||
|
||
if (propName == "start") | ||
{ | ||
return start(runtime, propNameId); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) { | ||
auto propName = propNameId.utf8(runtime); | ||
|
||
if (propName == "start") { | ||
return start(runtime, propNameId); | ||
} | ||
|
||
if (propName == "stop") { | ||
return stop(runtime, propNameId); | ||
} | ||
|
||
if (propName == "frequency") { | ||
return frequency(runtime, propNameId); | ||
} | ||
|
||
if (propName == "detune") { | ||
return detune(runtime, propNameId); | ||
} | ||
|
||
if (propName == "type") { | ||
return waveType(runtime, propNameId); | ||
} | ||
if (propName == "stop") | ||
{ | ||
return stop(runtime, propNameId); | ||
} | ||
|
||
if (propName == "connect") { | ||
return connect(runtime, propNameId); | ||
} | ||
if (propName == "frequency") | ||
{ | ||
return frequency(runtime, propNameId); | ||
} | ||
|
||
throw std::runtime_error("Prop not yet implemented!"); | ||
if (propName == "detune") | ||
{ | ||
return detune(runtime, propNameId); | ||
} | ||
|
||
void OscillatorNodeHostObject::set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) { | ||
auto propName = propNameId.utf8(runtime); | ||
if (propName == "type") | ||
{ | ||
return waveType(runtime, propNameId); | ||
} | ||
|
||
if (propName == "frequency") { | ||
auto frequency = value.asNumber(); | ||
oscillator_->setFrequency(frequency); | ||
return; | ||
} | ||
if (propName == "connect") | ||
{ | ||
return connect(runtime, propNameId); | ||
} | ||
|
||
if (propName == "detune") { | ||
auto detune = value.asNumber(); | ||
oscillator_->setDetune(detune); | ||
return; | ||
} | ||
throw std::runtime_error("Prop not yet implemented!"); | ||
} | ||
|
||
if (propName == "type") { | ||
auto waveType = value.asString(runtime).utf8(runtime); | ||
oscillator_->setWaveType(waveType); | ||
return; | ||
} | ||
void OscillatorNodeHostObject::set(jsi::Runtime &runtime, const jsi::PropNameID &propNameId, const jsi::Value &value) | ||
{ | ||
auto propName = propNameId.utf8(runtime); | ||
|
||
throw std::runtime_error("Not yet implemented!"); | ||
if (propName == "frequency") | ||
{ | ||
auto frequency = value.asNumber(); | ||
oscillator_->setFrequency(frequency); | ||
return; | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::start(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
oscillator_->start(); | ||
return jsi::Value::undefined(); | ||
}); | ||
if (propName == "detune") | ||
{ | ||
auto detune = value.asNumber(); | ||
oscillator_->setDetune(detune); | ||
return; | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::stop(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
oscillator_->stop(); | ||
return jsi::Value::undefined(); | ||
}); | ||
if (propName == "type") | ||
{ | ||
auto waveType = value.asString(runtime).utf8(runtime); | ||
oscillator_->setWaveType(waveType); | ||
return; | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::frequency(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
auto frequency = oscillator_->getFrequency(); | ||
return jsi::Value(frequency); | ||
}); | ||
} | ||
throw std::runtime_error("Not yet implemented!"); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::detune(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
jsi::Value OscillatorNodeHostObject::start(jsi::Runtime &runtime, const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
oscillator_->start(); | ||
return jsi::Value::undefined(); }); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::stop(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
oscillator_->stop(); | ||
return jsi::Value::undefined(); }); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::frequency(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto frequency = oscillator_->getFrequency(); | ||
return jsi::Value(frequency); }); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::detune(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto detune = oscillator_->getDetune(); | ||
return jsi::Value(detune); | ||
}); | ||
} | ||
|
||
jsi::Value | ||
OscillatorNodeHostObject::waveType(jsi::Runtime &runtime, const jsi::PropNameID &propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
return jsi::Value(detune); }); | ||
} | ||
|
||
jsi::Value | ||
OscillatorNodeHostObject::waveType(jsi::Runtime &runtime, const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 0, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto waveType = oscillator_->getWaveType(); | ||
return jsi::String::createFromUtf8(rt, waveType); | ||
}); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::connect(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) { | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 1, [this](jsi::Runtime& rt, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { | ||
return jsi::String::createFromUtf8(rt, waveType); }); | ||
} | ||
|
||
jsi::Value OscillatorNodeHostObject::connect(jsi::Runtime &runtime, | ||
const jsi::PropNameID &propNameId) | ||
{ | ||
return jsi::Function::createFromHostFunction(runtime, propNameId, 1, [this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value | ||
{ | ||
auto destination = args[0].asObject(rt).asHostObject<AudioDestinationNodeHostObject>(rt); | ||
oscillator_->connect(*destination->destination_); | ||
return jsi::Value::undefined(); | ||
}); | ||
} | ||
return jsi::Value::undefined(); }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.