fixes for new injector API in other scripts

This commit is contained in:
Stephen Birarda 2015-02-11 16:20:48 -08:00
parent d8646f6ea0
commit f9174366dc
6 changed files with 12 additions and 10 deletions

View file

@ -117,7 +117,7 @@
print("stopSound()"); print("stopSound()");
} }
if (this.injector) { if (this.injector) {
Audio.stopInjector(this.injector); this.injector.stop();
this.injector = null; this.injector = null;
} }
} }

View file

@ -75,14 +75,14 @@ function maybePlaySound(deltaTime) {
//print("number playing = " + numPlaying); //print("number playing = " + numPlaying);
} }
for (var i = 0; i < playing.length; i++) { for (var i = 0; i < playing.length; i++) {
if (!Audio.isInjectorPlaying(playing[i].audioId)) { if (!playing[i].audioId.isPlaying) {
Entities.deleteEntity(playing[i].entityId); Entities.deleteEntity(playing[i].entityId);
if (useLights) { if (useLights) {
Entities.deleteEntity(playing[i].lightId); Entities.deleteEntity(playing[i].lightId);
} }
playing.splice(i, 1); playing.splice(i, 1);
} else { } else {
var loudness = Audio.getLoudness(playing[i].audioId); var loudness = playing[i].audioId.loudness;
var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue }; var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue };
if (loudness > 0.05) { if (loudness > 0.05) {
newColor.red *= (1.0 - loudness); newColor.red *= (1.0 - loudness);

View file

@ -21,7 +21,7 @@ var offset = Vec3.normalize(Quat.getFront(MyAvatar.orientation));
var position = Vec3.sum(MyAvatar.position, offset); var position = Vec3.sum(MyAvatar.position, offset);
function update(deltaTime) { function update(deltaTime) {
if (!Audio.isInjectorPlaying(soundPlaying)) { if (!soundPlaying.isPlaying) {
soundPlaying = Audio.playSound(sound, { soundPlaying = Audio.playSound(sound, {
position: position, position: position,
loop: true loop: true
@ -31,7 +31,7 @@ function update(deltaTime) {
} }
function scriptEnding() { function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) { if (soundPlaying.isPlaying) {
Audio.stopInjector(soundPlaying); Audio.stopInjector(soundPlaying);
print("Stopped sound loop"); print("Stopped sound loop");
} }

View file

@ -32,14 +32,14 @@ var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volu
function update(deltaTime) { function update(deltaTime) {
time += deltaTime; time += deltaTime;
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS }; currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound); trailingLoudness = 0.9 * trailingLoudness + 0.1 * sound.loudness;
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } ); Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
Audio.setInjectorOptions(sound, { position: currentPosition }); sound.setOptions({ position: currentPosition });
} }
Script.scriptEnding.connect(function() { Script.scriptEnding.connect(function() {
Entities.deleteEntity(objectId); Entities.deleteEntity(objectId);
Audio.stopInjector(sound); sound.stop();
}); });
Script.update.connect(update); Script.update.connect(update);

View file

@ -45,8 +45,8 @@ function maybePlaySound(deltaTime) {
} }
function scriptEnding() { function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) { if (soundPlaying.isPlaying) {
Audio.stopInjector(soundPlaying); soundPlaying.stop();
Entities.deleteEntity(ball); Entities.deleteEntity(ball);
print("Stopped sound."); print("Stopped sound.");
} }

View file

@ -27,6 +27,8 @@ class AbstractAudioInterface;
class AudioInjector : public QObject { class AudioInjector : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool isPlaying READ isPlaying)
Q_PROPERTY(float loudness READ getLoudness)
public: public:
AudioInjector(QObject* parent); AudioInjector(QObject* parent);
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions); AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);