@@ -1223,18 +1223,15 @@ void postMidiMovePitchCursor(int command) {
1223
1223
}
1224
1224
}
1225
1225
1226
- void cmdMidiInsertNote (Command* command ) {
1226
+ void cmdhInsertNote ( int oldCount, int relativeNote, bool reportNewPos ) {
1227
1227
HWND editor = MIDIEditor_GetActive ();
1228
1228
MediaItem_Take* take = MIDIEditor_GetTake (editor);
1229
- int oldCount;
1230
- MIDI_CountEvts (take, &oldCount, nullptr , nullptr );
1231
- MIDIEditor_OnCommand (editor, command->gaccel .accel .cmd );
1232
1229
int newCount;
1233
1230
MIDI_CountEvts (take, &newCount, nullptr , nullptr );
1234
1231
if (newCount <= oldCount) {
1235
1232
return ; // Not inserted.
1236
1233
}
1237
- int pitch = MIDIEditor_GetSetting_int (editor, " active_note_row" );
1234
+ int pitch = MIDIEditor_GetSetting_int (editor, " active_note_row" ) + relativeNote ;
1238
1235
// Get selected notes.
1239
1236
vector<MidiNote> selectedNotes = getSelectedNotes (take);
1240
1237
// Find the just inserted note based on its pitch, as that makes it unique.
@@ -1250,9 +1247,6 @@ void cmdMidiInsertNote(Command* command) {
1250
1247
previewNotes (take, {note});
1251
1248
fakeFocus = FOCUS_NOTE;
1252
1249
ostringstream s;
1253
- // If we're advancing the cursor position, we should report the new position.
1254
- const bool reportNewPos = command->gaccel .accel .cmd ==
1255
- 40051 ; // Edit: Insert note at edit cursor
1256
1250
if (settings::reportNotes) {
1257
1251
s << getMidiNoteName (take, note.pitch , note.channel ) << " " ;
1258
1252
s << formatNoteLength (note.start , note.end );
@@ -1266,6 +1260,18 @@ void cmdMidiInsertNote(Command* command) {
1266
1260
outputMessage (s);
1267
1261
}
1268
1262
1263
+ void cmdMidiInsertNote (Command* command) {
1264
+ HWND editor = MIDIEditor_GetActive ();
1265
+ MediaItem_Take* take = MIDIEditor_GetTake (editor);
1266
+ int oldCount;
1267
+ MIDI_CountEvts (take, &oldCount, nullptr , nullptr );
1268
+ MIDIEditor_OnCommand (editor, command->gaccel .accel .cmd );
1269
+ // If we're advancing the cursor position, we should report the new position.
1270
+ const bool reportNewPos = command->gaccel .accel .cmd ==
1271
+ 40051 ; // Edit: Insert note at edit cursor
1272
+ cmdhInsertNote (oldCount, 0 , reportNewPos);
1273
+ }
1274
+
1269
1275
void cmdMidiPasteEvents (Command* command) {
1270
1276
HWND editor = MIDIEditor_GetActive ();
1271
1277
MediaItem_Take* take = MIDIEditor_GetTake (editor);
@@ -2413,3 +2419,28 @@ void postMidiChangeZoom(int command) {
2413
2419
outputMessage (format (translate (" {} pixels/second" ), formatDouble (zoom, 1 )));
2414
2420
}
2415
2421
}
2422
+
2423
+ // F1-f12 step input doesn't use actions, so we need to hook the key presses.
2424
+ int midiStepTranslateAccel (MSG* msg, accelerator_register_t * accelReg) {
2425
+ HWND editor = MIDIEditor_GetActive ();
2426
+ if (!editor || msg->message != WM_KEYDOWN || msg->wParam < VK_F1 ||
2427
+ msg->wParam > VK_F12 ||
2428
+ !GetToggleCommandState2 (SectionFromUniqueID (MIDI_EDITOR_SECTION), 40053 )) {
2429
+ // This isn't for us.
2430
+ return 0 ; // Normal handling.
2431
+ }
2432
+ MediaItem_Take* take = MIDIEditor_GetTake (editor);
2433
+ int oldCount;
2434
+ MIDI_CountEvts (take, &oldCount, nullptr , nullptr );
2435
+ // F1 is the note at the pitch cursor, f2 is 1 semitone above, etc.
2436
+ const int relativeNote = msg->wParam - VK_F1;
2437
+ // If the shift key is being held, the cursor is not advancing, so we should
2438
+ // not report the new position.
2439
+ const bool reportNewPos = !(GetAsyncKeyState (VK_SHIFT) & 0x8000 );
2440
+ // We need to let the hook return so REAPER can handle the key and insert the
2441
+ // note. We use CallLater to report the result.
2442
+ CallLater ([oldCount, relativeNote, reportNewPos] {
2443
+ cmdhInsertNote (oldCount, relativeNote, reportNewPos);
2444
+ }, 0 );
2445
+ return 0 ;
2446
+ }
0 commit comments