MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / KeyPressed

Method KeyPressed

Source/NoteStepSequencer.cpp:1368–1444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1366}
1367
1368void NoteStepSequencer::KeyPressed(int key, bool isRepeat)
1369{
1370 IDrawableModule::KeyPressed(key, isRepeat);
1371
1372 ofVec2f mousePos(TheSynth->GetMouseX(GetOwningContainer()), TheSynth->GetMouseY(GetOwningContainer()));
1373 if (mGrid->GetRect().contains(mousePos.x, mousePos.y))
1374 {
1375 auto cell = mGrid->GetGridCellAt(mousePos.x - mGrid->GetPosition().x, mousePos.y - mGrid->GetPosition().y);
1376 int tone = mTones[cell.mCol];
1377 if (key == OF_KEY_DOWN && tone > 0)
1378 {
1379 --mTones[cell.mCol];
1380 SyncGridToSeq();
1381 }
1382 if (key == OF_KEY_UP && tone < mNoteRange - 1)
1383 {
1384 ++mTones[cell.mCol];
1385 SyncGridToSeq();
1386 }
1387 if (key == OF_KEY_LEFT)
1388 {
1389 mNoteLengths[cell.mCol] = mNoteLengths[cell.mCol] * 0.5f;
1390 SyncGridToSeq();
1391 }
1392 if (key == OF_KEY_RIGHT)
1393 {
1394 mNoteLengths[cell.mCol] = MIN(1.0f, mNoteLengths[cell.mCol] * 2);
1395 SyncGridToSeq();
1396 }
1397 }
1398 if (mVelocityGrid->GetRect().contains(mousePos.x, mousePos.y))
1399 {
1400 auto cell = mGrid->GetGridCellAt(mousePos.x - mGrid->GetPosition().x, mousePos.y - mGrid->GetPosition().y);
1401 if (key == OF_KEY_UP || key == OF_KEY_DOWN)
1402 {
1403 float velocity = mVelocityGrid->GetVal(cell.mCol, cell.mRow);
1404 if (velocity > 0)
1405 {
1406 if (key == OF_KEY_UP)
1407 {
1408 for (int i = 0; i < (int)gStepVelocityLevels.size(); ++i)
1409 {
1410 if (velocity < gStepVelocityLevels[i] - .01f)
1411 {
1412 mVelocityGrid->SetVal(cell.mCol, cell.mRow, gStepVelocityLevels[i]);
1413 mVels[cell.mCol] = gStepVelocityLevels[i] * 127;
1414 break;
1415 }
1416 }
1417 }
1418
1419 if (key == OF_KEY_DOWN)
1420 {
1421 for (int i = (int)gStepVelocityLevels.size() - 1; i >= 0; --i)
1422 {
1423 if (velocity > gStepVelocityLevels[i] + .01f)
1424 {
1425 mVelocityGrid->SetVal(cell.mCol, cell.mRow, gStepVelocityLevels[i]);

Callers

nothing calls this directly

Calls 9

containsMethod · 0.80
GetValMethod · 0.80
sizeMethod · 0.80
SetValMethod · 0.80
GetMouseXMethod · 0.45
GetMouseYMethod · 0.45
GetRectMethod · 0.45
GetGridCellAtMethod · 0.45
GetPositionMethod · 0.45

Tested by

no test coverage detected