Skip to content

Commit

Permalink
added global and track level volume controls
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Feb 13, 2011
1 parent 1e6f297 commit 7cbb1fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
9 changes: 0 additions & 9 deletions .lock-wscript

This file was deleted.

Binary file removed gmon.out
Binary file not shown.
19 changes: 17 additions & 2 deletions src/main.cc
Expand Up @@ -16,6 +16,7 @@ class irrKlang: ObjectWrap
private:
int m_count;
ISoundEngine* engine;
float m_volume;
public:

static Persistent<FunctionTemplate> s_ct;
Expand All @@ -30,6 +31,7 @@ class irrKlang: ObjectWrap
s_ct->SetClassName(String::NewSymbol("irrKlang"));

NODE_SET_PROTOTYPE_METHOD(s_ct, "play", Play);
NODE_SET_PROTOTYPE_METHOD(s_ct, "setVolume", SetVolume);

target->Set(String::NewSymbol("irrKlang"),
s_ct->GetFunction());
Expand All @@ -38,7 +40,7 @@ class irrKlang: ObjectWrap
irrKlang() :
m_count(0)
{

this->m_volume = 1;
// create the engine
this->engine = createIrrKlangDevice();
if (!this->engine) {
Expand All @@ -59,6 +61,15 @@ class irrKlang: ObjectWrap
return args.This();
}

static Handle<Value> SetVolume(const Arguments& args)
{
HandleScope scope;
irrKlang* hw = ObjectWrap::Unwrap<irrKlang>(args.This());

hw->m_volume = (float)args[0]->NumberValue();
return Undefined();
}

static Handle<Value> Play(const Arguments& args)
{
HandleScope scope;
Expand All @@ -71,7 +82,11 @@ class irrKlang: ObjectWrap
return Undefined();
}

clip->setVolume(1);
if (args.Length() > 1) {
clip->setVolume((float)args[1]->NumberValue());
} else {
clip->setVolume(hw->m_volume);
}

return args.This();
}
Expand Down
17 changes: 13 additions & 4 deletions test/sanity.js
@@ -1,5 +1,14 @@
var irrKlang = require(__dirname + "/../lib/node-irrklang").irrKlang,
player = new irrKlang();
var irrKlang = require(__dirname + "/../lib/irrklang").irrKlang,
player = new irrKlang()
volume = 0,
where = 0;
setInterval(function() {
player.play(__dirname + "/snare.wav");
}, 500)
where++;

player.play(__dirname + "/snare.wav", volume);
volume += 0.001;
if (volume >= 1) {
volume = 0;
}

}, 50)

0 comments on commit 7cbb1fa

Please sign in to comment.