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

Reply
 
Thread Tools Display Modes
Old 08-18-2015, 07:31 AM   #1
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default Any code with Lua "repeat", "until", "while" crashes REAPER

Can anyone confirm?
mpl is offline   Reply With Quote
Old 08-18-2015, 08:47 AM   #2
Lazarus
Human being with feelings
 
Join Date: Aug 2013
Posts: 1,355
Default

No, using while loops here no probs. You can create infinite loops quite easily with this type of code though, so have a check that your exit condition is being met.
Lazarus is offline   Reply With Quote
Old 08-21-2015, 01:59 AM   #3
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Ok. If you not really bussy, can you please check this (snap notes of selected items to scale of opened MIDI Editor)? Here repeat/until crashes Reaper, though it looks like everything is Ok here.

PHP Code:
  midieditor reaper.MIDIEditor_GetActive() 
  if  
midieditor ~= nil then
    is_scale_enabled 
reaper.MIDIEditor_GetSetting_int(midieditor"scale_enabled")
    if 
is_scale_enabled == 1 then
    
      
--form pattern table
      scale_root 
reaper.MIDIEditor_GetSetting_int(midieditor"scale_root")
      
retvalscale_pat_original reaper.MIDIEditor_GetSetting_str(midieditor"scale""")
      
scale_pat string.sub(scale_pat_original13-scale_root).. string.sub(scale_pat_original012-scale_root)
      
scale_pat_t={} 
      
scale_pat:gsub(".",function(c) if ~= "0" then c "1" else "0"end table.insert(scale_pat_t,c)end)
      
      --
loop through selected items notes
      sel_item_count 
reaper.CountSelectedMediaItems(0)
      if 
sel_item_count ~= nil and scale_pat_t ~= nil then
        
for 1sel_item_count do
          
item reaper.GetSelectedMediaItem(0i-1)
          
count_takes reaper.CountTakes(item)
          if 
count_takes ~= nil then
            
for 1count_takes do
              
take reaper.GetTake(itemj-1)
              if 
take ~= nil then
                table_to_insert 
= {}
                
retvalnotecnt reaper.MIDI_CountEvts(take)
                if 
notecnt ~= nil then
                  
for 1notecnt do
                    
retval,selectedmutedstartppqposendppqposchanpitchvel reaper.MIDI_GetNote(takek-1)
                    
pitch_norm pitch 12                    
                    
if scale_pat_t[pitch_norm+1] == "0" then
                       set_pitch 
pitch
                       m 
1
                       repeat 
                         set_pitch 
set_pitch 
                         pitch_norm 
pitch 12 
                       until 
                         
(scale_pat_t[pitch_norm+1] == "1"
                      else
                       
set_pitch pitch
                    end
                    temp_table 
= {selectedmutedstartppqposendppqposchanset_pitchvel}
                    
table.insert(table_to_inserttemp_table)
                    
                  
end                    
                end
                reaper
.MIDI_Sort(take)
                
                -- 
delete notes from take
                
if notecnt ~= nil then
                  
for 1notecnt do
                    
reaper.MIDI_DeleteNote(take0
                    
reaper.MIDI_Sort(take)
                  
end
                end       
                
                
-- insert new notes from table
                
if table_to_insert ~= nil then
                  
for 1#table_to_insert do
                    
temp_table table_to_insert[n]
                    
selectedmutedstartppqposendppqposchanpitchvel 
                      
temp_table[1],temp_table[2],temp_table[3],temp_table[4],temp_table[5],temp_table[6], temp_table[7],
                    
reaper.MIDI_InsertNote(takeselectedmutedstartppqposendppqposchanpitchveltrue)
                  
end
                end  
              end
              reaper
.MIDI_Sort(take)
            
end
          end
          reaper
.UpdateItemInProject(item)
        
end
      end      
    end
  end 
UPD. You`re right, it is my fault with understanding condition, right code is
PHP Code:
until (scale_pat_t[pitch_norm+1] == "0"

Last edited by mpl; 08-21-2015 at 02:52 AM.
mpl is offline   Reply With Quote
Old 08-21-2015, 03:19 AM   #4
Lazarus
Human being with feelings
 
Join Date: Aug 2013
Posts: 1,355
Default

Cool, sometimes you need to stop looking at it for a while.

I haven't tried it, but this is a nice script idea. Can I borrow some of it for my transpose stuff?
Lazarus is offline   Reply With Quote
Old 08-21-2015, 06:58 AM   #5
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

Sure)
Actually I did this because of other thing: for some reason we can`t do changes in scale directly to item chunk, so I rewrite "Midi Editor: Force Selected notes into snap scale" in Lua as I understood this action.
mpl 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 05:18 AM.


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