static BOOL parseCreateBlock (char *line, CtnrBlock *block, char **freeSymbolMap, int idxBlock) { int ret; char *cursor; unsigned long lStartTime, lEndTime; EnumAction blockAction; BOOL inLabel; ret = TRUE; // TODO: set ret = 0 if there's not even a single time or no '-' block->idxFirstAction = -1; block->idxNextStart = MASK_IDX_NEXT_START; block->idxNextEnd = -1; cursor = strchr(line,DELIMITER); cursor++; //either number or whitespace immediately following DELIMITER while (*cursor && isspace(*cursor)) cursor++; //check for block-start action (of type EnumAction) //todo: don't get tricked into seeing digits in [labels] while (*cursor && !isdigit(*cursor) && *cursor != '-') { if (!isspace(*cursor)) { blockAction = getActionEnumFromChar(cursor); if (blockAction >= 0) setStartCode(&block->actionStartEnd,blockAction); //todo:else exception and log } cursor++; } if (*cursor == '-') lStartTime = 0; //nothing before '-' means block begins at beginning of file else lStartTime = strToLong(cursor); //reduce the precision to convert long to int ans space space block->startTime = compressTime(lStartTime, context.package->timePrecision); cursor = strchr(cursor,'-'); do //either number or whitespace immediately following '-' cursor++; while (*cursor && isspace(*cursor)); if (isdigit(*cursor)) lEndTime = strToLong(cursor); else lEndTime = 0xFFFFFFFF; // nothing after '-' means block runs to end of file //reduce the precision to convert long to int ans space space block->endTime = compressTime(lEndTime, context.package->timePrecision); if (block->startTime > block->endTime) ret = FALSE; //todo:log this problem while (*cursor && (isspace(*cursor) || isdigit(*cursor))) cursor++; //check for block-end action (of type EnumAction) while (*cursor && *cursor != '[' && *cursor != '/') { if (!isspace(*cursor)) { blockAction = getActionEnumFromChar(cursor); if (blockAction != -1) setEndCode(&block->actionStartEnd,blockAction); } cursor++; } // check if block is hyperlinked inLabel = FALSE; for (cursor=line;*cursor;cursor++) { if (*cursor == '[') inLabel = TRUE; else if (*cursor == ']') inLabel = FALSE; if (!inLabel && *cursor == '?') { setBlockHyperlinked(block); break; } } // check if block has enter/exit events cursor = strchr(line,'/'); if (cursor != NULL) { // go backwards to beginning of legit enter/exit codes do { cursor--; if (*cursor != '+' && *cursor != '-') blockAction = getEnterExitEnumFromChar(cursor); } while (blockAction != -1 || *cursor == '+' || *cursor == '-' || *cursor == 'N'); //read in enter codes for (cursor++;*cursor != '/';cursor++) { if (*cursor != '-' && *cursor != '+' && *cursor != 'N') { blockAction = getEnterExitEnumFromChar(cursor); setEnterCode(block,blockAction); } } // must be back to '/'; now read in exit codes do { cursor++; if (*cursor && *cursor != '-' && *cursor != '+' && *cursor != 'N') { blockAction = getEnterExitEnumFromChar(cursor); if (blockAction != -1) setExitCode(block,blockAction); } } while (*cursor && (blockAction != -1 || *cursor == '+' || *cursor == '-' || *cursor == 'N')); } cursor = strchr(line,']'); // a block does not need a symbol if nothing refers to it if (cursor != NULL) { //set null marker before ] but also before any whitespace while (isspace(*(cursor-1))) cursor--; *cursor = '\0'; cursor = strchr(line,'['); // todo: error if there is a ] but no [ do cursor++; while (isspace(*cursor)); cursor = strcpy(*freeSymbolMap,cursor); cursor = strchr(cursor,'\0'); *(cursor + 1) = idxBlock; *freeSymbolMap = cursor + 2; } return ret; }
int main (int argc, char *argv[]) { DMXDATA startCode = (DMXDATA)0; DMXDATA cue[512]; DMXDATA temp[512]; DMXDATA BO[512]; //DMXINT Patch[512]; DMXINT changed[512]; DMXINT upTime[512]; DMXINT downTime[512]; DMXINT waitTime[512]; int x; for(x = 0; x < 512; x++) { cue[x] = 128; BO[x] = 0; temp[x] = 0; changed[x] = 0; upTime[x] = 0; downTime[x] = 0; waitTime[x] = 0; // Patch[x] = x; } //for(x = 0; x < 512; x++) //cout << "before load. \n"; dmx_handle usb = open((DMXINT)512, (DMXINT)20); if(isSimulation(usb)) { std::cout << "Could not open port! Running in simulation mode\n"; //return; } std::cout << "after open: " << usb <<" \n"; close(usb); std::cout << "after Close: " << usb <<" \n"; // Sleep(5000); usb = open((DMXINT)512, (DMXINT)20); if(isSimulation(usb)) { std::cout << "Could not open port! Running in simulation mode\n"; //return; } std::cout << "after open: " << usb <<" \n"; setStartCode(usb, startCode); /* Patch[0] = 7; Patch[1] = 1; Patch[2] = 5; Patch[3] = 8; Patch[4] = 12; Patch[7] = 0; Patch[5] = 2; Patch[8] = 3; Patch[12] = 4; */ /* for(x = 0; x < 13; x++) { cout << "Patch[" << x << "] = " << Patch[x] << endl; }//*/ //patch(usb, Patch); // Sleep(1000); //clearPatch(usb); quickLoad(usb, BO); Sleep(1000); /* cout << "Overlaping Cross Fade Delayed Up and Down Times" << endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoad(usb, startCode, temp, changed, 6000, 2000, 1000, 5000); cout << "Channel: " << x << endl; Sleep(7000); printDMX(usb); temp[x] = 0; changed[x] = 0; } */ stopFade(usb); std::cout << "Overlaping Cross Fade Level Feedback Test" << std::endl; for(x = 0; x < 6; x++){ temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoadSplit(usb, temp, changed, 7000, 7000); std::cout << "Channel: " << x << std::endl; Sleep(3000); printDMX(usb); temp[x] = 0; changed[x] = 0; } quickLoad(usb, BO); Sleep(1000); setGrandMaster(usb, 128); std::cout << "Overlaping Cross Fade Level Feedback Test - GM @ 50" << std::endl; for(x = 0; x < 6; x++){ temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoadSplit(usb, temp, changed, 7000, 7000); std::cout << "Channel: " << x << std::endl; Sleep(3000); printDMX(usb); temp[x] = 0; changed[x] = 0; } quickLoad(usb, BO); Sleep(1000); setGrandMaster(usb, 255); setProportionalOutputs(usb, cue); std::cout << "Overlaping Cross Fade Level Feedback Test - PO @ 50" << std::endl; for(x = 0; x < 6; x++){ temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoadSplit(usb, temp, changed, 7000, 7000); std::cout << "Channel: " << x << std::endl; Sleep(3000); printDMX(usb); temp[x] = 0; changed[x] = 0; } quickLoad(usb, BO); Sleep(1000); setGrandMaster(usb, 126); std::cout << "Overlaping Cross Fade Level Feedback Test - PO & GM @ 50" << std::endl; for(x = 0; x < 6; x++){ temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoadSplit(usb, temp, changed, 7000, 7000); std::cout << "Channel: " << x << std::endl; Sleep(3000); printDMX(usb); temp[x] = 0; changed[x] = 0; } setGrandMaster(usb, 255); clearProportionalOutputs(usb); std::cout << "Simple Bumb Test" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; quickLoad(usb, temp); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = (DMXDATA)0; }//*/ quickLoad(usb, BO); Sleep(1000); std::cout << "Sectional Cross Fade Test: ON" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; upTime[x] = 4000*x; downTime[x] = 4000*x; }//*/ complexLoadSplit(usb, temp, changed, upTime, downTime); Sleep(24000); std::cout << "Sectional Cross Fade Test: OFF" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)0; changed[x] = 1; upTime[x] = 4000*x; downTime[x] = 4000*x; }//*/ complexLoadSplit(usb, temp, changed, upTime, downTime); Sleep(24000); quickLoad(usb, BO); Sleep(1000); std::cout << "Overlaping Delayed Bumb Test: ON" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; //quickLoad(usb, startCode, temp); partialLoadSplit(usb, temp, changed, 0, 0); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = 0; changed[x] = 0; }//*/ Sleep(2000); quickLoad(usb, BO); Sleep(1000); std::cout << "Overlaping Delayed Bumb Test: ON" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; waitTime[x] = (7000 - x*1000); //quickLoad(usb, startCode, temp); complexLoadSplit(usb, temp, changed, upTime, downTime); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = 0; changed[x] = 0; }//*/ Sleep(2000); quickLoad(usb, BO); Sleep(1000); std::cout << "Sectional Cross Fade Test: BUMB ON" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; upTime[x] = 0; downTime[x] = 0; }//*/ complexLoadSplit(usb, temp, changed, upTime, downTime); Sleep(1000); std::cout << "Sectional Cross Fade Test: BUMB OFF" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)0; changed[x] = 1; upTime[x] = 0; downTime[x] = 0; }//*/ complexLoadSplit(usb, temp, changed, upTime, downTime); Sleep(1000); quickLoad(usb, BO); Sleep(1000); //*/ // quickLoad(usb, startCode, BO); Sleep(1000); std::cout << "Overlaping Cross Fade Test: OFF" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)0; changed[x] = 1; partialLoadSplit(usb, temp, changed, 7000, 7000); std::cout << "Channel: " << x << std::endl; Sleep(3000); temp[x] = 0; changed[x] = 0; }//*/ quickLoad(usb, BO); Sleep(1000); std::cout << "Overlaping Cross Fade Test: Bumb On" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; changed[x] = 1; partialLoadSplit(usb, temp, changed, 0, 0); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = 0; changed[x] = 0; }//*/ std::cout << "Overlaping Cross Fade Test: Bumb OFF" << std::endl; for(x = 0; x < 6; x++){ temp[x] = (DMXDATA)0; changed[x] = 1; partialLoadSplit(usb, temp, changed, 0, 0); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = 0; changed[x] = 0; }//*/ quickLoad(usb, BO); Sleep(1000); std::cout << "Simple Cross Fade Test" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; fullLoadSplit(usb, temp, 5000, 2000); std::cout << "Channel: " << x << std::endl; Sleep(5000); temp[x] = (DMXDATA)0; }//*/ quickLoad(usb, BO); Sleep(1000); std::cout << "Simple Cross Fade Bumb Test" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; fullLoadSplit(usb, temp, 0, 0); std::cout << "Channel: " << x << std::endl; Sleep(5000); temp[x] = (DMXDATA)0; }//*/ quickLoad(usb, BO); Sleep(1000); std::cout << "Simple Bumb Test" << std::endl; for(x = 0; x < 6; x++) { temp[x] = (DMXDATA)255; quickLoad(usb, temp); std::cout << "Channel: " << x << std::endl; Sleep(1000); temp[x] = (DMXDATA)0; }//*/ quickLoad(usb, BO); Sleep(1000); close(usb); // cout << "after close. \n"; }
static BOOL parseCreateAction (char *line, Action *action, int *actionCount, char *symbolMapStart, CtnrBlock *block, ListItem *list, TranslationList *transList) { //TODO: // Add code to parse speed changes in actions (already incorporated into Action, but nowhere else yet) // //block is NULL when parsing package actions; otherwise it is used to set block startEndAction int ret = TRUE; //todo: add exception handling char *strEvents, *delimeter, *strAction, *cursor; long l; int eventCode, actionCode, index; BOOL inLabel, whenPaused, whenHeld; (*actionCount)++; strEvents = line + 1; // move past the 'A' delimeter = strchr(strEvents,DELIMITER); strAction = delimeter + 1; while (*strAction && isspace(*strAction)) strAction++; eventCode = getEventEnumFromChar(strEvents); // skip whitespace for (strEvents++;*strEvents && isspace(*strEvents);strEvents++); // check for onlyWhenPaused marker if (strEvents < delimeter) { whenPaused = (*strEvents == '|') || (*(strEvents+1) == '|') ; whenHeld = (*strEvents == '_') || (*(strEvents+1) == '_'); } else whenPaused = whenHeld = FALSE; setEventCodes(action + *actionCount, eventCode, whenPaused, whenHeld); // skip whitespace for (strEvents++;*strEvents && isspace(*strEvents);strEvents++); //work on action //but first check if there's a sound insert actionCode = getActionEnumFromChar(strAction); if (actionCode == INSERT_SOUND) { int *pStartEndCode; //process block to be sound-inserted before action is processed index = getIndexFromLine(++strAction,symbolMapStart); action[*actionCount].aux = index; // as long as the index < 2^11-1, a CALL action's rewind bits won't overwrite (see below) setSoundInsert(&action[*actionCount], TRUE); if (list) pStartEndCode = &list->actionStartEnd; else if (transList) pStartEndCode = &transList->actionStartEnd; else pStartEndCode = &block->actionStartEnd; if (eventCode == START) setStartCode(pStartEndCode,INSERT_SOUND); if (eventCode == END) setEndCode(pStartEndCode,INSERT_SOUND); actionCode = -1; // reset so that we can check if we have a new action //move strAction to be ready for action Code for (;*strAction && *strAction != ']';strAction++); if (*strAction) //move just past the ']' and skip whitespace for (strAction++;*strAction && isspace(*strAction);strAction++); if (*strAction) actionCode = getActionEnumFromChar(strAction); /* CODE BELOW IS BAD BECAUSE IT OVERWRITES BLOCK START/END ACTIONS SET ON BLOCK LINE AND NO LONGER NECESSARY. if ((!*strAction || actionCode == -1) && (eventCode1 == START || eventCode1 == END) && (eventCode2 == START || eventCode2 == END)) { actionCode = INSERT_SOUND; setActionCode(action + *actionCount, actionCode); } else ret = FALSE; */ } if (actionCode != -1) { setActionCode(action + *actionCount,actionCode); // actions like STOP, PAUSE, RETURN, FWD, BACK don't require parameters if (actionCode == JUMP_TIME || actionCode == CALL_BLOCK) { // get to numbers, but skip numbers inside any label inLabel = FALSE; for (cursor=strAction;*cursor;cursor++) { if (*cursor == '[') inLabel = TRUE; else if (*cursor == ']') inLabel = FALSE; if (!inLabel && (isdigit(*cursor) || *cursor == '-' || *cursor == '+')) break; } if (*cursor) { l = strToLong(cursor); switch (actionCode) { case JUMP_TIME: action[*actionCount].destination = compressTime(l, context.package->timePrecision); break; case CALL_BLOCK: setRewind(&action[*actionCount].aux,(int)l); break; default: /// not used now; was originally used for VOLUME and SPEED action[*actionCount].destination = (int)l; break; } } else if (actionCode == CALL_BLOCK) // no specified rewind time, so use default setRewind(&action[*actionCount].aux,-DEFAULT_REWIND); } if (actionCode == DELETE || actionCode == DELETE_MESSAGES || actionCode == COPY || actionCode == TRIM || actionCode == SURVEY_TAKEN || actionCode == SURVEY_APPLY || actionCode == SURVEY_USELESS || actionCode == POSITION_TO_TOP || actionCode == MAKE_FAVORITE || actionCode == RECORD_FEEDBACK) { strAction++; if (actionCode == SURVEY_TAKEN || actionCode == SURVEY_APPLY || actionCode == SURVEY_USELESS || actionCode == DELETE_MESSAGES || actionCode == RECORD_FEEDBACK) strAction++; // skip the 't', 'a', or 'u' or 'm' while (isspace(*strAction)) strAction++; if (*strAction == '{') { // variable-based package cursor = strchr(strAction,'}'); if (cursor) *cursor = 0; else { logException(8,strAction,0); // syntax error in control track ret = FALSE; } strAction++; index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].destination = index; } else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } else if (actionCode == POSITION_TO_TOP) // otherwise no parameter is legit for pushing language to top action[*actionCount].destination = -1; else { ret = FALSE; logException(8,strAction,0); // syntax error in control track } if (actionCode != TRIM) { // TRIM doesn't use aux cursor++; index = getIndexFromLine(cursor,symbolMapStart); if (index != -1) action[*actionCount].aux = index; } } if (actionCode == JUMP_BLOCK || actionCode == CALL_BLOCK || actionCode == CLONE || actionCode == COPY_LANGUAGE || actionCode == RECORD_TITLE || actionCode == RECORD_MSG || actionCode == PACKAGE_RECORDING || actionCode == USB_DEVICE_ON || actionCode == USB_HOST_ON) { if (actionCode == RECORD_TITLE || actionCode == RECORD_MSG) { // check if recording from headphone port instead of a microphone if (*(strAction+2) == '-') { // moves past 'E' and 't'/'m' action[*actionCount].aux = 1; strAction += 3; } else action[*actionCount].aux = 0; } index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) action[*actionCount].destination = index; //else { // ret = FALSE; // logException(6,strAction,0); // todo:invalid internal reference in control track file //} // TODO:If (index==-1), there was no destination ("[]"), which is ok for now -- and ret=FALSE was ignored anyway // else // ret = FALSE; } if (actionCode == JUMP_PACKAGE) { strAction++; if (*strAction == '{') { // variable-based package cursor = strchr(strAction,'}'); if (cursor) *cursor = 0; strAction++; index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].destination = index; action[*actionCount].aux = PKG_VARIABLE; } else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } else { // explicit name if (*strAction == SYS_PKG_CHAR) { action[*actionCount].aux = PKG_SYS; strAction++; } else if (*strAction == APP_PKG_CHAR) { action[*actionCount].aux = PKG_APP; strAction++; } else action[*actionCount].aux = PKG_MSG; cursor = strchr(strAction,'>'); if (cursor == strAction) // "<%>" indicates current system package action[*actionCount].destination = SAME_SYSTEM; else { if (*strAction == '+') action[*actionCount].destination = NEXT_SYSTEM; else if (*strAction == '-') action[*actionCount].destination = PREV_SYSTEM; else logException(8,strAction-2,USB_MODE); } } } if (actionCode == JUMP_LIST) { strAction++; switch (*strAction) { case '+': setListRotation(&action[*actionCount].aux, 1); strAction++; break; case '-': setListRotation(&action[*actionCount].aux, -1); strAction++; break; default: action[*actionCount].aux = 0; } index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) action[*actionCount].destination = index; else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } if (actionCode == DELETE_TRANSLATION || actionCode == WRAP_TRANSLATION) { //strAction = strAction+3; index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) action[*actionCount].destination = index; else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } if (actionCode == TRANSLATE_NEW){ //Get first block and store in destination //Move past 'c' (c for create) strAction=strAction+2; while (*strAction && isspace(*strAction)) strAction++; if (*strAction == '[') { cursor = strchr(strAction,']'); index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].destination = index; strAction = cursor+1; } else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } else { ret = FALSE; logException(8,strAction,0); // syntax error in control track } } if (actionCode == TRANSLATE_OVERWRITE) { //Get first block and store in destination //Move past '!' strAction=strAction+2; while (*strAction && isspace(*strAction)) strAction++; if (*strAction == '[') { cursor = strchr(strAction,']'); index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].destination = index; strAction = cursor+1; } else { ret = FALSE; logException(6,strAction,0); // todo:invalid internal reference in control track file } } else { ret = FALSE; logException(8,strAction,0); // syntax error in control track } } if (actionCode == TRANSLATE_DELETE_FINISH) { //Get first block and store in destination //Move past ? strAction=strAction+2; while (*strAction && isspace(*strAction)) strAction++; if (*strAction == '[') { cursor = strchr(strAction,']'); //if (cursor) // *cursor = 0; //else { // logException(8,strAction,0); // syntax error in control track // ret = FALSE; //} //strAction++; index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].destination = index; strAction = cursor+1; } else { ret = FALSE; logException(6,(char *)"here1",0); // todo:invalid internal reference in control track file } } else { ret = FALSE; logException(8,strAction,0); // syntax error in control track } // Store second block name in aux while (*strAction && isspace(*strAction)) strAction++; if (*strAction == '[') { //cursor = strchr(strAction,']'); //if (cursor) // *cursor = 0; //else { // logException(8,strAction,0); // syntax error in control track // ret = FALSE; //} //strAction++; index = getIndexFromLine(strAction,symbolMapStart); if (index != -1) { action[*actionCount].aux = index; } else { ret = FALSE; logException(6,(char *)"here1",0); // todo:invalid internal reference in control track file } } else { ret = FALSE; logException(8,strAction,0); // syntax error in control track } ///////// } } if ((block || list || transList) && actionCode != -1) { int *pStartEndCode; if (list) pStartEndCode = &list->actionStartEnd; else if (transList) pStartEndCode = &transList->actionStartEnd; else pStartEndCode = &block->actionStartEnd; if (eventCode == START) setStartCode(pStartEndCode,actionCode); if (eventCode == END) setEndCode(pStartEndCode,actionCode); } return ret; }