Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 07-19-2017, 03:11 PM   #1
Audio_Birdi
Human being with feelings
 
Audio_Birdi's Avatar
 
Join Date: Dec 2015
Posts: 73
Default Script to unselect / de-select first note of selected notes / events in midi editor?

Hi there,

i came across the following script which selects every 2nd event within a range of already selected notes.

How would I go about creating a script that unselects / deselects only the first note / event of a pre-existing note selection?

Thanks in advance!

Quote:
// Unselects every second selected event. Notes and CC are handled separately. (original by Veto, this version by spk77 - thanks a lot, guys)
// Uses "MIDI_Enum" -functions

Undo_BeginBlock2(0);
function unselectEverySecondEvent()
(
(take = MIDIEditor_GetTake(MIDIEditor_GetActive())) ? (
allEvents = MIDI_CountEvts(take, noteCount, ccCount, sysExCount);

index = -1;
k = 1;
while ((index = MIDI_EnumSelNotes(take, index)) != -1) (
MIDI_GetNote(take, index, isSelected, isMuted, startPpqPos, endPpqPos, channel, pitch, velocity) ? (
k % 2 == 0 ? (
MIDI_SetNote(take, index, 0, isMuted, startPpqPos, endPpqPos, channel, pitch, velocity);
);
k += 1;
);
);

index = -1;
n = 1;
while ((index = MIDI_EnumSelCC(take, index)) != -1) (
MIDI_GetCC(take, index, isSelected, isMuted, PpqPos, type, channel, CCnr, value) ? (
n % 2 == 0 ? (
MIDI_SetCC(take, index, 0, isMuted, PpqPos, type, channel, CCnr, value);
);
n += 1;
);
);
);
);

unselectEverySecondEvent();
Undo_EndBlock2(0,"Unselect every second note/CC",-1);

Last edited by Audio_Birdi; 07-20-2017 at 06:14 AM.
Audio_Birdi is offline   Reply With Quote
Old 07-23-2017, 03:42 AM   #2
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Code:
activeTake = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
reaper.MIDI_Sort(activeTake)
selectedNoteIndex = reaper.MIDI_EnumSelNotes(activeTake, -1)
if selectedNoteIndex ~= -1 then reaper.MIDI_SetNote(activeTake, selectedNoteIndex, false, nil, nil, nil, nil, nil, nil, false) end
juliansader is offline   Reply With Quote
Old 07-23-2017, 04:09 AM   #3
Audio_Birdi
Human being with feelings
 
Audio_Birdi's Avatar
 
Join Date: Dec 2015
Posts: 73
Default

Quote:
Originally Posted by juliansader View Post
Code:
activeTake = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
reaper.MIDI_Sort(activeTake)
selectedNoteIndex = reaper.MIDI_EnumSelNotes(activeTake, -1)
if selectedNoteIndex ~= -1 then reaper.MIDI_SetNote(activeTake, selectedNoteIndex, false, nil, nil, nil, nil, nil, nil, false) end
Thanks so much for creating this! it works splendidly

A quick request if you don't mind, is there a way have the script toggle between unselecting the first note and then re-selecting it again when clicking /activating the script again?

Thanks again Julian!
Audio_Birdi is offline   Reply With Quote
Old 07-23-2017, 06:34 AM   #4
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

The following is a very simple version of a toggle script, and will only work if don't make other changes to the notes and note selection:
Code:
activeTake = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
savedIndex = tonumber(reaper.GetExtState("js_Toggle first note", "Index"))
if savedIndex then
    reaper.MIDI_SetNote(activeTake, savedIndex, true, nil, nil, nil, nil, nil, nil, true)
    reaper.DeleteExtState("js_Toggle first note", "Index", true)
    reaper.Undo_OnStateChange_Item(0, "Re-select first selected note", reaper.GetMediaItemTake_Item(activeTake))
else
    reaper.MIDI_Sort(activeTake)
    selectedNoteIndex = reaper.MIDI_EnumSelNotes(activeTake, -1)
    if selectedNoteIndex ~= -1 then 
        reaper.MIDI_SetNote(activeTake, selectedNoteIndex, false, nil, nil, nil, nil, nil, nil, true)
        reaper.SetExtState("js_Toggle first note", "Index", tostring(selectedNoteIndex), false)
    end
    reaper.Undo_OnStateChange_Item(0, "Deselect first selected note", reaper.GetMediaItemTake_Item(activeTake))
end

For more intricate pattern-based selections, you can perhaps also try the script js_Select and deselect MIDI notes by step pattern.
juliansader is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.