|
|
|
07-09-2020, 04:59 PM
|
#1
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Build scales depending on region name[SOLVED]thanks MusoBob
Hello, maybe my last script request
I have modified and reduced(clarity) a script from MusoBob to generate scales depending on the region.
What I'm missing is:
1. If the number of items exceeds the number of scale tones within a region, the scale should then go on.
Example A(Cmaj7): 0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26 .....
Example B(C pentatonic): 0,2,4,7,9,12,14,16,19,21,24,26 .....
2.If the selected items are in 2 different regions, the appropriate scale should start again in the respective region.
many thanks
Code:
-- Display a message in the console for debugging
function Msg(variable)
reaper.ShowConsoleMsg(tostring(variable).."\n")
end
function select_region()
local time = reaper.GetCursorPosition()
local markeridxOut, regionidx = reaper.GetLastMarkerAndCurRegion(0, time)
local retval, isrgnOut, posOut, rgnendOut, nameOut, markrgnindexnumberOut, colorOut = reaper.EnumProjectMarkers3(0, regionidx)
local start_time, end_time = reaper.GetSet_LoopTimeRange(true, true, posOut, rgnendOut, 0)
end
function get_chord_notes(chord_region)
retval, isrgn, region_pos, region_end, region_name, region_index, region_color = reaper.EnumProjectMarkers3( 0, chord_region)
if string.match( region_name, "@.*") then next_region() end -- skip region marked @ ignore
if string.find(region_name, "/") then
root, chord, slash = string.match(region_name, "(%w[#b]?)(.*)(/%a[#b]?)$")
else
root, chord = string.match(region_name, "(%w[#b]?)(.*)$") slashnote = 0 slash = ""
end
if not chord or #chord == 0 then chord = "Maj" end
if not slash then slash = "" end
note1 = 0
-- 60 = C3
if root == "C" then note1 = 0
elseif root == "C#" then note1 = 1
elseif root == "Db" then note1 = 1
elseif root == "D" then note1 = 2
elseif root == "D#" then note1 = 3
elseif root == "Eb" then note1 = 3
elseif root == "E" then note1 = 4
elseif root == "F" then note1 = 5
elseif root == "F#" then note1 = 6
elseif root == "Gb" then note1 = 6
elseif root == "G" then note1 = 7
elseif root == "G#" then note1 = 8
elseif root == "Ab" then note1 = 8
elseif root == "A" then note1 = 9
elseif root == "A#" then note1 = 10
elseif root == "Bb" then note1 = 10
elseif root == "B" then note1 = 11
if not root then end
end
if string.find(",Maj,M,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=11 note8=12 end
if string.find(",m,min,", ","..chord..",", 1, true) then note2=2 note3=3 note4=5 note5=7 note6=9 note7=11 note8=12 end
if string.find(",7,dom,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=10 note8=12 end
if string.find(",m7,min7,-7,", ","..chord..",", 1, true) then note2=2 note3=3 note4=5 note5=7 note6=9 note7=10 note8=12 end
if string.find(",Maj7,maj7,Maj7,M7,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=11 note8=12 end
end
--MAIN---------------------------------------------------------------
function main()
commandID2 = reaper.NamedCommandLookup("_SWS_SELTRKWITEM")
reaper.Main_OnCommand(commandID2, 0) -- SWS: Select only track(s) with selected item(s) _SWS_SELTRKWITEM
items = reaper.CountMediaItems(0)
sel_tracks = reaper.CountSelectedMediaItems(0)
for i = 0, sel_tracks -1 do
track = reaper.GetSelectedMediaItem( 0,(sel_tracks-1)-i)
track_number = reaper.GetMediaItemInfo_Value(track, "IP_ITEMNUMBER" )
retval, num_markers, num_regions = reaper.CountProjectMarkers(0)
for r = 0, num_regions -1 do -- regions loop start
retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers3( 0, r )
for i = 0, items -1 do -- items loop start
media_item = reaper.GetMediaItem( 0, i )
selected_item = reaper.IsMediaItemSelected(media_item)
if selected_item then
current_item = reaper.GetMediaItem( 0, i )
item_start = reaper.GetMediaItemInfo_Value( current_item, "D_POSITION")
--Does item start within region
if item_start >= pos and item_start < rgnend then
--Msg("r "..r)
--Msg("markrgnindexnumber ".. markrgnindexnumber)
get_chord_notes(r) -- get the chord notes for current region
item0 = reaper.GetSelectedMediaItem(0, 0 )
take0 = reaper.GetActiveTake(item0)
reaper.SetMediaItemTakeInfo_Value(take0, 'D_PITCH',note1)
reaper.UpdateItemInProject(item0)
item1 = reaper.GetSelectedMediaItem(0, 1 )
take1 = reaper.GetActiveTake(item1)
reaper.SetMediaItemTakeInfo_Value(take1, 'D_PITCH',note1+note2)
reaper.UpdateItemInProject(item1)
item2 = reaper.GetSelectedMediaItem(0, 2 )
take2 = reaper.GetActiveTake(item2)
reaper.SetMediaItemTakeInfo_Value(take2, 'D_PITCH',note1+note3)
reaper.UpdateItemInProject(item2)
item3 = reaper.GetSelectedMediaItem(0, 3 )
take3 = reaper.GetActiveTake(item3)
reaper.SetMediaItemTakeInfo_Value(take3, 'D_PITCH',note1+note4)
reaper.UpdateItemInProject(item3)
item4 = reaper.GetSelectedMediaItem(0, 4 )
take4 = reaper.GetActiveTake(item4)
reaper.SetMediaItemTakeInfo_Value(take4, 'D_PITCH',note1+note5)
reaper.UpdateItemInProject(item4)
item5 = reaper.GetSelectedMediaItem(0, 5 )
take5 = reaper.GetActiveTake(item5)
reaper.SetMediaItemTakeInfo_Value(take5, 'D_PITCH',note1+note6)
reaper.UpdateItemInProject(item5)
item6 = reaper.GetSelectedMediaItem(0, 6 )
take6 = reaper.GetActiveTake(item6)
reaper.SetMediaItemTakeInfo_Value(take6, 'D_PITCH',note1+note7)
reaper.UpdateItemInProject(item6)
item7 = reaper.GetSelectedMediaItem(0, 7 )
take7 = reaper.GetActiveTake(item7)
reaper.SetMediaItemTakeInfo_Value(take7, 'D_PITCH',note1+note8)
reaper.UpdateItemInProject(item7)
end
end
end -- items loop end
end -- regions loop end
end
end
main()
reaper.Main_OnCommand(40297,0) -- unselect all tracks
::skip::
Last edited by Dragonetti; 07-24-2020 at 06:41 AM.
|
|
|
07-10-2020, 03:20 AM
|
#2
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Are you just doing one track at a time ?
and the scale keeps going up in octaves ?
so if there are 36 items on the one track in the chord region it will just keep going up ?
|
|
|
07-10-2020, 06:20 AM
|
#3
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Hi MusoBob
thank you for helping here
1. if several tracks go at the same time would be awesome. of course only selected items.
2. yes, even with 36 items with the octaves to the "infinite"(48)
another additional function. Is that possible?(two extra scripts)
3. The whole scale is shifted one note, I'm going to make a GIF.
you quickly created a scale with the appropriate thirds
Last edited by Dragonetti; 07-10-2020 at 02:47 PM.
|
|
|
07-14-2020, 10:04 PM
|
#4
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
|
|
|
07-15-2020, 03:11 AM
|
#5
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Thank you very much MusoBob.
So far it works quite well.
I showed 4 small bugs in the GIF.
I can no longer upload anything to reaper stash.
No idea why.
The whole script should only work with one track, this is clearer.
I once selected items from 2 tracks, then reaper crashes.
https://imgur.com/a/ha1wcyl
|
|
|
07-15-2020, 04:17 AM
|
#6
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
You were using the chord script but I think there would be an easier way of doing it, I will look at it tomorrow.
|
|
|
07-17-2020, 12:52 PM
|
#8
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
I am currently on the road and can unfortunately only test the script on Sunday evening, thank you in advance
|
|
|
07-19-2020, 12:54 PM
|
#9
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
@MusoBob thank you very much, everything works fine except for one case,
if the item selection has gaps.
|
|
|
07-19-2020, 08:13 PM
|
#10
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
|
|
|
07-20-2020, 03:40 AM
|
#11
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
madness -- works great
thank you again.
I hope it's not outrageous to ask for another feature.
Is it possible to move selected items to a next or previous position on the corresponding scale.
gif example C major
Arrow to the right:
if selected item pitch == note4 (+5.00) then
new pitch is note5 (+7.00)
Left arrow:
if selected item pitch == note4 (+5.00) then
new pitch is note3 (+4.00)
--------
You could quickly generate a third, fifth or any interval for a phrase.
I think I don't need more features anymore.
Thank you
Last edited by Dragonetti; 07-20-2020 at 09:13 AM.
|
|
|
07-21-2020, 02:50 PM
|
#12
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
It can be done but there would be a lot of variables unless I can think of a simpler way ?
Code:
for i = 0, reg_item_count do -- set items loop start
retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers3( 0, region_num )
sel_item = reaper.GetSelectedMediaItem(0, i )
if not sel_item then break end
item_start = reaper.GetMediaItemInfo_Value( sel_item, "D_POSITION")
if item_start >= rgnend then break end
sel_take = reaper.GetActiveTake(sel_item)
item_pitch = reaper.GetMediaItemTakeInfo_Value(sel_take, 'D_PITCH')
--CMaj
if string.find(",Maj,M,", ","..chord..",", 1, true) and note1 == 0 then
if item_pitch == 0 then new_pitch = note2
if item_pitch == 2 then new_pitch = note3
if item_pitch == 4 then new_pitch = note4
if item_pitch == 5 then new_pitch = note5
~~~~~
~~~~~
if item_pitch == 12 then new_pitch = 12+note2
if item_pitch == 14 then new_pitch = 12+note3
if item_pitch == 16 then new_pitch = 12+note4
if item_pitch == 17 then new_pitch = 12+note5
~~~~~
~~~~~
end
reaper.SetMediaItemTakeInfo_Value(take0, 'D_PITCH',new_pitch)
reaper.UpdateItemInProject(sel_item)
end -- items loop end
|
|
|
07-22-2020, 09:01 AM
|
#13
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
maybe you can somehow integrate "note 1" like this?
I only have 7 scales so far
Code:
--CMaj
if string.find(",Maj,M,", ","..chord..",", 1, true) then
if item_pitch-note1 == 0 then new_pitch = note2+note1
if item_pitch-note1 == 2 then new_pitch = note3+note1
if item_pitch-note1 == 4 then new_pitch = note4+note1
if item_pitch-note1 == 5 then new_pitch = note5+note1
if item_pitch-note1 == 7 then new_pitch = note6+note1
if item_pitch-note1 == 9 then new_pitch = note7+note1
if item_pitch-note1 == 11 then new_pitch = note1+note1+12
if item_pitch-note1 == 12 then new_pitch = note2+note1+12
if item_pitch-note1 == 14 then new_pitch = note3+note1+12
if item_pitch-note1 == 16 then new_pitch = note4+note1+12
if item_pitch-note1 == 17 then new_pitch = note5+note1+12
if item_pitch-note1 == 19 then new_pitch = note6+note1+12
if item_pitch-note1 == 21 then new_pitch = note7+note1+12
if item_pitch-note1 == 23 then new_pitch = note1+note1+24
if item_pitch-note1 == 24 then new_pitch = note2+note1+24
if item_pitch-note1 == 26 then new_pitch = note3+note1+24
if item_pitch-note1 == 28 then new_pitch = note4+note1+24
if item_pitch-note1 == 29 then new_pitch = note5+note1+24
if item_pitch-note1 == 31 then new_pitch = note6+note1+24
if item_pitch-note1 == 33 then new_pitch = note7+note1+24
if item_pitch-note1 == 35 then new_pitch = note1+note1+36
if item_pitch-note1 == 36 then new_pitch = note2+note1+36
if item_pitch-note1 == 38 then new_pitch = note3+note1+36
if item_pitch-note1 == 40 then new_pitch = note4+note1+36
if item_pitch-note1 == 41 then new_pitch = note5+note1+36
if item_pitch-note1 == 43 then new_pitch = note6+note1+36
if item_pitch-note1 == 45 then new_pitch = note7+note1+36
if item_pitch-note1 == 47 then new_pitch = note1+note1+48
if item_pitch-note1 == 48 then new_pitch = note2+note1+48
|
|
|
07-22-2020, 01:09 PM
|
#14
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
You should be able to have a scale table
Maj = {0,2,4,5,7,9,11,14,16,17,......}
then just loop the one line
if item_pitch-note1 == Maj[i] then new_pitch = Maj[i+1]
|
|
|
07-22-2020, 02:56 PM
|
#15
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Can I take minus values there?
Code:
Maj = {-24,-22,-20,-19,-17,-15,-13,-12,-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48}
Last edited by Dragonetti; 07-22-2020 at 03:04 PM.
|
|
|
07-22-2020, 10:08 PM
|
#16
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
This should take the note up to the next scale note
if item_pitch-note1 == Maj[i] then new_pitch = Maj[i+1]
This should take the note down to the next scale note
if item_pitch-note1 == Maj[i] then new_pitch = Maj[i-1]
If you want to take the scale notes down 2 octaves
Code:
Maj = {-24,-22,-20,-19,-17,-15,-13,-12,-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48}
So in your table position Maj[15] will = 0 in the scale table
if item_pitch-note1 == Maj[15] *(pitch 0)* then new_pitch = Maj[15-1] *(14) = pitch -1*
if item_pitch-note1 == Maj[5] *(pitch -17)* then new_pitch = Maj[5-1] *(4) = pitch -19*
So you loop through each selected item to check what pitch it is then set the new pitch
for i = 1, 43 do
I think that's right ? I'll look more at it later.
|
|
|
07-23-2020, 03:06 AM
|
#17
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
all right
table position Ionian[29] will = 0 in the scale table
These scales should be enough for now.
Code:
Ionian = {-48,-46,-44,-43,-41,-39,-37,-36,-34,-32,-31,-29,-27,-25,-24,-22,-20,-19,-17,-15,-13,-12,-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12,14,16,17,19,21,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48}
Dorian = {-48,-46,-45,-43,-41,-39,-38,-36,-34,-33,-31,-29,-27,-26,-24,-22,-21,-19,-17,-15,-14,-12,-10,-9,-7,-5,-3,-2,0,2,3,5,7,9,10,12,14,15,17,19,21,22,24,26,27,29,31,33,34,36,38,39,41,43,45,46,48}
Phrygian = {-48,-47,-45,-43,-41,-40,-38,-36,-35,-33,-31,-29,-28,-26,-24,-23,-21,-19,-17,-16,-14,-12,-11,-9,-7,-5,-4,-2,0,1,3,5,7,8,10,12,13,15,17,19,20,22,24,25,27,29,31,32,34,36,37,39,41,43,44,46,48}
Lydian = {-48,-46,-44,-42,-41,-39,-37,-36,-34,-32,-30,-29,-27,-25,-24,-22,-20,-18,-17,-15,-13,-12,-10,-8,-6,-5,-3,-1,0,2,4,6,7,9,11,12,14,16,18,19,21,23,24,26,28,30,31,33,35,36,38,40,42,43,45,47,48}
Mixolydian = {-48,-46,-44,-43,-41,-39,-38,-36,-34,-32,-31,-29,-27,-26,-24,-22,-20,-19,-17,-15,-14,-12,-10,-8,-7,-5,-3,-2,0,2,4,5,7,9,10,12,14,16,17,19,21,22,24,26,28,29,31,33,34,36,38,40,41,43,45,46,48}
Aeolian = {-48,-46,-45,-43,-41,-40,-38,-36,-34,-33,-31,-29,-28,-26,-24,-22,-21,-19,-17,-16,-14,-12,-10,-9,-7,-5,-4,-2,0,2,3,5,7,8,10,12,14,15,17,19,20,22,24,26,27,29,31,32,34,36,38,39,41,43,44,46,48}
Locrian = {-48,-47,-45,-43,-42,-40,-38,-36,-35,-33,-31,-30,-28,-26,-24,-23,-21,-19,-18,-16,-14,-12,-11,-9,-7,-6,-4,-2,0,1,3,5,6,8,10,12,13,15,17,18,21,22,24,25,27,29,30,32,34,36,37,39,41,42,44,46,48}
Code:
if string.find(",Maj7,maj7,Maj7,Maj,M,M7,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=11 end -- Ionian
if string.find(",m7,min7,-7,", ","..chord..",", 1, true) then note2=2 note3=3 note4=5 note5=7 note6=9 note7=10 end -- Dorian
if string.find(",m7b9,", ","..chord..",", 1, true) then note2=1 note3=3 note4=5 note5=7 note6=8 note7=10 end -- Phrygian
if string.find(",maj7#11,maj#11,", ","..chord..",", 1, true) then note2=2 note3=4 note4=6 note5=7 note6=9 note7=11 end -- Lydian
if string.find(",7,dom,9,13,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=10 end -- Mixolydian
if string.find(",m,min,", ","..chord..",", 1, true) then note2=2 note3=3 note4=5 note5=7 note6=8 note7=10 end -- Aeolian
if string.find(",m7b5b9,m7-5-9,", ","..chord..",", 1, true) then note2=1 note3=3 note4=5 note5=6 note6=8 note7=10 end -- Locrian
|
|
|
07-23-2020, 04:22 AM
|
#18
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
You can add "scale = Ionian"
Code:
if string.find(",Maj7,maj7,Maj7,Maj,M,M7,", ","..chord..",", 1, true) then note2=2 note3=4 note4=5 note5=7 note6=9 note7=11 scale = Ionian end -- Ionian
then use
Are you making the rest of the script or did you need me to do it ?
|
|
|
07-23-2020, 06:06 AM
|
#19
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Unfortunately I'm not far enough in scripting.
Maybe you can help me again.
Thanks
|
|
|
07-23-2020, 06:17 PM
|
#20
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
|
|
|
07-24-2020, 06:40 AM
|
#21
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
|
|
|
08-02-2020, 04:06 AM
|
#23
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
I don't know how to install them and what they can actually do.
For me at the moment only audio items manipulation are interesting
|
|
|
08-02-2020, 05:31 AM
|
#24
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
@MusoBob
how do I get this "if" integrated:
if a pitch value does not belong to the scale, it should be increased by 1
Code:
if item_pitch-note1 ~= scale[s] then
new_pitch = item_pitch+1 --increase existing pitch value by 1
reaper.SetMediaItemTakeInfo_Value(sel_take, 'D_PITCH',new_pitch)
reaper.UpdateItemInProject(sel_item)
|
|
|
08-02-2020, 12:32 PM
|
#25
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Highlight the same section and paste this over and see if it works.
This is for set selected items to next scale note.lua
Code:
get_chord_notes(item_region)
match=0
for s = 1, 57 do
if not sel_item then break end
sel_take = reaper.GetActiveTake(sel_item)
item_pitch = reaper.GetMediaItemTakeInfo_Value(sel_take, 'D_PITCH')
if item_pitch-note1 == scale[s] then
match=1
new_pitch = scale[s+1]+note1 --new_pitch = scale[s+1]
reaper.SetMediaItemTakeInfo_Value(sel_take, 'D_PITCH',new_pitch)
reaper.UpdateItemInProject(sel_item)
break
end
end
if match==0 then
new_pitch = item_pitch+1
reaper.SetMediaItemTakeInfo_Value(sel_take, 'D_PITCH',new_pitch)
reaper.UpdateItemInProject(sel_item)
end
end
::finish::
end
|
|
|
08-02-2020, 03:27 PM
|
#26
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
somehow nothing happens
|
|
|
08-02-2020, 03:48 PM
|
#27
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
This is what I get:
|
|
|
08-02-2020, 03:57 PM
|
#28
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
I didn't keep the "main ()".
Now everything works.
Thank you
|
|
|
08-02-2020, 05:05 PM
|
#29
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Cool, I updated the scripts in the links.
|
|
|
08-02-2020, 05:15 PM
|
#30
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
with previouse I would use -1, then you can transpose better
|
|
|
08-02-2020, 05:41 PM
|
#31
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Yes that's what I have
Code:
if match==0 then
new_pitch = item_pitch-1
|
|
|
08-10-2020, 11:25 AM
|
#32
|
Human being with feelings
Join Date: Feb 2017
Location: Kiel
Posts: 974
|
Last edited by Dragonetti; 07-02-2021 at 07:43 AM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:23 AM.
|