Advertisement
Guest User

Untitled

a guest
Aug 12th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. _AUTO_RELOAD_DEBUG = function() end
  2.  
  3. class "RenoiseScriptingTool" (renoise.Document.DocumentNode)
  4. function RenoiseScriptingTool:__init()
  5. renoise.Document.DocumentNode.__init(self)
  6. self:add_property("Name", "Untitled Tool")
  7. self:add_property("Id", "Unknown Id")
  8. end
  9.  
  10. local manifest = RenoiseScriptingTool()
  11. local ok,err = manifest:load_from("manifest.xml")
  12. local tool_name = manifest:property("Name").value
  13. local tool_id = manifest:property("Id").value
  14.  
  15. local dialog, sng, transp, show_dialog
  16. local divisor = 3
  17. sng = renoise.song()
  18. transp = sng.transport
  19. local function move_up()
  20. --debug.start()
  21. --launch dialog if no divisor is set
  22. -- if not transp then show_dialog() end
  23.  
  24. --worker values
  25. local line = transp.edit_pos.line
  26. local del_val = sng.selected_note_column.delay_value
  27. local sequence = transp.edit_pos.sequence
  28.  
  29. --step length
  30. local lpb = transp.lpb
  31. local pos_in_beat = line % lpb
  32. local step = lpb / divisor
  33.  
  34.  
  35. -- local new_line, new_delay = math.floor(step)
  36. --local = math.abs((step - step_lines)/255)
  37.  
  38. --move to closest quantised, finalise and return
  39. local amount_of_steps_over = math.floor(pos_in_beat / step)
  40. local pos_in_beat_of_last_full_step = amount_of_steps_over * step
  41. if not (pos_in_beat - pos_in_beat_of_last_full_step) == 0 then
  42. local math_floor_pos_in_beat_step_times_step_div_lpb = pos_in_beat_of_last_full_step / lpb
  43. line = line - pos_in_beat_of_last_full_step
  44. del_val = (math_floor_pos_in_beat_step_times_step_div_lpb - line)/255
  45. local t_edit_pos = tranp.edit_pos
  46. t_edit_pos.line = line
  47. transp.edit_pos = t_edit_pos
  48. sng.selected_note_column.delay_value = line * step
  49. return
  50. end
  51. --debug.stop()
  52.  
  53. --[[
  54. local new_line
  55.  
  56. --take into account current delay_value
  57. local sel_note_col = sng.selected_note_column
  58. --sel_note_col.delay_value
  59.  
  60. --pattern wrap
  61. local sel_pat_num_of_lines = sng.selected_pattern.number_of_lines
  62. local pattern_wrap_onff = transp.wrapped_pattern_edit
  63. if line < 0 then
  64. if pattern_wrap_onff then
  65. if not sequence == 1 then
  66. sequence = sequence - 1
  67. line = sng.pattern[sequence].number_of_lines - line
  68. end
  69. else
  70. line = sel_pat_num_of_lines - line
  71. end
  72. end
  73.  
  74. --finalise
  75. local t_edit_pos = transp.edit_pos
  76. t_edit_pos.line = line
  77. t_edit_pos.sequence = sequence
  78.  
  79. transp.edit_pos = t_edit_pos
  80. --sng.selected_note_column.delay_value =
  81.  
  82. ]]
  83. end
  84.  
  85. --[[
  86. local function move_down()
  87. --launch dialog if no initial value is set
  88. if not transp then show_dialog() end
  89.  
  90. --pattern wrap
  91. local sel_pat_num_of_lines = sng.selected_pattern.number_of_lines
  92. local pattern_wrap_onff = transp.wrapped_pattern_edit
  93. if line > sel_pat_num_of_lines then
  94. if pattern_wrap_onff then
  95. if sequence < #sng.patterns then
  96. sequence = sequence + 1
  97. line = line - sel_pat_num_of_lines
  98. end
  99. else
  100. line = line - sel_pat_num_of_lines
  101. end
  102. end
  103. end
  104. ]]
  105. function show_dialog()
  106.  
  107. if dialog and dialog.visible then
  108. dialog:show()
  109. return
  110. end
  111.  
  112. local vb = renoise.ViewBuilder()
  113. sng = renoise.song()
  114. transp = sng.transport
  115.  
  116. local draw_content = vb:row
  117. {
  118. vb:textfield
  119. {
  120. text = tostring(divisor),
  121. notifier = function(text)
  122. divisor = tonumber(text)
  123. end
  124. },
  125. }
  126.  
  127. local function keyhand(dialog, key)
  128. if (key.modifiers == "" and key.name == "esc") then
  129. dialog:close()
  130. else
  131. return key
  132. end
  133. end
  134.  
  135. dialog = renoise.app():show_custom_dialog('divisor', draw_content, keyhand)
  136. end
  137. --------------------------------------------------------------------------------
  138. -- Menu entries
  139. --------------------------------------------------------------------------------
  140.  
  141. renoise.tool():add_menu_entry {
  142. name = "Main Menu:Tools:"..tool_name.."...",
  143. invoke = move_up
  144. }
  145.  
  146.  
  147. --------------------------------------------------------------------------------
  148. -- Key Binding
  149. --------------------------------------------------------------------------------
  150.  
  151. --[[
  152. renoise.tool():add_keybinding {
  153. name = "Global:Tools:" .. tool_name.."...",
  154. invoke = show_dialog
  155. }
  156. --]]
  157.  
  158.  
  159. --------------------------------------------------------------------------------
  160. -- MIDI Mapping
  161. --------------------------------------------------------------------------------
  162.  
  163. --[[
  164. renoise.tool():add_midi_mapping {
  165. name = tool_id..":Show Dialog...",
  166. invoke = show_dialog
  167. }
  168. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement