Old 06-21-2020, 04:41 AM   #1
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default swapp_pitches (video) thanks jkooks

Hi
Has anyone an idea how the easiest way to program it.
Swap the pitch settings of the selected
Items depending on their tracks.
For example 4 tracks: counted from the bottom

1to4(+12), 2to1, 3to2, 4to3

Thank you
********************************

Here you can see the result
https://www.youtube.com/watch?v=an_iVttAVv4


************************************************** ***********


Last edited by Dragonetti; 06-03-2021 at 04:26 PM.
Dragonetti is offline   Reply With Quote
Old 06-21-2020, 02:26 PM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

https://mespotin.uber.space/Ultrasch...TakeInfo_Value

and

https://mespotin.uber.space/Ultrasch...TakeInfo_Value

Just swap the attributes

D_PITCH
B_PPITCH
I_PITCHMODE

around from one item to the next.
This should work.

Best is, put the old values into tables before setting them by using the values you stored into the table.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 06-22-2020, 12:32 PM   #3
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Thanks Mespotine
but
--I can not do this--
do i need the individual tracks?
and then the selected items on the respective track
Code:
reaper.Main_OnCommand(40297, 0) --Track: Unselect all tracks 40297
 commandID2 = reaper.NamedCommandLookup("_SWS_SELTRKWITEM")
  reaper.Main_OnCommand(commandID2, 0) -- SWS: Select only track(s) with selected item(s) _SWS_SELTRKWITEM
  
  sel_tracks = reaper.CountSelectedTracks(0)
there could be different numbers of items on a track
Dragonetti is offline   Reply With Quote
Old 06-22-2020, 12:36 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,629
Default

You mean, you don't know how to swap it, when, let's say, track 1 3 and 4 have one item but track 2 has two items in the same spot?
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 06-22-2020, 01:23 PM   #5
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Unfortunately I still haven't understood the principle of the nested for loop . Can you give a tip again?

Last edited by Dragonetti; 06-22-2020 at 01:32 PM.
Dragonetti is offline   Reply With Quote
Old 06-22-2020, 10:31 PM   #6
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Would you want it to change all the items on the selected track(s) or only the selected items? And are the pitches potentially different from other items on the same track, or are they all the same pitch if they are on the same track?
jkooks is offline   Reply With Quote
Old 06-23-2020, 05:50 AM   #7
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Thanks jkooks, that you want to help me.

Only selected items should be processed.
The selected items on a track have the same pitch.
The script should also deal with such a rhythm chaos (gif).


Dragonetti is offline   Reply With Quote
Old 06-24-2020, 10:19 AM   #8
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Alright, so in this example the top ones would become 12, the next level ones would be 15, then 12, then 10, then 7, then 3?
jkooks is offline   Reply With Quote
Old 06-24-2020, 12:22 PM   #9
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Oops.
It's more complicated than I thought.
It is best to octave the lowest note.
If the octave already exists,
lowest tone on octave of the 2nd tone,
if this already exists lowest tone
on octave of the 3rd tone.

In this case 12 is already there 15 is already there, then the lowest note must be 19 (7 + 12)

In any case, the next note must always be higher. 3,7,10,12,15,19.



It can also happen that the bottom note is shifted between 2 notes
0,4,7,10,13 then becomes
4,7,10,12,13

Last edited by Dragonetti; 06-24-2020 at 12:40 PM.
Dragonetti is offline   Reply With Quote
Old 06-25-2020, 02:39 PM   #10
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Hmm, alright. And notes on the same track can have different pitches? Or should all notes on the same track have the same pitch after the script is run?
jkooks is offline   Reply With Quote
Old 06-25-2020, 03:22 PM   #11
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

the selected items of the respective track have the same pitch even after executing the script.

You would actually have to write a second script, in which the voicing is shifted downwards.
I would probably get that from the first one myself.
Dragonetti is offline   Reply With Quote
Old 06-25-2020, 10:26 PM   #12
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Alright, try this out and hopefully everything works!
Attached Files
File Type: lua Cycle Pitches Down and Octave Up.lua (3.2 KB, 123 views)
jkooks is offline   Reply With Quote
Old 06-26-2020, 02:47 AM   #13
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

It’s like Christmas.
Thank you very much jkooks
Works great.
I try to turn it around so that the voicing goes down.
Dragonetti is offline   Reply With Quote
Old 06-26-2020, 10:30 AM   #14
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Alright, glad it works! And it shouldn't be too difficult to adjust it, but let me know if you need any clarification on the code.
jkooks is offline   Reply With Quote
Old 07-08-2020, 02:28 PM   #15
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

@jkooks
I thought I could do it myself.
But, maybe it would be better if you could create the script.

Thanks
Dragonetti is offline   Reply With Quote
Old 07-08-2020, 08:36 PM   #16
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Quote:
Originally Posted by Dragonetti View Post
@jkooks
I thought I could do it myself.
But, maybe it would be better if you could create the script.

Thanks

No worries! I modified the other script to cycle the pitches up and lower the pitch at the top down by an octave. Let me know if that works for you or not.
Attached Files
File Type: lua Cycle Pitches Up and Octave Down.lua (3.2 KB, 114 views)
jkooks is offline   Reply With Quote
Old 07-09-2020, 08:47 AM   #17
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

What have I done to deserve this.
Works just right, thanks.
Hopefully now I have my scripts all together.
But there is still something missing.
Dragonetti is offline   Reply With Quote
Old 07-09-2020, 11:13 AM   #18
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Glad it works! Apparently all it took was changing a few variables and subtracting 12 rather than adding 12, and I am glad I could help!
jkooks is offline   Reply With Quote
Old 09-18-2020, 01:32 AM   #19
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Hi jkooks

it is possible to improve your script so that it takes individual chords into account.
Currently the script converts all chords to the chord in the first place.
The result should be like selecting them one by one.
Thank you very much
Dragonetti is offline   Reply With Quote
Old 09-26-2020, 02:45 AM   #20
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Hi
Is it possible to extend the code so that the code of the selected items treats all items with the same starting position(chords) separately?
The same request as in the previous post.
Thanks
Code:
--This script swaps the pitches from takes down tracks (and to the first track if it is the last track)

reaper.Undo_BeginBlock()


--sorts whatever array that is passed to it in descending order (highest to lowest)
function bubbleSort(A)
    local n = #A
    local swapped = false
    
    repeat
      swapped = false
      
      for i = 1, n do
          if A[i-1] < A[i] then
            A[i-1] , A[i] = A[i] , A[i-1]
            swapped = true
          end
      end
    until not swapped

    return A
end


--main code

itemCount = reaper.CountSelectedMediaItems()

tracks = {}
tempTakes = {}
pitches = {}

counter = 0
takesCounter = 0

prevTrack = ""

--grabs all of the media items, tracks and pitches
for i = 0, itemCount - 1 do
  local thisItem = reaper.GetSelectedMediaItem(0, i)
  local thisTake = reaper.GetActiveTake(thisItem)

  --as long as the item has a take (i.e. isn't a note, etc)
  if thisTake ~= nil then
    local thisTrack = reaper.GetMediaItem_Track(thisItem)

    --records the new track info if the track is different from the last one - makes a new spot in the array for it
    if prevTrack ~= thisTrack then

      tracks[counter] = {}
      pitches[counter] = reaper.GetMediaItemTakeInfo_Value(thisTake, "D_PITCH")

      --as long as it isn't the first iteration in the loop it records the takes for the previous track and saves them to that track
      if i > 0 then
        tracks[counter - 1].takes = tempTakes
    
        --reinitializes the take info to go through and record the next tracks info
        takesCounter = 0
        tempTakes = {}
      end

      counter = counter + 1 --increases track count for next array spt
      prevTrack = thisTrack --sets the previous track to know if tracks have changed or not
    end
    
    --records take info so it can pass it to the track
    tempTakes[takesCounter] = thisTake
    takesCounter = takesCounter + 1
  
    --if it is the last iteration in the loop it will pass the last array of takes to their respective track spot
    if i == itemCount - 1 then
      tracks[counter - 1].takes = tempTakes
    end
  end
end



pitches = bubbleSort(pitches) --sorts all of the pitches so highest is first

highestPitch = pitches[#pitches] + 12 --sets the highest pitch as an octave higher than whatever the lowest pitch is


--loops through all of the pitches to make sure the lowest pitch raised by an octave isn't already in the list of pitches
  --if it is, it will raise the next lowest pitch by an octave and check - repeating this step until it breaks out
isEqual = false
nextIndex = #pitches

while true do
  for i = nextIndex - 1, 0, -1 do
    if pitches[i] == highestPitch then
      isEqual = true
      break
    end
  end

  if isEqual == true then
    nextIndex = nextIndex - 1
    highestPitch = pitches[nextIndex] + 12

    isEqual = false
  else
    break
  end

  if nextIndex < 0 then break end --check to break out of the while in case something goes wrong and everything is equal
end



pitches[#pitches] = highestPitch --sets the lowest pitch to whatever the highest pitch became


pitches = bubbleSort(pitches) --resorts all of the pitches so highest is first


for i = 0, #tracks do

  local tempTakes = tracks[i].takes
  local thisPitch = pitches[i]

  for j = 0, #tempTakes do
    reaper.SetMediaItemTakeInfo_Value(tempTakes[j], "D_PITCH", thisPitch)
  end
end

reaper.UpdateArrange()

reaper.Undo_EndBlock("Swap Pitches", -1)

Last edited by Dragonetti; 09-26-2020 at 03:16 AM.
Dragonetti is offline   Reply With Quote
Old 04-14-2021, 09:04 AM   #21
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Hello scripters
can someone try that.
I can not do it.
The script would have to invert each chord individually.
If I want to swap different inversions at once,
only one chord is created for all chords.
https://www.youtube.com/watch?v=7SophEfDtoQ

https://stash.reaper.fm/41788/voice_swapping_up.lua

Last edited by Dragonetti; 04-14-2021 at 10:09 AM.
Dragonetti is offline   Reply With Quote
Old 04-14-2021, 11:15 AM   #22
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Try this:

Code:
--This script swaps the pitches from takes down groups (and to the first track if it is the last track)
reaper.Undo_BeginBlock()

reaper.PreventUIRefresh(1)

--sorts whatever array that is passed to it in descending order (highest to lowest)
function bubbleSort(A)
	local n = #A
	local swapped = false

	repeat
		swapped = false

		for i = 2, n do
			if A[i-1] < A[i] then
				A[i-1] , A[i] = A[i] , A[i-1]
				swapped = true
			end
		end
	until not swapped

	return A
end


--main code
groups = {}
counter = 0
prevTrack = nil
isFirstTrack = true

--loop through and organize items into a multidimensional array
for i = 0, reaper.CountSelectedMediaItems() - 1 do
	local thisItem = reaper.GetSelectedMediaItem(0, i)
	local thisTake = reaper.GetActiveTake(thisItem)

	if thisTake then
		local thisTrack = reaper.GetMediaItem_Track(thisItem)

		if thisTrack == prevTrack then
			if isFirstTrack then table.insert(groups, {takes = {}, pitches = {}}) end
			counter = counter + 1
		else
			if i == 0 then table.insert(groups, {takes = {}, pitches = {}}) else isFirstTrack = false end
			counter = 1
		end

		table.insert(groups[counter].takes, thisTake)
		table.insert(groups[counter].pitches, reaper.GetMediaItemTakeInfo_Value(thisTake, "D_PITCH"))

		prevTrack = thisTrack
	end
end


for i = 1, #groups do
	local tempPitches = groups[i].pitches

	pitchesNum = #tempPitches

	tempPitches = bubbleSort(tempPitches) --sorts all of the pitches so highest is first
	highestPitch = tempPitches[pitchesNum] + 12 --sets the highest pitch as an octave higher than whatever the lowest pitch is

	--loops through all of the pitches to make sure the lowest pitch raised by an octave isn't already in the list of pitches
		--if it is, it will raise the next lowest pitch by an octave and check - repeating this step until it breaks out
	isEqual = false
	nextIndex = pitchesNum

	while true do
		for j = nextIndex - 1, 0, -1 do
			if tempPitches[j] == highestPitch then
				isEqual = true
				break
			end
		end

		if isEqual == true then
			nextIndex = nextIndex - 1
			highestPitch = tempPitches[nextIndex] + 12

			isEqual = false
		else
			break
		end

		if nextIndex < 0 then break end --check to break out of the while in case something goes wrong and everything is equal
	end

	tempPitches[pitchesNum] = highestPitch --sets the lowest pitch to whatever the highest pitch became
	tempPitches = bubbleSort(tempPitches) --resorts all of the pitches so highest is first

	--go through and change the pitches in the current grouping
	local tempTakes = groups[i].takes
	for j = 1, #tempTakes do
		reaper.SetMediaItemTakeInfo_Value(tempTakes[j], "D_PITCH", tempPitches[j])
	end
end

reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()

reaper.Undo_EndBlock("Swap Pitches", -1)
jkooks is offline   Reply With Quote
Old 04-14-2021, 04:44 PM   #23
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Thank you, works wonderfully.
I am now trying to create the opposite script myself.
"swapp_notes_down", maybe I can do it myself.
Dragonetti is offline   Reply With Quote
Old 04-15-2021, 12:01 PM   #24
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

I've tried it for a long time, but unfortunately I can't.
Can you help me again?
"voice swapping down".
example Cmaj7

c(0) e(4) g(7) b(11) ----becomes---- b(-1) c(0) e(4) g(7)

Thanks
Dragonetti is offline   Reply With Quote
Old 04-16-2021, 11:05 AM   #25
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Here is code for one that swaps everything down:

Code:
reaper.Undo_BeginBlock()

reaper.PreventUIRefresh(1)

--sorts whatever array that is passed to it in descending order (highest to lowest)
function bubbleSort(A)
	local n = #A
	local swapped = false

	repeat
		swapped = false

		for i = 2, n do
			if A[i-1] > A[i] then
				A[i] , A[i-1] = A[i-1] , A[i]
				swapped = true
			end
		end
	until not swapped

	return A
end


--main code
groups = {}
counter = 0
prevTrack = nil
isFirstTrack = true

--loop through and organize items into a multidimensional array
for i = 0, reaper.CountSelectedMediaItems() - 1 do
	local thisItem = reaper.GetSelectedMediaItem(0, i)
	local thisTake = reaper.GetActiveTake(thisItem)

	if thisTake then
		local thisTrack = reaper.GetMediaItem_Track(thisItem)

		if thisTrack == prevTrack then
			if isFirstTrack then table.insert(groups, {takes = {}, pitches = {}}) end
			counter = counter + 1
		else
			if i == 0 then table.insert(groups, {takes = {}, pitches = {}}) else isFirstTrack = false end
			counter = 1
		end

		table.insert(groups[counter].takes, thisTake)
		table.insert(groups[counter].pitches, reaper.GetMediaItemTakeInfo_Value(thisTake, "D_PITCH"))

		prevTrack = thisTrack
	end
end


for i = 1, #groups do
	local tempPitches = groups[i].pitches

	pitchesNum = #tempPitches

	tempPitches = bubbleSort(tempPitches) --sorts all of the pitches so highest is first
	lowestPitch = tempPitches[pitchesNum] - 12 --sets the highest pitch as an octave higher than whatever the lowest pitch is

	--loops through all of the pitches to make sure the lowest pitch raised by an octave isn't already in the list of pitches
		--if it is, it will raise the next lowest pitch by an octave and check - repeating this step until it breaks out
	isEqual = false
	nextIndex = pitchesNum

	while true do
		for j = nextIndex-1, 1, -1 do
			if tempPitches[j] == lowestPitch then
				isEqual = true
				break
			end
		end

		if isEqual == true then
			nextIndex = nextIndex - 1
			lowestPitch = tempPitches[nextIndex] - 12

			isEqual = false
		else
			break
		end

		if nextIndex < 1 then break end --check to break out of the while in case something goes wrong and everything is equal
	end

	tempPitches[pitchesNum] = lowestPitch --sets the lowest pitch to whatever the highest pitch became
	tempPitches = bubbleSort(tempPitches) --resorts all of the pitches so highest is first

	--go through and change the pitches in the current grouping
	local tempTakes = groups[i].takes
	for j = 1, #tempTakes do
		reaper.SetMediaItemTakeInfo_Value(tempTakes[j], "D_PITCH", tempPitches[j])
	end
end

reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()

reaper.Undo_EndBlock("Swap Pitches Down", -1)

I also fixed a minor issue with the other script:
Code:
reaper.Undo_BeginBlock()

reaper.PreventUIRefresh(1)

--sorts whatever array that is passed to it in descending order (highest to lowest)
function bubbleSort(A)
	local n = #A
	local swapped = false

	repeat
		swapped = false

		for i = 2, n do
			if A[i-1] < A[i] then
				A[i-1] , A[i] = A[i] , A[i-1]
				swapped = true
			end
		end
	until not swapped

	return A
end


--main code
groups = {}
counter = 0
prevTrack = nil
isFirstTrack = true

--loop through and organize items into a multidimensional array
for i = 0, reaper.CountSelectedMediaItems() - 1 do
	local thisItem = reaper.GetSelectedMediaItem(0, i)
	local thisTake = reaper.GetActiveTake(thisItem)

	if thisTake then
		local thisTrack = reaper.GetMediaItem_Track(thisItem)

		if thisTrack == prevTrack then
			if isFirstTrack then table.insert(groups, {takes = {}, pitches = {}}) end
			counter = counter + 1
		else
			if i == 0 then table.insert(groups, {takes = {}, pitches = {}}) else isFirstTrack = false end
			counter = 1
		end

		table.insert(groups[counter].takes, thisTake)
		table.insert(groups[counter].pitches, reaper.GetMediaItemTakeInfo_Value(thisTake, "D_PITCH"))

		prevTrack = thisTrack
	end
end


for i = 1, #groups do
	local tempPitches = groups[i].pitches

	pitchesNum = #tempPitches

	tempPitches = bubbleSort(tempPitches) --sorts all of the pitches so highest is first
	highestPitch = tempPitches[pitchesNum] + 12 --sets the highest pitch as an octave higher than whatever the lowest pitch is

	--loops through all of the pitches to make sure the lowest pitch raised by an octave isn't already in the list of pitches
		--if it is, it will raise the next lowest pitch by an octave and check - repeating this step until it breaks out
	isEqual = false
	nextIndex = pitchesNum

	while true do
		for j = nextIndex-1, 1, -1 do
			if tempPitches[j] == highestPitch then
				isEqual = true
				break
			end
		end

		if isEqual == true then
			nextIndex = nextIndex - 1
			highestPitch = tempPitches[nextIndex] + 12

			isEqual = false
		else
			break
		end

		if nextIndex < 1 then break end --check to break out of the while in case something goes wrong and everything is equal
	end

	tempPitches[pitchesNum] = highestPitch --sets the lowest pitch to whatever the highest pitch became
	tempPitches = bubbleSort(tempPitches) --resorts all of the pitches so highest is first

	--go through and change the pitches in the current grouping
	local tempTakes = groups[i].takes
	for j = 1, #tempTakes do
		reaper.SetMediaItemTakeInfo_Value(tempTakes[j], "D_PITCH", tempPitches[j])
	end
end

reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()

reaper.Undo_EndBlock("Swap Pitches Up", -1)
jkooks is offline   Reply With Quote
Old 04-17-2021, 06:09 AM   #26
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Thank you, works wonderfully.
I'll take another look at the code to learn.
Dragonetti is offline   Reply With Quote
Old 04-19-2021, 08:31 AM   #27
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

Hi
I found a bug (Swapp Pitches Down)
The chord is correct but in the wrong order.
The top and bottom are swapped.
The highest note of the chord must always be on top.
Can you look there again?
Thanks
Dragonetti is offline   Reply With Quote
Old 04-19-2021, 10:35 AM   #28
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

This should work:

Code:
reaper.Undo_BeginBlock()

reaper.PreventUIRefresh(1)

--sorts whatever array that is passed to it in descending order (highest to lowest)
function bubbleSort(A)
	local n = #A
	local swapped = false

	repeat
		swapped = false

		for i = 2, n do
			if A[i-1] > A[i] then
				A[i] , A[i-1] = A[i-1] , A[i]
				swapped = true
			end
		end
	until not swapped

	return A
end


--main code
groups = {}
counter = 0
prevTrack = nil
isFirstTrack = true

--loop through and organize items into a multidimensional array
for i = 0, reaper.CountSelectedMediaItems() - 1 do
	local thisItem = reaper.GetSelectedMediaItem(0, i)
	local thisTake = reaper.GetActiveTake(thisItem)

	if thisTake then
		local thisTrack = reaper.GetMediaItem_Track(thisItem)

		if thisTrack == prevTrack then
			if isFirstTrack then table.insert(groups, {takes = {}, pitches = {}}) end
			counter = counter + 1
		else
			if i == 0 then table.insert(groups, {takes = {}, pitches = {}}) else isFirstTrack = false end
			counter = 1
		end

		table.insert(groups[counter].takes, thisTake)
		table.insert(groups[counter].pitches, reaper.GetMediaItemTakeInfo_Value(thisTake, "D_PITCH"))

		prevTrack = thisTrack
	end
end


for i = 1, #groups do
	local tempPitches = groups[i].pitches

	pitchesNum = #tempPitches

	tempPitches = bubbleSort(tempPitches) --sorts all of the pitches so highest is first
	lowestPitch = tempPitches[pitchesNum] - 12 --sets the highest pitch as an octave higher than whatever the lowest pitch is

	--loops through all of the pitches to make sure the lowest pitch raised by an octave isn't already in the list of pitches
		--if it is, it will raise the next lowest pitch by an octave and check - repeating this step until it breaks out
	isEqual = false
	nextIndex = pitchesNum

	while true do
		for j = nextIndex-1, 1, -1 do
			if tempPitches[j] == lowestPitch then
				isEqual = true
				break
			end
		end

		if isEqual == true then
			nextIndex = nextIndex - 1
			lowestPitch = tempPitches[nextIndex] - 12

			isEqual = false
		else
			break
		end

		if nextIndex < 1 then break end --check to break out of the while in case something goes wrong and everything is equal
	end

	tempPitches[pitchesNum] = lowestPitch --sets the lowest pitch to whatever the highest pitch became
	tempPitches = bubbleSort(tempPitches) --resorts all of the pitches so highest is first

	pitchesNum = pitchesNum + 1

	--go through and change the pitches in the current grouping
	local tempTakes = groups[i].takes
	for j = 1, #tempTakes do
		reaper.SetMediaItemTakeInfo_Value(tempTakes[j], "D_PITCH", tempPitches[pitchesNum - j])
	end
end

reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()

reaper.Undo_EndBlock("Swap Pitches Down", -1)
jkooks is offline   Reply With Quote
Old 04-19-2021, 02:02 PM   #29
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 974
Default

This is exactly right now. thanks
Dragonetti 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 02:25 PM.


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