我目前正在编写一个程序来帮助我控制复杂的灯光安装.我的想法是告诉程序启动预设,然后应用程序有三个选项(取决于预设类型)
1)灯光进入一个位置(所以当预设开始时只发送一组数据)2)灯光遵循一个数学方程式(例如:带有计时器的正弦曲线,以制作光滑的圆圈)3)灯光响应流量数据(ex midi控制器)
所以我决定使用一个我称之为AppBrain的对象,它从控制器和模板接收数据,但也能够将处理后的数据发送到灯光.
现在,我来自非本地编程,我有一些信任问题涉及处理大量处理,事件和时间; 以及理解100%Cocoa逻辑的麻烦.
这是实际问题开始的地方,抱歉
我想要做的是,当我加载预设时,我会解析它以准备定时器/数据接收事件,因此它不必每秒100次通过100个灯的每个选项.
为了更深入地解释,这里是我将如何在Javascript中做到这一点(当然,糟糕的伪代码)
var lightsFunctions = {};
function prepareTemplate(theTemplate){
//Let's assume here the template is just an array, and I won't show all the processing
switch(theTemplate.typeOfTemplate){
case "simpledata":
sendAllDataTooLights(); // Simple here
break;
case "periodic":
for(light in theTemplate.lights){
switch(light.typeOfEquation){
case "sin":
lightsFunctions[light.id] = doTheSinus; // doTheSinus being an existing function
break;
case "cos":
...
}
}
function onFrame(){
for(light in lightsFunctions){
lightsFunctions[light]();
}
}
var theTimer = setTimeout(onFrame, theTemplate.delay);
break;
case "controller":
//do the …Run Code Online (Sandbox Code Playgroud)