Permalink
Browse files

effect chains, clean up build hierarchy

  • Loading branch information...
1 parent 665643a commit a375d7a9cd022707a0c88008b3979d81ec22962c @substack committed Jul 7, 2012
Showing with 89 additions and 16 deletions.
  1. 0 sox.cc → _old.cc
  2. +1 −6 binding.gyp
  3. +66 −0 src/chain.hpp
  4. +0 −10 src/{format.cc → format.hpp}
  5. +22 −0 src/sox.cc
View
File renamed without changes.
View
@@ -2,12 +2,7 @@
"targets": [
{
"target_name": "sox",
- "sources": [ "sox.cc" ],
- "libraries" : [ "-lsox" ]
- },
- {
- "target_name": "format",
- "sources": [ "src/format.cc" ],
+ "sources": [ "src/sox.cc" ],
"libraries" : [ "-lsox" ],
"include_dirs" : [ "src" ]
}
View
@@ -0,0 +1,66 @@
+#ifndef NODE_SOX_CHAIN
+#define NODE_SOX_CHAIN
+
+#include <node.h>
+#include <v8.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+#include <sox.h>
+#include "format.hpp"
+
+class Chain : public ObjectWrap {
+public:
+ static Persistent<FunctionTemplate> constructor_template;
+ sox_effects_chain_t *chain;
+
+ static void Initialize (Handle<Object> target) {
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+ constructor_template = Persistent<FunctionTemplate>::New(t);
+ constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor_template->SetClassName(String::NewSymbol("Chain"));
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "addEffect", AddEffect);
+
+ target->Set(
+ String::NewSymbol("Chain"),
+ constructor_template->GetFunction()
+ );
+ }
+
+ static Handle<Value> New(const Arguments &args) {
+ HandleScope scope;
+
+ Format *in, *out;
+ in = ObjectWrap::Unwrap<Format>(Handle<Object>::Cast(args[0]));
+ out = ObjectWrap::Unwrap<Format>(Handle<Object>::Cast(args[1]));
+
+ Chain *c = new Chain();
+ c->chain = sox_create_effects_chain(
+ &(in->format->encoding), &(out->format->encoding)
+ );
+
+ c->Wrap(args.This());
+ return args.This();
+ }
+
+ static Handle<Value> AddEffect(const Arguments &args) {
+ HandleScope scope;
+ Chain *c = ObjectWrap::Unwrap<Chain>(args.This());
+ Effect *e = ObjectWrap::Unwrap<Effect>(Handle<Object>::Cast(args[0]));
+
+ Format *in, *out;
+ in = ObjectWrap::Unwrap<Format>(Handle<Object>::Cast(args[1]));
+ out = ObjectWrap::Unwrap<Format>(Handle<Object>::Cast(args[2]));
+
+ assert(sox_add_effect(
+ c->chain, e->effect, &in->format->signal, &out->format->signal
+ ) == SOX_SUCCESS);
+ return args.This();
+ }
+};
+
+Persistent<FunctionTemplate> Chain::constructor_template;
+
+#endif
@@ -10,7 +10,6 @@ using namespace node;
#include <sox.h>
#include "signal.hpp"
-#include "effect.hpp"
class Format : public ObjectWrap {
public:
@@ -113,13 +112,4 @@ class Format : public ObjectWrap {
Persistent<FunctionTemplate> Format::constructor_template;
-void init(Handle<Object> target) {
- HandleScope scope;
- Format::Initialize(target);
- Signal::Initialize(target);
- Effect::Initialize(target);
-}
-
-NODE_MODULE(format, init);
-
#endif
View
@@ -0,0 +1,22 @@
+#include <node.h>
+#include <v8.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+#include <sox.h>
+#include "format.hpp"
+#include "signal.hpp"
+#include "effect.hpp"
+#include "chain.hpp"
+
+void init(Handle<Object> target) {
+ HandleScope scope;
+ Format::Initialize(target);
+ Signal::Initialize(target);
+ Effect::Initialize(target);
+ Chain::Initialize(target);
+}
+
+NODE_MODULE(sox, init);

0 comments on commit a375d7a

Please sign in to comment.