local path = reaper.GetResourcePath() .. "\\REAPER.ini"
O1, octave = reaper.BR_Win32_GetPrivateProfileString("notation", "Octave", "nil", path)
if  (tonumber(octave) == 9) then
pp= 126
elseif  (tonumber(octave) == -2) then
pp= 66
elseif  (tonumber(octave) == -1) then
pp= 6
elseif  (tonumber(octave) == 0) then
pp= 18
elseif  (tonumber(octave) == 1) then
pp= 30
elseif  (tonumber(octave) == 2) then
pp= 42
elseif  (tonumber(octave) == 3) then
pp= 54
elseif  (tonumber(octave) == 4) then
pp= 66
elseif  (tonumber(octave) == 5) then
pp= 78
elseif  (tonumber(octave) == 6) then
pp= 90
elseif  (tonumber(octave) == 7) then
pp= 102
elseif  (tonumber(octave) == 8) then
pp= 114
else
pp= 66

end
reaper.osara_outputMessage(spk)
local path = reaper.GetResourcePath()
local NameFile ="Notes, Octaves and duration names"
local  pathfull =path .. "\\ini\\" .. NameFile .. ".ini"


    local me = reaper.MIDIEditor_GetActive()
    if not me then return end
    local tk =  reaper.MIDIEditor_GetTake( me )
take = tk
    if not tk then return end
editor_grid, _, _ = reaper.MIDI_GetGrid(tk) -- get MIDI Editor grid
local grid, _, note_length = reaper.MIDI_GetGrid(tk)
		cursor_pos = reaper.GetCursorPosition()

a1 = reaper.MIDI_GetPPQPosFromProjTime(tk,		cursor_pos)
b1 = reaper.TimeMap2_QNToTime(0,grid)
c1 = reaper.MIDI_GetPPQPosFromProjTime(tk,b1)
    reaper.MIDI_InsertNote( tk, true, false, a1,a1+c1, 1, pp, 100, true )











--    reaper.StuffMIDIMessage(0, 0x90+1, pp, 100)
X = "FaaDyiaz"
-- reaper.MIDI_SetItemExtents(MediaItem item, number startQN, number endQN)
--reaper.MIDIEditor_LastFocused_OnCommand(40048,0)
statt =  reaper.NamedCommandLookup("_OSARA_PREVNOTE")
reaper.MIDIEditor_LastFocused_OnCommand(statt,0)
    local _,notecnt,menaa,awadd = reaper.MIDI_CountEvts(tk);
    for i = 1,notecnt do;
        local retval, sel, mut, startppqpos, endppqpos, chan, pitch, vel = reaper.MIDI_GetNote(take,i-1);

        if (sel == true) and (mut == false) then
poss =endppqpos -  startppqpos
break
end
end

if  (poss >= 3456) and (poss <= 3840) then

oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "Rond", "nil", pathfull)
elseif (poss >= 1728) and (poss <= 1920) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "Blanch", "nil", pathfull)
elseif  (poss >= 864) and (poss <= 960) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "Noir", "nil", pathfull)
elseif (poss >= 432) and (poss <= 480) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "Qroch", "nil", pathfull)
elseif (poss >= 216) and (poss <= 240) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "DoppleQroch", "nil", pathfull)
elseif (poss >= 108) and (poss <= 120) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "TrippleQroch", "nil", pathfull)
elseif (poss >= 54) and  (poss >= 64) then
oo1, poss2 = reaper.BR_Win32_GetPrivateProfileString("names", "QuaTripple", "nil", pathfull)
else
poss2 =""

end

reaper.osara_outputMessage("")
reaper.MIDIEditor_LastFocused_OnCommand(40048,0)
reaper.osara_outputMessage(X.." " .. poss2 ..  " octave".. octave   )