app/js/patchwork/core/Patch.js
/**
         * Adds a module to the patch.
         * @param moduleType
         * @param moduleArguments
         * @param moduleObject
         * @returns {Module}
         */
Adds a module to the patch.
Adds a module to the patch .
addModuleByType(moduleType, moduleArguments, moduleObject) {
            if (!moduleType) {
                console.error('No type given');
                return;
            }
            let definition = ModuleDefinitions_1.default.findByType(moduleType);
            if (definition) {
                if (typeof this.countsByType[moduleType] === 'undefined')
                    this.countsByType[moduleType] = 0;
                this.countsByType[moduleType]++;
                let moduleId = moduleObject ? moduleObject.id : moduleType + Patch.ID_COUNT_SEPARATOR + this.countsByType[moduleType];
                let module = new Module_1.default(this, definition, moduleId, moduleArguments);
                this.modules.push(module);
                if (moduleObject) {
                    module.position = moduleObject.pos;
                }
                if (definition.type === ModuleTypes_1.default.SUBPATCH) {
                    let subPatch = new Patch(this.audioContext, module);
                    this.addEventListenersToSubPatch(subPatch);
                    if (!moduleObject) {
                        subPatch.addModuleByType(ModuleTypes_1.default.INPUT);
                        subPatch.addModuleByType(ModuleTypes_1.default.OUTPUT);
                    }
                    else {
                        subPatch.fromObject(moduleObject.subPatch);
                    }
                    module.subPatch = subPatch;
                }
                this.addEventListenersToModule(module);
                this.dispatchEvent(PatchEvent_1.default.MODULE_ADDED, { module: module, args: moduleArguments });
                if (moduleObject)
                    module.setAttributesByLoadedObject(moduleObject);
                return module; 
            }
            else {
                console.error('No module definition found for type: ' + moduleType);
            }
        }
addModuleByType ( moduleType , moduleArguments , moduleObject ) { if ( ! moduleType ) { console . error ( 'No type given' ) ; return ; } let definition = ModuleDefinitions_1 . default . findByType ( moduleType ) ; if ( definition ) { if ( typeof this . countsByType [ moduleType ] === 'undefined' ) this . countsByType [ moduleType ] = 0 ; this . countsByType [ moduleType ] ++ ; let moduleId = moduleObject ? moduleObject . id : moduleType + Patch . ID_COUNT_SEPARATOR + this . countsByType [ moduleType ] ; let module = new Module_1 . default ( this , definition , moduleId , moduleArguments ) ; this . modules . push ( module ) ; if ( moduleObject ) { module . position = moduleObject . pos ; } if ( definition . type === ModuleTypes_1 . default . SUBPATCH ) { let subPatch = new Patch ( this . audioContext , module ) ; this . addEventListenersToSubPatch ( subPatch ) ; if ( ! moduleObject ) { subPatch . addModuleByType ( ModuleTypes_1 . default . INPUT ) ; subPatch . addModuleByType ( ModuleTypes_1 . default . OUTPUT ) ; } else { subPatch . fromObject ( moduleObject . subPatch ) ; } module . subPatch = subPatch ; } this . addEventListenersToModule ( module ) ; this . dispatchEvent ( PatchEvent_1 . default . MODULE_ADDED , { module : module , args : moduleArguments } ) ; if ( moduleObject ) module . setAttributesByLoadedObject ( moduleObject ) ; return module ; } else { console . error ( 'No module definition found for type: ' + moduleType ) ; } }
Adds a module to the patch.
Adds a module to the patch .
//console.log('addModuleByType', moduleType); // init the counter for this moduletype // increase count // get the id of the module (module data, containing a saved id is given when loading a patch) // create the module TODO try/catch this all and make sure the id doesnt get incremented if all fails // if the module was loaded, set the position as well (so the visualmodule doesnt set to default startposition) // if it was a subpatch, we need to give it a new patch // listen to subpatch events. should be done BEFORE setting the subpatch, so that when loaded, the events from adding nested modules // are caught and the ACM can set the audionode // module was NOT created from parsing an object, create default subpatch // module created from parsing an object, parse the subpatch // set it // listen to module events // notify ACM (audionode gets set in this module) and the editor (visual module is created) // after event has been dispatched, set the values (so there is a node to set the values on and the visual module can update its values) // for now only needed for parsing a json and handling a subpatch TODO what is this?!