

local cur_wnd = reaper.MIDIEditor_GetActive()
if not cur_wnd then
	reaper.ShowMessageBox( "This script needs an active MIDI editor.", "No MIDI editor found", 0)
	return -1
end

local cur_take = reaper.MIDIEditor_GetTake(cur_wnd)

-- Parse the scale string into something useful
-- Size = number of non-zero values in the scale
local __, key, __, scale_name = reaper.MIDI_GetScale(cur_take, 0, 0, "")
local __, scale_str = reaper.MIDIEditor_GetSetting_str(cur_wnd, "scale", "")
local __, size = string.gsub(scale_str, "[^0]", "")
	if key == 0 then
key22 =  " Doo"
elseif key == 1 then
key22 =  " DooDyiaz"
elseif key == 2 then
key22 =  " Ree"
elseif key == 3 then
key22 =  " ReeDyiaz"
elseif key == 4 then
key22 =  " keyee"
elseif key == 5 then
key22 =  " Faa"
elseif key == 6 then
key22 =  " FaaDyiaz"
elseif key == 7 then
key22 =  " Sol"
elseif key == 8 then
key22 =  " SolDyiaz"
elseif key == 9 then
key22 =  " Laa"
elseif key == 10 then
key22 =  " LaaDyiaz"
elseif key ==11  then
key22 =  " See"
elseif key == 12 then
key22 =  " Doo"
elseif key == 13 then
key22 =  " DooDyiaz"
elseif key == 14 then
key22 =  " Ree"
elseif key == 15 then
key22 =  " ReeDyiaz"
elseif key == 16 then
key22 =  " keyee"
elseif key == 17 then
key22 =  " Faa"
elseif key == 18 then
key22 =  " FaaDyiaz"
elseif key == 19 then
key22 =  " Sol"
elseif key == 20 then
key22 =  " SolDyiaz"
elseif key == 21 then
key22 =  " Laa"
elseif key == 22 then
key22 =  " LaaDyiaz"
elseif key ==23  then
key22 =  " See"

end

scale_arr = {[0] = 0}
for i = 1, size do
	scale_arr[i] = string.find(scale_str, "[^0]", scale_arr[i-1] + 1)
end

-- Adjust the values so that root = 0
for i = 1, size do
	scale_arr[i] = scale_arr[i] - 1
MM = ""
M= ""end
	for i = 1, #scale_arr  do

M =  scale_arr[i]+key

if M == 0 then
MM = MM.. " Doo"
elseif M == 1 then
MM = MM.. " DooDyiaz"
elseif M == 2 then
MM = MM.. " Ree"
elseif M == 3 then
MM = MM.. " ReeDyiaz"
elseif M == 4 then
MM = MM.. " Mee"
elseif M == 5 then
MM = MM.. " Faa"
elseif M == 6 then
MM = MM.. " FaaDyiaz"
elseif M == 7 then
MM = MM.. " Sol"
elseif M == 8 then
MM = MM.. " SolDyiaz"
elseif M == 9 then
MM = MM.. " Laa"
elseif M == 10 then
MM = MM.. " LaaDyiaz"
elseif M ==11  then
MM = MM.. " See"
elseif M == 12 then
MM = MM.. " Doo"
elseif M == 13 then
MM = MM.. " DooDyiaz"
elseif M == 14 then
MM = MM.. " Ree"
elseif M == 15 then
MM = MM.. " ReeDyiaz"
elseif M == 16 then
MM = MM.. " Mee"
elseif M == 17 then
MM = MM.. " Faa"
elseif M == 18 then
MM = MM.. " FaaDyiaz"
elseif M == 19 then
MM = MM.. " Sol"
elseif M == 20 then
MM = MM.. " SolDyiaz"
elseif M == 21 then
MM = MM.. " Laa"
elseif M == 22 then
MM = MM.. " LaaDyiaz"
elseif M ==23  then
MM = MM.. " See"

end
	end

reaper.osara_outputMessage("Current Scale is " .. key22 .. " " .. scale_name  .. MM)