Пример #1
0
void ProjectViewer::dropEvent(QGraphicsSceneDragDropEvent *event)
{
    event->accept();
    std::stringstream ss;
    QTreeWidget * lw = (QTreeWidget*) event->source();
    QString classname =  lw->currentItem()->text(0);
    std::string type = lw->currentItem()->text(1).toStdString();
    if (type.compare("Module") == 0) {
        emit NewModule(classname, event->scenePos(), this->rootGroup->getDMModel());
    } else {
        this->ResultViewer->importSimulation( lw->currentItem()->text(2), event->scenePos());
    }

}
Пример #2
0
Файл: wcX.c Проект: aji/nursery
int main(int argc, char *argv[]) {
	ModularContext mctx;
	Module *master;
	Module *output;
	int timer;

	srand(0);

	mctx.rate = SAMPLE_RATE;

	ModularInitialize(&mctx);
	master = ModularMaster(&mctx);
	output = ModularOutput(&mctx);

	Module *osc = NewModule(&mctx, &ModOscillator);
	Module *env = NewModule(&mctx, &ModADSR);

	OscillatorGet(osc)->waveform = OscBandlimitedSaw;

	*ADSRGet(env)->A = 0.006;
	*ADSRGet(env)->D = 0.700;
	*ADSRGet(env)->S = 0.000;
	*ADSRGet(env)->R = 0.100;
	*ADSRGet(env)->trig = 0.0;

	OscillatorGet(osc)->gain = env->out;
	AddDependency(&mctx, osc, env);

	Module *filt = NewModule(&mctx, &ModFilter);
	FilterSetInput(&mctx, filt, osc);

	Module *env2filt = NewModule(&mctx, &ModMatrix);
	MatrixSetInput(&mctx, env2filt, env);
	MatrixScale(env2filt, 0.0, 1.0, 10.0, 10000.0);
	FilterGet(filt)->cutoff = env2filt->out;
	AddDependency(&mctx, filt, env2filt);

	Module *env2reso = NewModule(&mctx, &ModMatrix);
	MatrixSetInput(&mctx, env2reso, env);
	MatrixScale(env2reso, 0.0, 1.0, 0.1, 2.0);
	FilterGet(filt)->reso = env2reso->out;
	AddDependency(&mctx, filt, env2reso);

	MixerSlot *slot = MixerAddSlot(&mctx, master, filt, 0.3, 0.0);

	KeyController *kc = NewMonoSynth();
	OscillatorGet(osc)->freq  = MonoSynthGet(kc)->freq;
	ADSRGet(env)->trig        = MonoSynthGet(kc)->trig;


	Module *bassosc = NewModule(&mctx, &ModOscillator);
	Module *bassenv = NewModule(&mctx, &ModADSR);

	OscillatorGet(bassosc)->waveform = OscBandlimitedSaw;

	*ADSRGet(bassenv)->A = 0.006;
	*ADSRGet(bassenv)->D = 0.200;
	*ADSRGet(bassenv)->S = 0.000;
	*ADSRGet(bassenv)->R = 0.100;
	*ADSRGet(bassenv)->trig = 0.0;

	//OscillatorGet(bassosc)->gain = bassenv->out;
	AddDependency(&mctx, bassosc, bassenv);

	Module *bassfilt = NewModule(&mctx, &ModFilter);
	FilterSetInput(&mctx, bassfilt, bassosc);

	Module *bassenv2filt = NewModule(&mctx, &ModMatrix);
	MatrixSetInput(&mctx, bassenv2filt, bassenv);
	MatrixScale(bassenv2filt, 0.0, 1.0, 50.0, 5000.0);
	FilterGet(bassfilt)->cutoff = bassenv2filt->out;
	AddDependency(&mctx, bassfilt, bassenv2filt);
	*FilterGet(bassfilt)->reso = 0.4;

	MixerSlot *bassslot = MixerAddSlot(&mctx, master, bassfilt, 0.3, 0.0);

	KeyController *bkc = NewMonoSynth();
	OscillatorGet(bassosc)->freq  = MonoSynthGet(bkc)->freq;
	ADSRGet(bassenv)->trig        = MonoSynthGet(bkc)->trig;


	for (timer=0; ; timer++) {
		ModularStep(&mctx);

		if (timer % 96000 == 84000)
			seq = seqs[((timer / 96000) % 2)];

		if (timer % 12000 == 0)
			KeyControllerKeyDown(kc, seq[(timer / 12000) % 4] - 12, 64);
		if (timer % 24000 == 22000)
			KeyControllerKeyUp(kc, seq[(timer / 12000) % 4] - 12);
		KeyControllerUpdate(kc);

		if (timer % 12000 == 0)
			KeyControllerKeyDown(bkc, bass[(timer / 12000) % 16], 64);
		if (timer % 12000 == 11000)
			KeyControllerKeyUp(bkc, bass[(timer / 12000) % 16]);
		KeyControllerUpdate(bkc);

		put_frame(output->out[0] * OUTPUT_SCALE,
		          output->out[1] * OUTPUT_SCALE);
	}

	return 0;
}
Пример #3
0
// Pass One
int ParseFile(FILE * pFile, MODULE_t ** pMT)
{
    if (!pFile)
    {
        // file pointer invalid?
        printf("File access error, exit.\n");
        return -1;
    }

    size_t line_num = 0;
    unsigned int offset;
    char * token = NULL;
    char symbol[17];
    int addr = 0;
    STATE_t state = DEF_COUNT;
    MODULE_t * MT;
    int count, code_size = 0;

    for (;;)
    {
        token = GetToken(pFile, &line_num, &offset);
        switch (state)
        {
            case DEF_COUNT:
                if (!token)
                    return 0;       // EOF when expecting a defcount, 
                                    // regarded as success
                if (!isNum(token))  // if token is not presenting a number
                    return __parseerror(NUM_EXPECTED, line_num, offset);

                count = atoi(token);
                if (count > 16)
                    return __parseerror(TO_MANY_DEF_IN_MODULE, line_num, offset);

                NewModule(pMT, code_size);
                MT = *pMT;
                if (count == 0)
                    state = USE_COUNT;
                else
                    state = DEF_S;
                break;

            case DEF_S:
                if (isValidSymbol(token) == SYM_INVALID)
                    return __parseerror(SYM_EXPECTED, line_num, offset);
                if (isValidSymbol(token) == SYM_LONG)
                    return __parseerror(SYM_TOLONG, line_num, offset);

                strcpy(symbol, token);  // preserve symbol name
                state = DEF_R;
                break;

            case DEF_R:
                if (!isNum(token))
                    return __parseerror(NUM_EXPECTED, line_num, offset);

                addr = atoi(token);
                AddSymbol(MT, symbol, code_size+addr);
                count--;
                if (count == 0)
                    state = USE_COUNT;
                else
                    state = DEF_S;

                break;

            case USE_COUNT:
                if (!isNum(token))  // if token is not presenting a number
                    return __parseerror(NUM_EXPECTED, line_num, offset);

                count = atoi(token);
                if (count > 16)
                    return __parseerror(TO_MANY_USE_IN_MODULE, line_num, offset);

                if (count == 0)
                    state = CODE_COUNT;
                else
                    state = USE_LIST;
                break;

            case USE_LIST:
                if (isValidSymbol(token) == SYM_INVALID)
                    return __parseerror(SYM_EXPECTED, line_num, offset);
                if (isValidSymbol(token) == SYM_LONG)
                    return __parseerror(SYM_TOLONG, line_num, offset);

                AddUse(MT, token);
                count--;
                if (count == 0)
                    state = CODE_COUNT;
                else
                    state = USE_LIST;
                break;

            case CODE_COUNT:
                if (!isNum(token))  // if token is not presenting a number
                    return __parseerror(NUM_EXPECTED, line_num, offset);

                count = atoi(token);
                if (count + code_size > 512)
                    return __parseerror(TO_MANY_INSTR, line_num, offset);

                SetModuleSize(MT, count);

                if (count == 0)
                    state = DEF_COUNT;
                else
                {
                    code_size += count;     // keep calculating code size
                    state = CODE_TYPE;
                }
                break;

            case CODE_TYPE:
                if(!isAddrType(token))
                    return __parseerror(ADDR_EXPECTED, line_num, offset);
                state = CODE_INSTR;
                break;

            case CODE_INSTR:
                if (!isNum(token))  // if token is not presenting a number
                    return __parseerror(NUM_EXPECTED, line_num, offset);
                count--;
                if (count == 0)
                    state = DEF_COUNT;
                else
                    state = CODE_TYPE;
                break;

            default:
                break;
        }   // switch
    }   // for
}