.open / .load opt meta , axe mob , music -> wave

This commit is contained in:
Mark Nadal 2019-12-30 11:57:28 -08:00
parent 9db8adea2a
commit 88a5c8fea0
6 changed files with 109 additions and 31 deletions

4
axe.js
View File

@ -287,7 +287,9 @@
if(peer.url){ return } // I am assuming that if we are wanting to make an outbound connection to them, that we don't ever want to drop them unless our actual config settings change.
var count = Object.keys(opt.peers).length;
if(opt.mob >= count){ return } // TODO: Make dynamic based on RAM/CPU also. Or possibly even weird stuff like opt.mob / axe.up length?
mesh.say({dam: 'mob', mob: count, peers: Object.keys(axe.up)}, peer);
var peers = Object.keys(axe.up);
if(!peers.length){ return }
mesh.say({dam: 'mob', mob: count, peers: peers}, peer);
//setTimeout(function(){ mesh.bye(peer) }, 9); // something with better perf? // UNCOMMENT WHEN WE ACTIVATE THIS FEATURE
});
at.on('bye', function(peer){

View File

@ -33,7 +33,7 @@
<script src="../../gun/lib/normalize.js"></script>
<script async src="../../gun/lib/fun.js"></script>
<script async src="../../gun/lib/music.js"></script>
<script async src="../../gun/lib/wave.js"></script>
<!-- script async src="https://edide.io/music.lib"></script -->
<script>
@ -214,7 +214,7 @@ meta.edit({
song.play = true;
music.stop();
setTimeout(function(){
song.now = music.play($('#page').text());
song.now = wave($('#page').text()).play();
},250);
}
});
@ -223,7 +223,7 @@ meta.edit({
on: function(eve){
$(document).on('mousemove.tmp', function(eve){
var x = eve.pageX;
song.now.blur(x);
song.now.loud(x/$('body').innerWidth());
});
},
up: function(){

View File

@ -5,6 +5,7 @@ Gun.chain.open = function(cb, opt, at){
opt.doc = opt.doc || {};
opt.ids = opt.ids || {};
opt.any = opt.any || cb;
opt.meta = opt.meta || false;
opt.ev = opt.ev || {off: function(){
Gun.obj.map(opt.ev.s, function(e){
if(e){ e.off() }
@ -12,7 +13,9 @@ Gun.chain.open = function(cb, opt, at){
opt.ev.s = {};
}, s:{}}
return this.on(function(data, key, ctx, ev){
delete ((data = Gun.obj.copy(data))||{})._;
if(opt.meta !== true){
delete ((data = Gun.obj.copy(data))||{})._;
}
clearTimeout(opt.to);
opt.to = setTimeout(function(){
if(!opt.any){ return }

View File

@ -2,7 +2,7 @@
var Gun = require('../gun'), u;
Gun.serve = require('./serve');
//process.env.GUN_ENV = process.env.GUN_ENV || 'debug';
console.LOG = true; // only temporarily, REVERT THIS IN FUTURE!
//console.LOG = true; // only temporarily, REVERT THIS IN FUTURE!
Gun.on('opt', function(root){
if(u === root.opt.super){
root.opt.super = true;

View File

@ -20,7 +20,7 @@ return this;
}).call({}, edide);
"use strict";edide.var = (function _var (edide) {
var currentReact, debugging, dependees, dependsOn, depsRequired, inInitCall, infinityCheck, initSetter, newVar, parent, setLinks, setters, updateVar, values;
values = new Map; // TODO //edide.keep ?
values = new Map; // //edide.keep ?
setters = new Map; // varName => setter:func
dependees = new Map; // varName => deps:
setLinks = new Map; // for reactiveGraph, show setters inside reactive/setter:s
@ -190,7 +190,13 @@ return (initialVars = {}) => {
}
return edide.var(func);
};
return {revar, unvar, react}; // , dom
return {
react,
revar,
unvar,
un: unvar,
re: revar // , dom
};
};
return this;
}).call({}, edide);
@ -416,7 +422,7 @@ this.fromKeyCode = (key) => {
};
return this;
}).call({}, edide);
"use strict";edide.new = (function (edide) {
"use strict";edide.clone = (function _clone (edide) {
return function(...objects) {
if (Array.isArray(objects[0])) {
return Object.assign([], ...objects);
@ -443,7 +449,7 @@ this.hasVar = (varName) => {
this.activateVar = (name, value) => {
var configs;
if (value != null) {
configs = edide.new(mutatingVars[name]);
configs = edide.clone(mutatingVars[name]);
if (edide.strParsesToNumber(value)) {
value = parseFloat(value);
}
@ -601,7 +607,7 @@ return this;
}).call({}, edide);
"use strict";edide.mmPipe = (function _mmPipe (edide) {Object.defineProperty(this, 'module_name', {value:'mmPipe'});
var dist, lowpass, react, revar, reverber, unvar;
({revar, unvar, react} = edide.mmState);
({revar, unvar, react} = edide.mmState.init());
dist = lowpass = reverber = null;
this.initPipe = () => {
lowpass = new Tone.Filter(unvar.lowpass, 'lowpass', -12);
@ -932,12 +938,35 @@ return sleep;
return this;
}).call({}, edide);
"use strict";edide.mmInstrument = (function _mmInstrument (edide) {Object.defineProperty(this, 'module_name', {value:'mmInstrument'});
var cloneOrCreateInstrument, getInstruments, instruments, play, react, revar, unvar;
({unvar, revar, react} = edide.mmState);
revar.beatDelay = () => {
return (1 / revar.bpm) * 60 * 1000;
};
var cloneOrCreateInstrument, getInstruments, instruments, play, react, revar, unvar, updateVolAndTune;
instruments = {}; // name: [instrument instances...]
({unvar, revar, react} = edide.mmState);
react('delay from bmp', () => {
return revar.beatDelay = (1 / revar.bpm) * 60 * 1000;
});
react(() => {});
updateVolAndTune = (inst) => {
var detune, volume;
({volume, detune} = unvar);
if ((detune != null) && (inst.detune != null)) {
inst.set("detune", detune);
}
if ((volume != null) && (inst.volume != null)) {
return inst.set("volume", volume);
}
};
react(() => {
var inst, insts, j, len, name;
revar.volume;
revar.detune;
for (name in instruments) {
insts = instruments[name];
for (j = 0, len = insts.length; j < len; j++) {
inst = insts[j];
updateVolAndTune(inst);
}
}
});
react('create first instrument', () => {
var name, ref;
if (!(name = (ref = revar.instrumentConf) != null ? ref.name : void 0)) { // e.g. illegal instrument name
@ -950,13 +979,9 @@ react('create first instrument', () => {
});
cloneOrCreateInstrument = (name) => {
var inst;
if (instruments[name][0].soundFontInstrument) {
inst = edide.cloneSibling(instruments[name][0]);
inst.isPlaying = false;
return inst;
} else {
return edide.instrumentConfigs.createNew();
}
inst = instruments[name][0].soundFontInstrument ? (inst = edide.cloneSibling(instruments[name][0]), inst.isPlaying = false, inst) : edide.instrumentConfigs.createNew();
updateVolAndTune(inst);
return inst;
};
getInstruments = (n) => {
var all, free, name;
@ -1164,12 +1189,54 @@ this.play = (str) => {
this.stop = () => revar.playing = false
edide.instrumentConfigs.initInstrument()
var initialSettings = {
"instrument": "piano"
"instrument": "synth-simple", //"piano"
}
react(() => {
if(!revar.pipeReady) return
this.play(JSON.stringify(initialSettings))
this.play(playQueue.join("\n\n"))
edide.mmConfigs.activate(initialSettings)
this.play(playQueue.join("\n\n")) // JSON.stringify(initialSettings)
}) // TEMP init instrument
return this;
}).call({}, edide);
"use strict";edide.wave = (function _wave (edide) {
var parent = {
play: function(){
edide.music.play(this.sheet)
return this
},
stop: function(){
edide.music.stop(this.sheet)
return this
},
blur: function(val){
edide.mmConfigs.activate({'blur': val})
return this
},
itch: function(val){
edide.mmConfigs.activate({'itch': val})
return this
},
long: function(val){ // note delay in seconds
edide.mmConfigs.activate({'beatDelay': val*1000})
return this
},
pace: function(val) { // note delay in beats per minute
edide.mmConfigs.activate({'bpm': val})
return this
},
vary: function(val){
edide.mmConfigs.activate({'detune': val})
return this
},
loud: function(val){ // increase (>0) or decrease (<0) amplitude in decibels
edide.mmConfigs.activate({'volume': val})
return this
},
}
return edide.global.wave = (str) => {
var obj = Object.create(parent)
obj.sheet = str
return obj
}
return this;
}).call({}, edide);

View File

@ -112,7 +112,7 @@ describe("Put ACK", function(){
//}
}
console.log(port, " connect to ", peers);
var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 1});
var gun = Gun({file: env.i+'data', peers: peers, web: server, mob: 4});
global.gun = gun;
server.listen(port, function(){
test.done();
@ -136,12 +136,18 @@ describe("Put ACK", function(){
var env = test.props;
var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
// SOME NEXT TEST HERE LOL
var mesh = gun.back('opt.mesh');
mesh.hear['mob'] = function(msg, peer){
// TODO: NOTE, code AXE DHT to aggressively drop new peers AFTER superpeer sends this rebalance/disconnect message that contains some other superpeers.
console.log("we got a message!", msg);
try{ peer.wire.close(); }catch(e){ console.log("err:", e) }
if(!msg.peers){ return }
var one = msg.peers[Math.floor(Math.random()*msg.peers.length)];
console.log("CONNECT TO THIS PEER:", one);
gun.opt(one);
mesh.bye(peer);
if(test.c){ return }
test.c = 1;
test.done();
}
console.log("connected to who superpeer(s)?", gun._.opt.peers);
@ -157,7 +163,7 @@ describe("Put ACK", function(){
browsers.each(function(browser, id){
tests.push(browser.run(function(test){
console.log("...");
console.log("...", gun._.opt.peers);
}, {i: i += 1, config: config}));
});