Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit cac12bcd1d53ad402165d714fdbfac0791a21683 @Maciek416 committed May 2, 2010
Showing with 10,207 additions and 0 deletions.
  1. 0 README
  2. +85 −0 app.js
  3. +82 −0 public/javascript/nodesynth.js
  4. +94 −0 public/javascript/ui.js
  5. +519 −0 public/synth/dsp.js
  6. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_diagonals-small_40_db4865_40x40.png
  7. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_diagonals-small_50_93c3cd_40x40.png
  8. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_diagonals-small_50_ff3853_40x40.png
  9. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_diagonals-small_75_ccd232_40x40.png
  10. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_dots-medium_80_ffff38_4x4.png
  11. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_dots-small_35_35414f_2x2.png
  12. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_flat_75_ba9217_40x100.png
  13. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_flat_75_ffffff_40x100.png
  14. BIN public/synth/examples/css/hot-sneaks/images/ui-bg_white-lines_85_f7f7ba_40x100.png
  15. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_454545_256x240.png
  16. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_88a206_256x240.png
  17. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_c02669_256x240.png
  18. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_e1e463_256x240.png
  19. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_ffeb33_256x240.png
  20. BIN public/synth/examples/css/hot-sneaks/images/ui-icons_ffffff_256x240.png
  21. +480 −0 public/synth/examples/css/hot-sneaks/jquery-ui-1.8.custom.css
  22. BIN public/synth/examples/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
  23. BIN public/synth/examples/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
  24. BIN public/synth/examples/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
  25. BIN public/synth/examples/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
  26. BIN public/synth/examples/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
  27. BIN public/synth/examples/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
  28. BIN public/synth/examples/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
  29. BIN public/synth/examples/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  30. BIN public/synth/examples/css/smoothness/images/ui-icons_222222_256x240.png
  31. BIN public/synth/examples/css/smoothness/images/ui-icons_2e83ff_256x240.png
  32. BIN public/synth/examples/css/smoothness/images/ui-icons_454545_256x240.png
  33. BIN public/synth/examples/css/smoothness/images/ui-icons_888888_256x240.png
  34. BIN public/synth/examples/css/smoothness/images/ui-icons_cd0a0a_256x240.png
  35. +406 −0 public/synth/examples/css/smoothness/jquery-ui-1.7.2.custom.css
  36. +29 −0 public/synth/examples/js/init.js
  37. +154 −0 public/synth/examples/js/jquery-1.4.2.min.js
  38. +374 −0 public/synth/examples/js/jquery-ui-1.8.custom.min.js
  39. +7,390 −0 public/synth/examples/js/processing.js
  40. +580 −0 public/synth/examples/synthesizer2.html
  41. +14 −0 views/index.html.haml
0 README
No changes.
85 app.js
@@ -0,0 +1,85 @@
+var sys = require('sys');
+var kiwi = require('kiwi');
+kiwi.require('express');
+require('express/plugins')
+
+configure(function(){
+ use(MethodOverride);
+ use(ContentLength);
+ use(Logger);
+ use(Static);
+ set('root', __dirname);
+})
+
+var requestcounter = 0;
+
+// Generate pattern data
+var data = {
+ pattern:[]
+};
+
+// var pianorollheight = 24;
+// var patternwidth = 32;
+// for(var i=0;i<pianorollheight;i++){
+// data.pattern[i] = [];
+// for(var j=0;j<patternwidth;j++){
+// //data.pattern[i][j] = (Math.random()>0.5)?true:false;
+// // initial pattern is always empty
+// data.pattern[i][j] = false;
+// }
+// }
+
+data.pattern = new Array(32);
+for ( var i = 0; i < data.pattern.length; i++ ) {
+ data.pattern[i] = new Array(24);
+ for( var j = 0; j < data.pattern[i].length; j++ ) {
+ data.pattern[i][j] = false;
+ }
+}
+
+
+// UI
+get('/', function(){
+ requestcounter++;
+ this.render('index.html.haml', {
+ layout: false,
+ locals: {
+ data: data.pattern,
+ requestcounter: requestcounter,
+ title: 'NodeSynth'
+ }
+ })
+});
+
+// Fetch a key
+get('/get/:k', function(){
+ var result = JSON.stringify(data[this.param('k')]);
+ sys.puts("Returning:",result);
+ return result;
+});
+
+// Set the value of a key k
+post('/set/:k', function(){
+ var value = JSON.parse(this.body);
+ var key = this.param('k');
+ sys.puts("setting value ["+key+"] to ["+value+"]");
+ data[key] = value;
+ // TODO: return some kind of intelligent cache id
+ return JSON.stringify({});
+});
+
+// Set value of k at x at y, where x and y are integers
+post('/set/:k/:sub1/:sub2', function(){
+ var value = JSON.parse(this.body);
+ var key = this.param('k');
+ var sub1 = parseInt(this.param('sub1'));
+ var sub2 = parseInt(this.param('sub2'));
+ sys.puts("setting value data["+key+"]["+sub1+"]["+sub2+"] to ["+value+"]");
+ data[key][sub1][sub2] = value;
+ // TODO: return some kind of intelligent cache id
+ return JSON.stringify({});
+});
+
+run();
+
+sys.puts("NodeSynth is running");
@@ -0,0 +1,82 @@
+$(function(){
+
+ var SharedKeyValueStore = function(){
+ return {
+ attr: function(key, value, callback){
+ // usage:
+ //
+ // set:
+ // kvstore.attr("price",9.99,function(){...});
+ //
+ // set:
+ // kvstore.attr("cells",5,10,182,function(){...});
+ //
+ // get:
+ // kvstore.attr("price",function(value){...});
+ //
+ if(arguments.length==5) {
+ $.ajax({
+ type: 'POST',
+ url: "/set/" + key + "/" + arguments[1] + "/" + arguments[2],
+ data: JSON.stringify(arguments[3]),
+ success: arguments[4],
+ dataType: 'json'
+ });
+ } else if (arguments.length==3) {
+ //
+ // TODO: intelligent caching
+ //
+ $.ajax({
+ type: 'POST',
+ url: "/set/" + key,
+ data: JSON.stringify(value),
+ success: callback,
+ dataType: 'json'
+ });
+ } else if(arguments.length==2) {
+ // get
+ $.ajax({
+ type: 'GET',
+ url: "/get/" + key,
+ success: arguments[1],
+ dataType: 'json'
+ });
+ } else {
+ throw "Wrong number of arguments to attr() (must be 2 or 3 or 5)";
+ }
+ }
+ };
+ };
+
+
+ var NodeSynth = function(){
+ // initialize
+ var store = SharedKeyValueStore();
+
+ var self = {
+ refreshPattern: function(){
+ store.attr("pattern", function(updatedpattern){
+ // TODO: Make this cleaner and less global-abusive
+ sequencer = updatedpattern;
+ });
+ },
+ setNote: function(row, col, value){
+ // set
+ store.attr("pattern", row, col, value, function(){
+ self.refreshPattern();
+ });
+ },
+ initSynchronizer: function(){
+ setInterval(function(){
+ self.refreshPattern();
+ },1000);
+ }
+ };
+
+ return self;
+ };
+
+ window.synth = NodeSynth();
+ window.synth.initSynchronizer();
+
+});
@@ -0,0 +1,94 @@
+$(function() {
+
+ var SharedKeyValueStore = function(){
+ return {
+ attr: function(key, value, callback){
+ // usage:
+ //
+ // set:
+ // kvstore.attr("price",9.99,function(){...});
+ //
+ // set:
+ // kvstore.attr("cells",5,10,182,function(){...});
+ //
+ // get:
+ // kvstore.attr("price",function(value){...});
+ //
+ if(arguments.length==5) {
+ $.ajax({
+ type: 'POST',
+ url: "/set/" + key + "/" + arguments[1] + "/" + arguments[2],
+ data: JSON.stringify(arguments[3]),
+ success: arguments[4],
+ dataType: 'json'
+ });
+ } else if (arguments.length==3) {
+ //
+ // TODO: intelligent caching
+ //
+ $.ajax({
+ type: 'POST',
+ url: "/set/" + key,
+ data: JSON.stringify(value),
+ success: callback,
+ dataType: 'json'
+ });
+ } else if(arguments.length==2) {
+ // get
+ $.ajax({
+ type: 'GET',
+ url: "/get/" + key,
+ success: arguments[1],
+ dataType: 'json'
+ });
+ } else {
+ throw "Wrong number of arguments to attr() (must be 2 or 3 or 5)";
+ }
+ }
+ };
+ };
+
+ var store = SharedKeyValueStore();
+
+ //
+ // Redraw the entire pattern
+ //
+ var updateCells = function(data){
+ for(var i=0;i<data.length;i++){
+ for(var j=0;j<data[i].length;j++){
+ // TODO: don't refetch this selector constantly, cache it
+ ($("#datacell_" + i + "_" + j)
+ .css({
+ backgroundColor:(data[i][j]==1?'rgb(200,200,210)':'rgb(32,32,32)')
+ })
+ .removeClass("cell_on")
+ .removeClass("cell_off")
+ .addClass(data[i][j]==1?"cell_on":"cell_off")
+ );
+ }
+ }
+ };
+
+ //
+ // Fetch a pattern update periodically
+ //
+ setInterval(function(){
+ store.attr("pattern",function(pattern){
+ updateCells(pattern);
+ });
+ },1000);
+
+ //
+ // Update cells manually with a click on the pattern itself
+ //
+ $(".datacell").click(function(){
+ var rowindex = $(this).attr("id").split("_")[1];
+ var colindex = $(this).attr("id").split("_")[2];
+ var value = $(this).hasClass("cell_on")?0:1;
+ store.attr("pattern", rowindex, colindex, value, function(pattern){
+ store.attr("pattern", function(pattern){
+ updateCells(pattern);
+ });
+ });
+ })
+});
Oops, something went wrong.

0 comments on commit cac12bc

Please sign in to comment.