-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release Find Overlapping Notes v0.5 (Initial Release) (#1468)
- Loading branch information
1 parent
99c9052
commit bdc7579
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--[[ | ||
@description Find overlapping notes in project / active take | ||
@version 0.5 | ||
@author Ben 'Talagan' Babut | ||
@donation https://www.paypal.com/donate/?business=3YEZMY9D6U8NC&no_recurring=1¤cy_code=EUR | ||
@license MIT | ||
@changelog | ||
- Initial Release | ||
@metapackage | ||
@provides | ||
[main=main,midi_editor] talagan_Find overlapping notes/actions/talagan_Find overlapping notes in active take and select them.lua > . | ||
[main=main,midi_editor] talagan_Find overlapping notes/actions/talagan_Find overlapping notes in project and report items.lua > . | ||
[nomain] talagan_Find overlapping notes/overlapping_lib.lua | ||
@about | ||
Simple scripts to detect overlapping notes. Currently comes in two actions : | ||
- One to search in the whole project, that will give you a report per track+item if some overlapping notes were found | ||
- One to launch with a MIDI Editor open, it will select problematic notes if found | ||
--]] |
14 changes: 14 additions & 0 deletions
14
...erlapping notes/actions/talagan_Find overlapping notes in active take and select them.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- @noindex | ||
-- @author Ben 'Talagan' Babut | ||
-- @license MIT | ||
-- @description Secondary action for the "Find overlapping notes" package | ||
|
||
package.path = debug.getinfo(1, "S").source:match [[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path | ||
|
||
local ok, overlib = pcall(require, "talagan_Find overlapping notes/overlapping_lib") | ||
if not ok then | ||
reaper.MB("This script is not well installed. Please reinstall it through Reapack", "Ouch!", 0); | ||
return | ||
end | ||
|
||
overlib.findOverlappingNotesInCurrentMETake() |
15 changes: 15 additions & 0 deletions
15
... overlapping notes/actions/talagan_Find overlapping notes in project and report items.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- @noindex | ||
-- @author Ben 'Talagan' Babut | ||
-- @license MIT | ||
-- @description Secondary action for the "Find overlapping notes" package | ||
|
||
package.path = debug.getinfo(1, "S").source:match [[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path | ||
|
||
local ok, overlib = pcall(require, "talagan_Find overlapping notes/overlapping_lib") | ||
if not ok then | ||
reaper.MB("This script is not well installed. Please reinstall it through Reapack", "Ouch!", 0); | ||
return | ||
end | ||
|
||
overlib.findOverlappinNotesInAlltakes() | ||
|
86 changes: 86 additions & 0 deletions
86
MIDI Editor/talagan_Find overlapping notes/overlapping_lib.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
-- @noindex | ||
-- @author Ben 'Talagan' Babut | ||
-- @license MIT | ||
-- @description Shared code for "Find overlapping notes" actions | ||
|
||
local function findOverlappingNotesInTake(take, should_select) | ||
local lookup = {} | ||
|
||
local errocount = 0 | ||
|
||
local _, nc = reaper.MIDI_CountEvts(take); | ||
for i=0, nc-1 do | ||
ret, sel, muted, sppq, eppq, chan, pitch, vel = reaper.MIDI_GetNote(take, i); | ||
if not lookup[chan] then lookup[chan] = {} end | ||
|
||
-- Deselect all notes | ||
if should_select then | ||
reaper.MIDI_SetNote(take, i, false, nil,nil,nil,nil,nil,nil,false) | ||
end | ||
|
||
local existing = lookup[chan][pitch] | ||
if not existing then | ||
else | ||
if existing.ep > sppq then | ||
errocount = errocount + 1; | ||
if should_select then | ||
reaper.MIDI_SetNote(take, existing.idx, true, nil,nil,nil,nil,nil,nil,false) | ||
end | ||
end | ||
end | ||
|
||
lookup[chan][pitch] = { sp = sppq, ep = eppq, idx = i } | ||
end | ||
|
||
return errocount | ||
end | ||
|
||
local function findOverlappingNotesInCurrentMETake() | ||
local me = reaper.MIDIEditor_GetActive(); | ||
if not me then return end | ||
|
||
local take = reaper.MIDIEditor_GetTake(me); | ||
if not take then return end | ||
|
||
local err_count = findOverlappingNotesInTake(take, true) | ||
|
||
if err_count > 0 then | ||
reaper.MB(err_count .. " overlapping notes found ! "," Ouch!",0) | ||
else | ||
reaper.MB("No overlapping notes in current take !", "Cool!", 0) | ||
end | ||
end | ||
|
||
local function findOverlappinNotesInAlltakes() | ||
local report = '' | ||
local ic = reaper.CountMediaItems(); | ||
local tec = 0; | ||
|
||
for i=0, ic-1 do | ||
local item = reaper.GetMediaItem(0,i); | ||
local tc = reaper.CountTakes(item); | ||
|
||
for ti=0, tc-1 do | ||
local take = reaper.GetMediaItemTake(item,ti); | ||
local track = reaper.GetMediaItemTrack(item); | ||
local ec = findOverlappingNotesInTake(take, false); | ||
local _,trname = reaper.GetTrackName(track) | ||
if ec > 0 then | ||
tec = tec + ec; | ||
report = report .. trname .. " : " .. reaper.GetTakeName(take) .. " : " .. ec .. "\n" | ||
end | ||
end | ||
end | ||
|
||
if not (report == '') then | ||
reaper.MB(report, "Found " .. tec .. " overlapping notes !! \n", 0) | ||
else | ||
reaper.MB("No overlapping notes found in project !", "Cool!", 0) | ||
end | ||
end | ||
|
||
return { | ||
findOverlappingNotesInTake = findOverlappingNotesInTake, | ||
findOverlappinNotesInAlltakes = findOverlappinNotesInAlltakes, | ||
findOverlappingNotesInCurrentMETake = findOverlappingNotesInCurrentMETake | ||
} |