コード例 #1
0
ファイル: MDX.cpp プロジェクト: vampirefrog/mdxtools
bool MDXParser::eat(uint8_t b) {
	handleByte(b);
	pos++;
	switch(state) {
		case None:
			if(b >= 0x00 && b <= 0x7f) {
				handleRest(b + 1);
			} else if(b >= 0x80 && b < 0xdf) {
				nn = b;
				state = NoteDuration;
			} else {
				switch(b) {
					case 0xff: // Set tempo
						state = TempoVal;
						break;
					case 0xfe:
						state = OPMRegisterNum;
						break;
					case 0xfd:
						state = VoiceNum;
						break;
					case 0xfc:
						state = PanVal;
						break;
					case 0xfb:
						state = VolumeVal;
						break;
					case 0xfa:
						handleVolumeDec();
						handleCommand(b);
						state = None;
						break;
					case 0xf9:
						handleVolumeInc();
						handleCommand(b);
						state = None;
						break;
					case 0xf8:
						state = SoundLen;
						break;
					case 0xf7:
						handleDisableKeyOff();
						handleCommand(b);
						state = None;
						break;
					case 0xf6:
						state = RepeatStartCount;
						break;
					case 0xf5:
						state = RepeatEndOffsetMSB;
						break;
					case 0xf4:
						state = RepeatEscapeMSB;
						break;
					case 0xf3:
						state = DetuneMSB;
						break;
					case 0xf2:
						state = PortamentoMSB;
						break;
					case 0xf1:
						state = DataEndMSB;
						break;
					case 0xf0:
						state = KeyOnDelayVal;
						break;
					case 0xef:
						state = SyncSendChannel;
						break;
					case 0xee:
						handleSyncWait();
						handleCommand(b);
						state = None;
						break;
					case 0xed:
						state = ADPCMNoiseFreqVal;
						break;
					case 0xec:
						state = LFOPitchWave;
						break;
					case 0xeb:
						state = LFOVolumeWave;
						break;
					case 0xea:
						state = OPMLFOSyncWave;
						break;
					case 0xe9:
						state = LFODelayVal;
						break;
					case 0xe8:
						handlePCM8ExpansionShift();
						handleCommand(b);
						state = None;
						break;
					case 0xe7:
						state = ExtendedCmd;
						break;
					default:
						handleUndefinedCommand(b);
						handleCommand(b);
						break;
				}
			}
			break;
		case NoteDuration:
			handleNote(nn - 0x80, b + 1);
			state = None;
			break;
		case TempoVal:
			handleSetTempo(b);
			handleCommand(0xff, b);
			state = None;
			break;
		case OPMRegisterNum:
			nn = b;
			state = OPMRegisterVal;
			break;
		case OPMRegisterVal:
			handleSetOPMRegister(nn, b);
			handleCommand(0xfe, nn, b);
			state = None;
			break;
		case VoiceNum:
			handleSetVoiceNum(b);
			handleCommand(0xfd, b);
			state = None;
			break;
		case PanVal:
			handlePan(b);
			handleCommand(0xfc, b);
			state = None;
			break;
		case VolumeVal:
			handleSetVolume(b);
			handleCommand(0xfb, b);
			state = None;
			break;
		case SoundLen:
			handleSoundLength(b);
			handleCommand(0xf8, b);
			state = None;
			break;
		case RepeatStartCount:
			handleRepeatStart(b);
			handleCommand(0xf6, b);
			state = RepeatStartZero;
			break;
		case RepeatStartZero:
			state = None;
			break;
		case RepeatEndOffsetMSB:
			nn = b;
			state = RepeatEndOffsetLSB;
			break;
		case RepeatEndOffsetLSB:
			handleRepeatEnd((nn << 8) | b);
			handleCommand(0xf5, (nn << 8) | b);
			state = None;
			break;
		case RepeatEscapeMSB:
			nn = b;
			state = RepeatEscapeLSB;
			break;
		case RepeatEscapeLSB:
			handleRepeatEscape((nn << 8) | b);
			handleCommand(0xf4, (nn << 8) | b);
			state = None;
			break;
		case DetuneMSB:
			nn = b;
			state = DetuneLSB;
			break;
		case DetuneLSB:
			handleDetune((nn << 8) | b);
			handleCommand(0xf3, (nn << 8) | b);
			state = None;
			break;
		case PortamentoMSB:
			nn = b;
			state = PortamentoLSB;
			break;
		case PortamentoLSB:
			handlePortamento((nn << 8) | b);
			handleCommand(0xf2, (nn << 8) | b);
			state = None;
			break;
		case DataEndMSB:
			if(b == 0) {
				handleDataEnd();
				handleCommand(0xf1, 0);
				state = None;
				return true;
			} else {
				nn = b;
				state = DataEndLSB;
			}
			break;
		case DataEndLSB:
			handleDataEnd((nn << 8) | b);
			handleCommand(0xf1, (nn << 8) | b);
			state = None;
			return true;
			break;
		case KeyOnDelayVal:
			handleKeyOnDelay(b);
			handleCommand(0xf0, b);
			state = None;
			break;
		case SyncSendChannel:
			handleSyncSend(b);
			handleCommand(0xef, b);
			state = None;
			break;
		case ADPCMNoiseFreqVal:
			handleADPCMNoiseFreq(b);
			handleCommand(0xed, b);
			state = None;
			break;
		case LFOPitchWave:
			if(b == 0x80) {
				handleLFOPitchMPOF();
				handleCommand(0xec, b);
				state = None;
			} else if(b == 0x81) {
				handleLFOPitchMPON();
				handleCommand(0xec, b);
				state = None;
			} else {
				nn = b;
				state = LFOPitchPeriodMSB;
			}
			break;
		case LFOPitchPeriodMSB:
			w = b << 8;
			state = LFOPitchPeriodLSB;
			break;
		case LFOPitchPeriodLSB:
			w |= b;
			state = LFOPitchChangeMSB;
			break;
		case LFOPitchChangeMSB:
			v = b << 8;
			state = LFOPitchChangeLSB;
			break;
		case LFOPitchChangeLSB:
			v |= b;
			handleLFOPitch(nn, nn == 0 ? w>>2 : w>>1, nn == 1 ? (v + 255) >> 8 : (v * w + 511) >> 9);
			handleCommand(0xec, nn, w, v);
			state = None;
			break;
		case LFOVolumeWave:
			if(b == 0x80) {
				handleLFOVolumeMAOF();
				handleCommand(0xeb, b);
				state = None;
			} else if(b == 0x81) {
				handleLFOVolumeMAON();
				handleCommand(0xeb, b);
				state = None;
			} else {
				nn = b;
				state = LFOVolumePeriodMSB;
			}
			break;
		case LFOVolumePeriodMSB:
			w = b << 8;
			state = LFOVolumePeriodLSB;
			break;
		case LFOVolumePeriodLSB:
			w |= b;
			state = LFOVolumeChangeMSB;
			break;
		case LFOVolumeChangeMSB:
			v = b << 8;
			state = LFOVolumeChangeLSB;
			break;
		case LFOVolumeChangeLSB:
			v |= b;
			handleLFOVolume(nn, nn == 0 ? w>>2 : w>>1, nn == 1 ? (v + 255) >> 8 : (v * w + 255) >> 8);
			handleCommand(0xeb, nn, w, v);
			state = None;
			break;
		case OPMLFOSyncWave:
			if(b == 0x80) {
				handleOPMLFOMHOF();
				handleCommand(0xea, b);
				state = None;
			} else if(b == 0x81) {
				handleOPMLFOMHON();
				handleCommand(0xea, b);
				state = None;
			} else {
				nn = b;
				state = OPMLFOLFRQ;
			}
			break;
		case OPMLFOLFRQ:
			n2 = b;
			state = OPMLFOPMD;
			break;
		case OPMLFOPMD:
			n3 = b;
			state = OPMLFOAMD;
			break;
		case OPMLFOAMD:
			n4 = b;
			state = OPMLFOPMSAMS;
			break;
		case OPMLFOPMSAMS:
			handleOPMLFO(nn, n2, n3, n4, b);
			handleCommand(0xea, nn, n2, n3, n4, b);
			state = None;
			break;
		case LFODelayVal:
			handleLFODelaySetting(b);
			handleCommand(0xe9, b);
			state = None;
			break;
		case ExtendedCmd:
			switch(b) {
				case 0x00:
					handleKill();
					handleCommand(0xe7, 0x00);
					break;
				case 0x01:
					state = FadeOutValue;
					break;
				case 0x03:
					state = FlagValue;
					break;
				default:
					handleCommand(0xe7, b); // bogus, for statistics. Need to handle other commands properly
			}
			break;
		case FadeOutValue:
			handleFadeOut(b);
			handleCommand(0xe7, 0x01, b);
			state = None;
			break;
		case FlagValue:
			handleFlag(b);
			handleCommand(0xe7, 0x03, b);
			state = None;
		default:
			printf("Unknown state %d\n", state);
			break;
	}
	return false;
}
コード例 #2
0
void WorksheetSubStreamHandler::handleRecord(Record* record)
{
    if (!record) return;

    const unsigned type = record->rtti();

    if (type == BottomMarginRecord::id)
        handleBottomMargin(static_cast<BottomMarginRecord*>(record));
    else if (type == BoolErrRecord::id)
        handleBoolErr(static_cast<BoolErrRecord*>(record));
    else if (type == BlankRecord::id)
        handleBlank(static_cast<BlankRecord*>(record));
    else if (type == CalcModeRecord::id)
        handleCalcMode(static_cast<CalcModeRecord*>(record));
    else if (type == ColInfoRecord::id)
        handleColInfo(static_cast<ColInfoRecord*>(record));
    else if (type == DataTableRecord::id)
        handleDataTable(static_cast<DataTableRecord*>(record));
    else if (type == FormulaRecord::id)
        handleFormula(static_cast<FormulaRecord*>(record));
    else if (type == FooterRecord::id)
        handleFooter(static_cast<FooterRecord*>(record));
    else if (type == HeaderRecord::id)
        handleHeader(static_cast<HeaderRecord*>(record));
    else if (type == LabelRecord::id)
        handleLabel(static_cast<LabelRecord*>(record));
    else if (type == LabelSSTRecord::id)
        handleLabelSST(static_cast<LabelSSTRecord*>(record));
    else if (type == LeftMarginRecord::id)
        handleLeftMargin(static_cast<LeftMarginRecord*>(record));
    else if (type == MergedCellsRecord::id)
        handleMergedCells(static_cast<MergedCellsRecord*>(record));
    else if (type == MulBlankRecord::id)
        handleMulBlank(static_cast<MulBlankRecord*>(record));
    else if (type == MulRKRecord::id)
        handleMulRK(static_cast<MulRKRecord*>(record));
    else if (type == NumberRecord::id)
        handleNumber(static_cast<NumberRecord*>(record));
    else if (type == RightMarginRecord::id)
        handleRightMargin(static_cast<RightMarginRecord*>(record));
    else if (type == RKRecord::id)
        handleRK(static_cast<RKRecord*>(record));
    else if (type == RowRecord::id)
        handleRow(static_cast<RowRecord*>(record));
    else if (type == RStringRecord::id)
        handleRString(static_cast<RStringRecord*>(record));
    else if (type == SharedFormulaRecord::id)
        handleSharedFormula(static_cast<SharedFormulaRecord*>(record));
    else if (type == StringRecord::id)
        handleString(static_cast<StringRecord*>(record));
    else if (type == TopMarginRecord::id)
        handleTopMargin(static_cast<TopMarginRecord*>(record));
    else if (type == HLinkRecord::id)
        handleHLink(static_cast<HLinkRecord*>(record));
    else if (type == NoteRecord::id)
        handleNote(static_cast<NoteRecord*>(record));
    else if (type == ObjRecord::id)
        handleObj(static_cast<ObjRecord*>(record));
    else if (type == TxORecord::id)
        handleTxO(static_cast<TxORecord*>(record));
    else if (type == BOFRecord::id)
        handleBOF(static_cast<BOFRecord*>(record));
    else if (type == DefaultRowHeightRecord::id)
        handleDefaultRowHeight(static_cast<DefaultRowHeightRecord*>(record));
    else if (type == DefaultColWidthRecord::id)
        handleDefaultColWidth(static_cast<DefaultColWidthRecord*>(record));
    else if (type == SetupRecord::id)
        handleSetup(static_cast<SetupRecord*>(record));
    else if (type == HCenterRecord::id)
        handleHCenter(static_cast<HCenterRecord*>(record));
    else if (type == VCenterRecord::id)
        handleVCenter(static_cast<VCenterRecord*>(record));
    else if (type == ZoomLevelRecord::id)
        handleZoomLevel(static_cast<ZoomLevelRecord*>(record));
    else if (type == 0xA) {} //EofRecord
    else if (type == DimensionRecord::id)
        handleDimension(static_cast<DimensionRecord*>(record));
    else if (type == MsoDrawingRecord::id)
        handleMsoDrawing(static_cast<MsoDrawingRecord*>(record));
    else if (type == Window2Record::id)
        handleWindow2(static_cast<Window2Record*>(record));
    else if (type == PasswordRecord::id)
        handlePassword(static_cast<PasswordRecord*>(record));
    else if (type == BkHimRecord::id)
        handleBkHim(static_cast<BkHimRecord*>(record));
    else if (type == VerticalPageBreaksRecord::id)
        handleVerticalPageBreaksRecord(static_cast<VerticalPageBreaksRecord*>(record));
    else if (type == HorizontalPageBreaksRecord::id)
        handleHorizontalPageBreaksRecord(static_cast<HorizontalPageBreaksRecord*>(record));
    else if (type == CondFmtRecord::id)
        handleCondFmtRecord(static_cast<CondFmtRecord*>(record));
    else if (type == CFRecord::id)
        handleCFRecord(static_cast<CFRecord*>(record));
    else {
        //std::cout << "Unhandled worksheet record with type=" << type << " name=" << record->name() << std::endl;
    }
}