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

Reply
 
Thread Tools Display Modes
Old 01-08-2016, 12:08 PM   #1
Mordi
Human being with feelings
 
Mordi's Avatar
 
Join Date: May 2014
Location: Norway
Posts: 982
Default [Lua-script] Chord-finder - Select notes in MIDI editor and see chord information

I'd like to share this script I made using Lua. It's quite useful for analyzing chords quickly in the MIDI editor. It generates a URL to this site and goes to it.

I've mapped it to a button in the toolbar of the MIDI editor.



It can take up to six notes.

Download here: .lua or .lua

Code:
-- This script will take any selected notes and generate a URL
-- that will show what chord the notes make, if any.
-- It uses the wonderful site "www.scales-chords.com" to
-- do this.
--
-- Made by Mordi, Jan 2016

-- Function for opening a URL
function OpenURL(url)
  local OS = reaper.GetOS()
  if OS == "OSX32" or OS == "OSX64" then
    os.execute('open "" "' .. url .. '"')
  else
    os.execute('start "" "' .. url .. '"')
  end
end

function Msg(str)
  reaper.ClearConsole();
  reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

-- Init note name-array (for use in URL)
noteNames = {"C", "C%23", "D", "D%23", "E", "F", "F%23", "G", "G%23", "A", "A%23", "B"}

-- Get HWND
hwnd = reaper.MIDIEditor_GetActive()

-- Get current take being edited in MIDI Editor
take = reaper.MIDIEditor_GetTake(hwnd)

-- Count all notes in take
retval, notes, ccs, sysex = reaper.MIDI_CountEvts(take)

-- Setup variables for number of selected notes
-- and an array to hold the pitch of selected notes
selNum = 0
selNotePitch = {}

-- Loop through every note in take, and get selected notes
-- and their pitch
for i = 0, notes-1 do
  retval, sel, muted, startppqposOut, endppqposOut, chan, pitch, vel = reaper.MIDI_GetNote(take, i)
  
  if sel == true then
    -- Don't add note if it already exists
    note_is_dupe = false
    for n = 0, selNum-1 do
      if (selNotePitch[n] % 12) == (pitch % 12) then
        note_is_dupe = true
      end
    end
    if not note_is_dupe then -- Add note to array
      selNotePitch[selNum] = pitch % 12
      selNum = selNum + 1
    end
  end
end

-- If more than 6 notes are selected, we can't generate a URL
if (selNum > 6) then
  Msg("Chord-finder: Whoops! Can't select more than 6 notes.")
else
  -- If no notes are selected we can't generate a URL
  if (selNum == 0) then
    Msg("Chord-finder: Whoops! No notes selected.")
  else
    -- Generate URL to chord-finder
    url = "http://www.scales-chords.com/findnotes_en.php?"
    for i = 0, selNum-1 do
      url = url .. "n" .. tostring(i + 1) .. "=" .. noteNames[selNotePitch[i] + 1] .. "&"
    end
    
    -- Set "do not allow additional notes"
    url = url .. "strict=1"
    
    -- Open url in browser
    OpenURL(url)
  end
end
Thanks to X-Raym / heda / cfillion / snooks / jrengmusic.

Last edited by Mordi; 01-10-2016 at 11:54 AM.
Mordi is offline   Reply With Quote
Old 01-08-2016, 12:51 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Interesting idea and implementation !
Thanks for sharing :P
(Maybe write it into a file and upload it on stash or github ? Will be more handy to download !)
X-Raym is offline   Reply With Quote
Old 01-10-2016, 11:55 AM   #3
Mordi
Human being with feelings
 
Mordi's Avatar
 
Join Date: May 2014
Location: Norway
Posts: 982
Default

Quote:
Originally Posted by X-Raym View Post
Interesting idea and implementation !
Thanks for sharing :P
(Maybe write it into a file and upload it on stash or github ? Will be more handy to download !)
There's a link to the file in the post. I added a stash-link as a mirror.
Mordi is offline   Reply With Quote
Old 01-10-2016, 02:23 PM   #4
Reno.thestraws
Human being with feelings
 
Reno.thestraws's Avatar
 
Join Date: Nov 2009
Location: Belgium
Posts: 10,474
Default

did you know that?

__________________
http://www.residenceemilia.com
Reno.thestraws is offline   Reply With Quote
Old 04-20-2016, 01:35 PM   #5
Mordi
Human being with feelings
 
Mordi's Avatar
 
Join Date: May 2014
Location: Norway
Posts: 982
Default

I think I've seen that before. I guess it's a plugin you can add to an FX-chain? Seems very useful. One thing that the chords-scales.com site does different from that plugin is that it shows how to finger the given chord on a guitar, which is quite useful.
Mordi is offline   Reply With Quote
Old 04-24-2016, 05:38 AM   #6
Mordi
Human being with feelings
 
Mordi's Avatar
 
Join Date: May 2014
Location: Norway
Posts: 982
Default

AHmusic did a youtube tip-video on this: https://www.youtube.com/watch?v=2u_uOWLNYKw

He also made a version that finds scales based on the selected notes!
Mordi is offline   Reply With Quote
Old 04-24-2016, 10:00 AM   #7
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,247
Default

Many thanks, highly appreciated !
vanhaze is offline   Reply With Quote
Old 04-25-2016, 09:31 AM   #8
X-Tech
Human being with feelings
 
Join Date: Apr 2015
Posts: 589
Default

This script could be usefull for me very much if instead of run WWW - will run "SCALE FINDER" in Reaper and send instantly notes into "SCALE FINDER" and display window of "SCALE FINDER" Usefull for offline situations too and more fast solution. I'm not convinient to use WWW at same time with softwares like Reaper during more cpu advanced more massive oprations. Script which after run automatically rename selected item as musical notes which contain example "c,d,#f,a" would be super usefull too. Another usefull script would be if selected item will copy notes into scale finder and run scale finder and display in momment instead of select notes in midi editor too.
__________________
nonononononono

Last edited by X-Tech; 04-25-2016 at 09:38 AM.
X-Tech 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 06:44 PM.


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