rPonto SegmentoBasico::intercecao(const RetanguloBasico &r) const { float mix = m_ini.x(), miy = m_ini.y(), mfx = m_fim.x(), mfy = m_fim.y(); SegmentoBasico si(r.pontoInferiorEsquerdo(), r.pontoInferiorDireito()), ss(r.pontoSuperiorEsquerdo(), r.pontoSuperiorDireito()), sle(r.pontoSuperiorEsquerdo(),r.pontoInferiorEsquerdo()), sld(r.pontoSuperiorDireito() , r.pontoInferiorDireito()); float s; s = intercecaoS(si); if(s >= 0.f && s <= 1.f) { cout << "OK si" << endl; return rPonto(mix + (mfx-mix)*s, miy + (mfy-miy)*s); } s = intercecaoS(ss); if(s >= 0.f && s <= 1.f) { cout << "OK ss" << endl; return rPonto(mix + (mfx-mix)*s, miy + (mfy-miy)*s); } s = intercecaoS(sle); if(s >= 0.f && s <= 1.f) { cout << "OK sle" << endl; return rPonto(mix + (mfx-mix)*s, miy + (mfy-miy)*s); } s = intercecaoS(sld); if(s >= 0.f && s <= 1.f) { cout << "OK sld" << endl; return rPonto(mix + (mfx-mix)*s, miy + (mfy-miy)*s); } return rPonto(0,0); }
int main(int argc, char* argv[]) { // initialize Launchpad MIDI Launchpad launchpad; launchpad.initMidi(); // test /*for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { launchpad.plot(x * 2, y * 2, x, y); launchpad.plot(x * 2 + 1, y * 2 + 1, x, y); } }*/ NanoKontrol nanoKontrol; /*nanoKontrol.initMidi(); nanoKontrol.bindControl(16, &fltrRawCutoff); nanoKontrol.bindControl(17, &(fltr.reso)); nanoKontrol.bindControl(18, &changeRoom); nanoKontrol.bindControl(19, &changeDamp); nanoKontrol.bindControl(20, &changeDecay); nanoKontrol.bindControl(21, &changeCurve);*/ kontrolF1.bindControl(30, &fltrRawCutoff); kontrolF1.bindControl(31, &(fltr.reso)); kontrolF1.bindControl(32, &changeRoom); kontrolF1.bindControl(33, &changeDamp); kontrolF1.bindControl(37, &changeDecay); // kontrolF1.bindControl(21, &changeCurve); for (int x = 0; x < 8; x++) { for (int y = 0; y < 3; y++) { nanoKontrol.plot(x, y, false); } } kontrolF1.initMidi(); kontrolF1.bindControl(34, &f1ChangeH); kontrolF1.bindControl(35, &f1ChangeS); kontrolF1.bindControl(36, &f1ChangeB); kontrolF1.bindPads(&selectPad); // initialize SDL video and audio if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) return 1; // make sure SDL cleans up before exit atexit(SDL_Quit); // init synth osc3.freq = 0.03; osc3.width = 0.9; glide.freq = 0.004; fltrSmoothCutoff.freq = 0.001; env.setReleaseTime(0.3); env.setCurvature(0.8); clk.setTempo(tempo); seq.setTempo(tempo); reverb.setRoomSize(0.3); reverb.setDamp(0.3); mix = 0.0; fltr.connect(&mix); glide.connect(&(seq.out)); fltrSmoothCutoff.connect(&fltrRawCutoff); env.connect(&(clk.out)); reverb.connect(&dry); // init SDL audio { SDL_AudioSpec audioSpec; audioSpec.freq = SAMPLE_RATE; // 44.1 kHz audioSpec.format = AUDIO_S16; // signed 16 bit audioSpec.channels = 2; // stereo audioSpec.samples = 512; // buffer size: 512 audioSpec.callback = audioCallback; SDL_OpenAudio(&audioSpec, NULL); } SDL_PauseAudio(0); // start audio SDL_Surface* screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_WM_SetCaption("oodio", NULL); RenderingContext ctx(screen); ctx.backgroundColor(0, 0, 127); // load images AmsFont font("img/amstradFont.bmp"); Button btn(5, 23, "start/stop"); Button btnf(5, 25, "filter"); Slider sld(5, 27, 10, 0.1, 2); Slider cut(12, 25, 30, 0.0, 1.0); Slider res(16, 23, 26, 0.0, 0.7); btn.onClic(&playStop); btnf.onClic(&activateFilter); sld.onChange(&(osc3.freq)); cut.onChange(&fltrRawCutoff); res.onChange(&(fltr.reso)); displayMidiPorts(&font); // displayHidDevices(&font); btn.draw(&font); btnf.draw(&font); font.paper(1); font.pen(24); int nkx = 0; // program main loop bool run = true; while (run) { //------------------------- // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { case SDL_QUIT: // exit if the window is closed run = false; break; // check for keypresses case SDL_KEYDOWN: // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) run = false; // start / stop sound with F1 key else if (event.key.keysym.sym == SDLK_F1) playStop(); else if (event.key.keysym.sym == SDLK_F2) osc1.freq = 110; else if (event.key.keysym.sym == SDLK_F3) osc1.freq = 440; // keyboard else if (event.key.keysym.sym <= 256 && event.key.keysym.sym >= 0 ) { font.print(event.key.keysym.sym); } break; case SDL_MOUSEMOTION: // font.locate(event.motion.x / (8 * PIXEL), event.motion.y / (8 * PIXEL)); // font.paper(-1); // font.print('*'); sld.move(event.motion.x, event.motion.y); cut.move(event.motion.x, event.motion.y); res.move(event.motion.x, event.motion.y); break; case SDL_MOUSEBUTTONDOWN: btn.clic(event.button.x, event.button.y); btnf.clic(event.button.x, event.button.y); sld.clic(event.button.x, event.button.y); cut.clic(event.button.x, event.button.y); res.clic(event.button.x, event.button.y); break; case SDL_MOUSEBUTTONUP: sld.unclic(event.button.x, event.button.y); cut.unclic(event.button.x, event.button.y); res.unclic(event.button.x, event.button.y); break; } } ctx.clear(); sld.draw(&font); cut.draw(&font); res.draw(&font); ctx.drawImage(font.getImage(), 0, 0); ctx.update(); //---------------------------------- // nanoKontrol light show /*nkx--; if (nkx < 0) nkx = 15; for (int x = 0; x < 8; x++) { for (int y = 0; y < 3; y++) { bool value = ((nkx + x + y) % 16) < 2; nanoKontrol.plot(x, y, value); } }*/ //---------------------------------- SDL_Delay(40); // 25 FPS } // close audio SDL_CloseAudio(); // close midi // midiOutReset(device); // midiOutClose(device); return 0; }