@ -73,7 +73,7 @@ var auto_writeagain = 0; // When enabled, will send a "writeagain" to pattrst
var menu _number _only = 0 ; // Populates the umenu connected to 2nd outlet with stored preset number only, instead of number and name
var menu _number _only = 0 ; // Populates the umenu connected to 2nd outlet with stored preset number only, instead of number and name
var scrollable = 1 ; // Defines weither the object can be scrolled or not
var scrollable = 1 ; // Defines weither the object can be scrolled or not
var min _rows = 50 ; // Minimum number of rows to display if scrollable is enabled
var min _rows = 50 ; // Minimum number of rows to display if scrollable is enabled
var color _mode = 0 ; // Change the way the filled slots (stored presets) color is handeld. 0: stored_slot_color. 1: looping through color_1 to color_6
var color _mode = 0 ; // Change the way the filled slots (stored presets) color is handeld. 0: stored_slot_color. 1: looping through color_1 to color_6. 2: Freely assign colors 1 to 6. 3: Set any color to any preset
var select _mode = 0 ; // 0: single click to select and recall the slot. 1: single click to select the slot, double click to recall it.
var select _mode = 0 ; // 0: single click to select and recall the slot. 1: single click to select the slot, double click to recall it.
// (WORK)
// (WORK)
@ -105,6 +105,14 @@ var shift_hold, option_hold = 0;
var is _interpolating = 0 ;
var is _interpolating = 0 ;
var is _dragging = 0 ; // Drag flag
var is _dragging = 0 ; // Drag flag
var drag _slot = - 1 ; // Stores the slot that's being dragged
var drag _slot = - 1 ; // Stores the slot that's being dragged
var is _writing = 0 ;
// Keeping track of various variables for dealing with color modes
var requested _slot = - 1 ; // Which slot we're waiting a value for (used in get_all_preset_colors)
var color _mode _candidate = 0 ; // Which color mode we're aiming
var is _listening _to _subscriptionlist = 0 ; //Filters out received subscriptionlist messages when not updating slot color values
var is _listening _to _clientlist = 0 ; //Filters out received clientlist messages when not updating slot color values
var color _pattr ;
var has _loaded = false ;
var has _loaded = false ;
@ -113,6 +121,42 @@ if (jsarguments.length>1) { // Depreciated, use "pattrstorage" attribute instead
}
}
// FUNCTIONS
// FUNCTIONS
function slot ( left , top , right , bottom , name , lock , interp , color _index , color _custom ) {
this . left = left ;
this . top = top ;
this . right = right ;
this . bottom = bottom ;
this . name = name ;
this . lock = lock ;
this . interp = interp ;
this . color _index = color _index ;
this . color _custom = color _custom ;
this . init = function ( ) {
this . left = 0 ;
this . top = 0 ;
this . right = 0 ;
this . bottom = 0 ;
this . name = null ;
this . lock = 0 ;
this . interp = - 1 ;
this . init _color ( ) ;
}
this . init _color = function ( ) {
this . color _index = 0 ;
this . color _custom = stored _slot _color ;
}
this . clear = function ( ) {
this . name = null ;
this . lock = 0 ;
this . interp = - 1 ;
this . color _index = 0 ;
this . color _custom = stored _slot _color ;
}
}
function loadbang ( ) {
function loadbang ( ) {
// post("loadbang\n");
// post("loadbang\n");
has _loaded = true ;
has _loaded = true ;
@ -125,7 +169,7 @@ function calc_rows_columns() {
half _spacing = spacing / 2 ;
half _spacing = spacing / 2 ;
half _slot _size = slot _size / 2 ;
half _slot _size = slot _size / 2 ;
slots [ 0 ] = [ 0 , 0 , 0 , 0 , "(tmp)" , 0 , - 1 ] ; // Slot 0 is valid, but not represented in the GUI (and never saved by pattrstorage)
slots [ 0 ] = new slot ( 0 , 0 , 0 , 0 , "(tmp)" , 0 , - 1 , 0 , stored _slot _color ) ; // Slot 0 is valid, but not represented in the GUI (and never saved by pattrstorage)
if ( layout == 0 ) {
if ( layout == 0 ) {
columns = Math . floor ( ( ui _width - margin + spacing ) / ( slot _size + spacing ) ) ;
columns = Math . floor ( ( ui _width - margin + spacing ) / ( slot _size + spacing ) ) ;
@ -147,22 +191,19 @@ function calc_rows_columns() {
var left = margin + j * ( spacing + slot _size ) ;
var left = margin + j * ( spacing + slot _size ) ;
var right = left + slot _size ;
var right = left + slot _size ;
var cur = 1 + i * columns + j ;
var cur = 1 + i * columns + j ;
var prev _name = null ;
var prev _lock = 0 ;
// var prev_name = null;
var prev _interp = - 1 ;
// var prev_lock = 0;
// var prev_interp = -1;
var prev _state = new slot ( ) ;
prev _state . init ( ) ;
if ( typeof slots [ cur ] !== 'undefined' ) {
if ( typeof slots [ cur ] !== 'undefined' ) {
prev _name = slots [ cur ] [ 4 ] ;
prev _state = slots [ cur ] ;
prev _lock = slots [ cur ] [ 5 ] ;
// prev_name = slots[cur].name;
prev _interp = slots [ cur ] [ 6 ] ;
// prev_lock = slots[cur].lock;
// prev_interp = slots[cur].interp;
}
}
slots [ cur ] = [ left , top , right , bottom , prev _name , prev _lock , prev _interp ] ;
slots [ cur ] = new slot ( left , top , right , bottom , prev _state . name , prev _state . lock , prev _state . interp , prev _state . color _index , prev _state . color _custom ) ;
//0: left position
//1: top position
//2: right position
//3: bottom position
//4: name, null if nothing stored on that slot
//5: lock state
//6: is being interpolated (0 or 1)
}
}
}
}
@ -170,7 +211,8 @@ function calc_rows_columns() {
if ( slots _count _display < slots _highest ) {
if ( slots _count _display < slots _highest ) {
for ( var i = slots _count _display + 1 ; i <= slots _highest ; i ++ ) {
for ( var i = slots _count _display + 1 ; i <= slots _highest ; i ++ ) {
slots [ i ] = [ 0 , 0 , 0 , 0 , null , 0 , - 1 ] ;
slots [ i ] = new slot ( ) ;
slots [ i ] . init ( ) ;
}
}
}
}
paint _base ( ) ;
paint _base ( ) ;
@ -185,21 +227,21 @@ function draw_slot(id, scale, cont) {
if ( is _painting _base ) {
if ( is _painting _base ) {
draw _slot _bubble ( slots [ id ] [ 0 ] * scale , slots [ id ] [ 1 ] * scale , slot _size * scale , slot _size * scale , cont ) ;
draw _slot _bubble ( slots [ id ] . left * scale , slots [ id ] . top * scale , slot _size * scale , slot _size * scale , cont ) ;
} else {
} else {
draw _slot _bubble ( slots [ id ] [ 0 ] + offset , slots [ id ] [ 1 ] + offset , slot _size * scale , slot _size * scale , cont ) ;
draw _slot _bubble ( slots [ id ] . left + offset , slots [ id ] . top + offset , slot _size * scale , slot _size * scale , cont ) ;
}
}
cont . fill ( ) ;
cont . fill ( ) ;
if ( layout == 1 ) {
if ( layout == 1 ) {
// slot text background
// slot text background
var bg _txt _pos _x = margin + slot _size + spacing ;
var bg _txt _pos _x = margin + slot _size + spacing ;
var bg _txt _pos _y = slots [ id ] [ 1 ] ;
var bg _txt _pos _y = slots [ id ] . top ;
var bg _txt _dim _w = ui _width - ( 2 * margin + slot _size + spacing ) ;
var bg _txt _dim _w = ui _width - ( 2 * margin + slot _size + spacing ) ;
var bg _txt _dim _h = slot _size ;
var bg _txt _dim _h = slot _size ;
if ( slots [ id ] [ 4 ] != null ) {
if ( slots [ id ] . name != null ) {
cont . set _source _rgba ( stored _slot _color ) ;
cont . set _source _rgba ( stored _slot _color ) ;
} else {
} else {
cont . set _source _rgba ( empty _slot _color ) ;
cont . set _source _rgba ( empty _slot _color ) ;
@ -252,12 +294,12 @@ draw_text_bubble.local = 1;
function format _slot _name ( id ) {
function format _slot _name ( id ) {
var text = id ;
var text = id ;
// If slot is locked, add brackets around its number
// If slot is locked, add brackets around its number
if ( slots [ id ] [ 5 ] == 1 ) {
if ( slots [ id ] . lock == 1 ) {
text = '[' + text + ']' ;
text = '[' + text + ']' ;
}
}
// If slot has a name, append it to the preset name
// If slot has a name, append it to the preset name
if ( slots [ id ] [ 4 ] != null ) {
if ( slots [ id ] . name != null ) {
text += ': ' + slots [ id ] [ 4 ] ;
text += ': ' + slots [ id ] . name ;
}
}
text = text . toString ( ) ;
text = text . toString ( ) ;
return text ;
return text ;
@ -284,9 +326,13 @@ function paint_base() {
// All slots
// All slots
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
if ( i != drag _slot ) { //We mask the slot that is currently dragged as it is drawn at the mouse position already
if ( i != drag _slot ) { //We mask the slot that is currently dragged as it is drawn at the mouse position already
if ( slots [ i ] [ 4 ] != null ) {
if ( slots [ i ] . name != null ) {
if ( color _mode ) {
if ( color _mode == 1 ) {
set _source _rgba ( color _wheel _custom [ i % color _wheel _size ] ) ;
set _source _rgba ( color _wheel _custom [ i % color _wheel _size ] ) ;
} else if ( color _mode == 2 ) {
set _source _rgba ( color _wheel _custom [ Math . abs ( slots [ i ] . color _index ) % color _wheel _size ] ) ;
} else if ( color _mode == 3 ) {
set _source _rgba ( slots [ i ] . color _custom ) ;
} else {
} else {
set _source _rgba ( stored _slot _color ) ;
set _source _rgba ( stored _slot _color ) ;
}
}
@ -329,11 +375,11 @@ function paint()
if ( is _dragging == 0 && active _slot > 0 && active _slot <= slots _count _display ) {
if ( is _dragging == 0 && active _slot > 0 && active _slot <= slots _count _display ) {
set _source _rgba ( active _slot _color ) ;
set _source _rgba ( active _slot _color ) ;
if ( color _mode ) {
if ( color _mode ) {
draw _slot _bubble ( slots [ active _slot ] [ 0 ] + 1.5 , slots [ active _slot ] [ 1 ] + 1.5 , slot _size - 3 , slot _size - 3 ) ;
draw _slot _bubble ( slots [ active _slot ] . left + 1.5 , slots [ active _slot ] . top + 1.5 , slot _size - 3 , slot _size - 3 ) ;
set _line _width ( 3 ) ;
set _line _width ( 3 ) ;
stroke ( ) ;
stroke ( ) ;
} else {
} else {
draw _slot _bubble ( slots [ active _slot ] [ 0 ] , slots [ active _slot ] [ 1 ] , slot _size , slot _size ) ;
draw _slot _bubble ( slots [ active _slot ] . left , slots [ active _slot ] . top , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
}
}
}
}
@ -346,11 +392,11 @@ function paint()
// stroke();
// stroke();
set _source _rgba ( active _slot _color [ 0 ] , active _slot _color [ 1 ] , active _slot _color [ 2 ] , active _slot _color [ 3 ] * 0.5 ) ;
set _source _rgba ( active _slot _color [ 0 ] , active _slot _color [ 1 ] , active _slot _color [ 2 ] , active _slot _color [ 3 ] * 0.5 ) ;
if ( color _mode ) {
if ( color _mode ) {
draw _slot _bubble ( slots [ previous _active _slot ] [ 0 ] + 1.5 , slots [ previous _active _slot ] [ 1 ] + 1.5 , slot _size - 3 , slot _size - 3 ) ;
draw _slot _bubble ( slots [ previous _active _slot ] . left + 1.5 , slots [ previous _active _slot ] . top + 1.5 , slot _size - 3 , slot _size - 3 ) ;
set _line _width ( 3 ) ;
set _line _width ( 3 ) ;
stroke ( ) ;
stroke ( ) ;
} else {
} else {
draw _slot _bubble ( slots [ previous _active _slot ] [ 0 ] , slots [ previous _active _slot ] [ 1 ] , slot _size , slot _size ) ;
draw _slot _bubble ( slots [ previous _active _slot ] . left , slots [ previous _active _slot ] . top , slot _size , slot _size ) ;
fill ( ) ;
fill ( ) ;
}
}
}
}
@ -359,7 +405,7 @@ function paint()
if ( selected _slot > 0 && selected _slot <= slots _count _display ) {
if ( selected _slot > 0 && selected _slot <= slots _count _display ) {
set _source _rgba ( active _slot _color ) ;
set _source _rgba ( active _slot _color ) ;
set _line _width ( 1 ) ;
set _line _width ( 1 ) ;
draw _slot _bubble ( slots [ selected _slot ] [ 0 ] - 0.5 , slots [ selected _slot ] [ 1 ] - 0.5 , slot _size + 1 , slot _size + 1 ) ;
draw _slot _bubble ( slots [ selected _slot ] . left - 0.5 , slots [ selected _slot ] . top - 0.5 , slot _size + 1 , slot _size + 1 ) ;
stroke ( ) ;
stroke ( ) ;
}
}
@ -367,12 +413,12 @@ function paint()
if ( is _dragging == 0 && display _interp && is _interpolating ) {
if ( is _dragging == 0 && display _interp && is _interpolating ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
var interp = slots [ i ] [ 6 ] ;
var interp = slots [ i ] . interp ;
if ( interp >= 0 ) {
if ( interp >= 0 ) {
set _source _rgba ( interp _slot _color ) ;
set _source _rgba ( interp _slot _color ) ;
draw _slot _bubble ( slots [ i ] [ 0 ] , slots [ i ] [ 1 ] , slot _size , slot _size ) ;
draw _slot _bubble ( slots [ i ] . left , slots [ i ] . top , slot _size , slot _size ) ;
stroke ( ) ;
stroke ( ) ;
draw _slot _bubble ( slots [ i ] [ 0 ] , slots [ i ] [ 1 ] + slot _size * ( 1 - interp ) , slot _size , slot _size * interp ) ;
draw _slot _bubble ( slots [ i ] . left , slots [ i ] . top + slot _size * ( 1 - interp ) , slot _size , slot _size * interp ) ;
fill ( ) ;
fill ( ) ;
}
}
}
}
@ -384,18 +430,18 @@ function paint()
if ( option _hold ) {
if ( option _hold ) {
// About to delete
// About to delete
set _source _rgba ( empty _slot _color [ 0 ] , empty _slot _color [ 1 ] , empty _slot _color [ 2 ] , 0.8 ) ;
set _source _rgba ( empty _slot _color [ 0 ] , empty _slot _color [ 1 ] , empty _slot _color [ 2 ] , 0.8 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
draw _slot _bubble ( slots [ last _hovered ] . left + 1 , slots [ last _hovered ] . top + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
fill ( ) ;
} else {
} else {
// About to store
// About to store
set _source _rgba ( active _slot _color [ 0 ] , active _slot _color [ 1 ] , active _slot _color [ 2 ] , 0.7 ) ;
set _source _rgba ( active _slot _color [ 0 ] , active _slot _color [ 1 ] , active _slot _color [ 2 ] , 0.7 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] + 1 , slots [ last _hovered ] [ 1 ] + 1 , slot _size - 2 , slot _size - 2 ) ;
draw _slot _bubble ( slots [ last _hovered ] . left + 1 , slots [ last _hovered ] . top + 1 , slot _size - 2 , slot _size - 2 ) ;
fill ( ) ;
fill ( ) ;
}
}
}
}
// Slot border
// Slot border
set _source _rgba ( 1 , 1 , 1 , 0.8 ) ;
set _source _rgba ( 1 , 1 , 1 , 0.8 ) ;
draw _slot _bubble ( slots [ last _hovered ] [ 0 ] , slots [ last _hovered ] [ 1 ] , slot _size , slot _size ) ;
draw _slot _bubble ( slots [ last _hovered ] . left , slots [ last _hovered ] . top , slot _size , slot _size ) ;
stroke ( ) ;
stroke ( ) ;
if ( layout == 0 ) {
if ( layout == 0 ) {
@ -407,13 +453,13 @@ function paint()
var bg _txt _dim _w = text _dim [ 0 ] > slot _size ? text _dim [ 0 ] + 4 : slot _size + 4 ;
var bg _txt _dim _w = text _dim [ 0 ] > slot _size ? text _dim [ 0 ] + 4 : slot _size + 4 ;
var bg _txt _dim _h = text _dim [ 1 ] > slot _size ? text _dim [ 1 ] + 4 : slot _size + 4 ;
var bg _txt _dim _h = text _dim [ 1 ] > slot _size ? text _dim [ 1 ] + 4 : slot _size + 4 ;
var bg _txt _pos _x = text _dim [ 0 ] > slot _size || is _dragging ? slots [ last _hovered ] [ 0 ] + slot _size + 2 : slots [ last _hovered ] [ 0 ] - 2 ;
var bg _txt _pos _x = text _dim [ 0 ] > slot _size || is _dragging ? slots [ last _hovered ] . left + slot _size + 2 : slots [ last _hovered ] . left - 2 ;
var bg _txt _pos _y = text _dim [ 1 ] > slot _size || is _dragging ? slots [ last _hovered ] [ 1 ] - 2 : slots [ last _hovered ] [ 1 ] - 2 ;
var bg _txt _pos _y = text _dim [ 1 ] > slot _size || is _dragging ? slots [ last _hovered ] . top - 2 : slots [ last _hovered ] . top - 2 ;
// If there is not enough place, text is displayed on the left
// If there is not enough place, text is displayed on the left
if ( bg _txt _pos _x + bg _txt _dim _w > ui _width ) {
if ( bg _txt _pos _x + bg _txt _dim _w > ui _width ) {
bg _txt _pos _x = slots [ last _hovered ] [ 0 ] - half _spacing - bg _txt _dim _w ;
bg _txt _pos _x = slots [ last _hovered ] . left - half _spacing - bg _txt _dim _w ;
}
}
var txt _pos _x = text _dim [ 0 ] > slot _size ? bg _txt _pos _x + half _spacing : bg _txt _pos _x + ( bg _txt _dim _w / 2 ) - ( text _dim [ 0 ] / 2 ) ;
var txt _pos _x = text _dim [ 0 ] > slot _size ? bg _txt _pos _x + half _spacing : bg _txt _pos _x + ( bg _txt _dim _w / 2 ) - ( text _dim [ 0 ] / 2 ) ;
@ -482,6 +528,7 @@ function color_wheel() {
// But that makes the code sooo ugly...
// But that makes the code sooo ugly...
var args = arrayfromargs ( arguments ) ;
var args = arrayfromargs ( arguments ) ;
if ( args . length == 0 ) {
if ( args . length == 0 ) {
// Reset to default
color _wheel _custom = [ ] ;
color _wheel _custom = [ ] ;
color _wheel _custom = color _wheel _default . slice ( ) ;
color _wheel _custom = color _wheel _default . slice ( ) ;
color _1 = color _wheel _default [ 0 ] ;
color _1 = color _wheel _default [ 0 ] ;
@ -491,6 +538,7 @@ function color_wheel() {
color _5 = color _wheel _default [ 4 ] ;
color _5 = color _wheel _default [ 4 ] ;
color _6 = color _wheel _default [ 5 ] ;
color _6 = color _wheel _default [ 5 ] ;
} else if ( args . length == 5 ) {
} else if ( args . length == 5 ) {
// Set color
var n = args [ 0 ] ;
var n = args [ 0 ] ;
var col = [ args [ 1 ] , args [ 2 ] , args [ 3 ] , args [ 4 ] ]
var col = [ args [ 1 ] , args [ 2 ] , args [ 3 ] , args [ 4 ] ]
if ( n > 0 && n < 7 ) {
if ( n > 0 && n < 7 ) {
@ -522,6 +570,99 @@ function color_wheel() {
paint _base ( ) ;
paint _base ( ) ;
}
}
function setcolor ( ) {
if ( preset _color _pattr _exist ( ) ) {
var args = arrayfromargs ( arguments ) ;
var nb _args = args . length ;
var slot _nb = selected _slot ;
if ( nb _args < 1 && nb _args > 5 ) {
error ( "color: wrong number of arguments." ) ;
} else {
if ( nb _args == 0 ) {
// Reset colors of selected slot to default values
slots [ selected _slot ] . init _color ( ) ;
} else if ( nb _args == 1 ) {
// Set the color index of the currently selected slot (for when color_mode is 2)
slots [ selected _slot ] . color _index = Math . floor ( args ) ;
} else if ( nb _args == 2 ) {
// Set the color index to the 2nd argument for the slot number defined by the 1st argument
slot _nb = Math . floor ( args [ 0 ] ) ;
slots [ slot _nb ] . color _index = Math . floor ( args [ 1 ] ) ;
} else if ( nb _args == 4 ) {
// Set the custom color of the currently selected slot (for when color_mode is 3)
slots [ selected _slot ] . color _custom = [ args [ 0 ] , args [ 1 ] , args [ 2 ] , args [ 3 ] ] ;
} else if ( nb _args == 5 ) {
// Set the custom color for the slot number defined by the 1st argument to the color defined by following arguments in rgba format.
slot _nb = Math . floor ( args [ 0 ] ) ;
slots [ slot _nb ] . color _custom = [ args [ 1 ] , args [ 2 ] , args [ 3 ] , args [ 4 ] ] ;
}
update _preset _color _pattr ( slot _nb ) ;
paint _base ( ) ;
trigger _writeagain ( ) ;
}
}
}
function preset _color _pattr _exist ( ) {
var obj = this . patcher . getnamed ( "preset_color" ) ;
if ( ! obj ) {
error ( "preset_color pattr not found.\n" ) ;
color _pattr = 0 ;
return false ;
} else if ( obj . maxclass != "pattr" ) {
error ( "preset_color named object is not a pattr object.\n" ) ;
color _pattr = 0 ;
return false ;
} else if ( obj . getattr ( 'invisible' ) == 1 ) {
error ( "preset_color has been found but has invisible attribute set to 1\n" ) ;
color _pattr = 0 ;
return false ;
} else {
color _pattr = obj ;
return true ;
}
}
preset _color _pattr _exist . local = 1 ;
function update _preset _color _pattr ( s ) {
var cstm = slots [ s ] . color _custom ;
to _pattrstorage ( "setstoredvalue" , "preset_color" , s , slots [ s ] . color _index , cstm [ 0 ] , cstm [ 1 ] , cstm [ 2 ] , cstm [ 3 ] ) ;
}
update _preset _color _pattr . local = 1
function get _all _preset _colors ( ) {
if ( filled _slots . length ) {
for ( var i = 0 ; i < filled _slots . length ; i ++ ) {
get _preset _color ( filled _slots [ i ] ) ;
}
requested _slot = - 1 ;
}
}
get _all _preset _colors . local = 1 ;
function get _preset _color ( s ) {
requested _slot = s ;
to _pattrstorage ( "getstoredvalue" , "preset_color" , s ) ;
}
get _preset _color . local = 1 ;
function preset _color ( ) {
var args = arrayfromargs ( arguments ) ;
// post(pattrstorage_name, "preset_color", args, '----- args.length: ', args.length, '----- requested_slot: ', requested_slot,'\n');
if ( args . length == 5 ) {
var col = Math . max ( 0 , Math . floor ( args [ 0 ] ) ) % color _wheel _size ;
slots [ requested _slot ] . color _index = col ;
slots [ requested _slot ] . color _custom = [ args [ 1 ] , args [ 2 ] , args [ 3 ] , args [ 4 ] ] ;
} else if ( args . length == 4 ) {
slots [ requested _slot ] . color _index = 0 ;
slots [ requested _slot ] . color _custom = args ;
} else if ( args . length == 1 ) {
var col = Math . max ( 0 , Math . floor ( args ) ) % color _wheel _size ;
slots [ requested _slot ] . color _index = col ;
slots [ requested _slot ] . color _custom = stored _slot _color ;
}
}
function anything ( ) {
function anything ( ) {
// Here just to avoid error messages in case pattrstorage sends unhandled message, like when using getstoredvalue, getsubscriptionlist, getalias, etc.
// Here just to avoid error messages in case pattrstorage sends unhandled message, like when using getstoredvalue, getsubscriptionlist, getalias, etc.
@ -530,11 +671,11 @@ function anything() {
var v = arrayfromargs ( arguments ) [ 0 ] ;
var v = arrayfromargs ( arguments ) [ 0 ] ;
v = Math . floor ( v ) ;
v = Math . floor ( v ) ;
if ( v >= 0 ) {
if ( v >= 0 ) {
if ( slots [ v ] [ 5 ] > 0 ) {
if ( slots [ v ] . lock > 0 ) {
error ( 'cannot delete locked slot ' + v + '\n' ) ;
error ( 'cannot delete locked slot ' + v + '\n' ) ;
} else {
} else {
slots [ v ] [ 4 ] = null ;
slots [ v ] . name = null ;
slots [ v ] [ 6 ] = - 1 ;
slots [ v ] . interp = - 1 ;
if ( active _slot == v ) {
if ( active _slot == v ) {
active _slot = 0 ;
active _slot = 0 ;
} else if ( previous _active _slot == v ) {
} else if ( previous _active _slot == v ) {
@ -598,19 +739,21 @@ function slotlist() {
slots _highest = filled _slots [ filled _slots . length - 1 ] ;
slots _highest = filled _slots [ filled _slots . length - 1 ] ;
if ( slots _count _display < slots _highest ) {
if ( slots _count _display < slots _highest ) {
for ( var i = slots _count _display + 1 ; i <= slots _highest ; i ++ ) {
for ( var i = slots _count _display + 1 ; i <= slots _highest ; i ++ ) {
slots [ i ] = [ 0 , 0 , 0 , 0 , null , 0 , - 1 ] ;
slots [ i ] = new slot ( ) ;
slots [ i ] . init ( ) ;
}
}
}
}
for ( var i = 0 ; i < filled _slots . length ; i ++ ) {
for ( var i = 0 ; i < filled _slots . length ; i ++ ) {
to _pattrstorage ( "getslotname" , filled _slots [ i ] ) ;
to _pattrstorage ( "getslotname" , filled _slots [ i ] ) ;
}
}
get _all _preset _colors ( ) ;
}
}
}
}
function slotname ( ) {
function slotname ( ) {
var args = arrayfromargs ( arguments ) ;
var args = arrayfromargs ( arguments ) ;
if ( args [ 0 ] > 0 && args [ 1 ] != "(undefined)" ) {
if ( args [ 0 ] > 0 && args [ 1 ] != "(undefined)" ) {
slots [ args [ 0 ] ] [ 4 ] = args [ 1 ] ;
slots [ args [ 0 ] ] . name = args [ 1 ] ;
}
}
}
}
@ -640,57 +783,62 @@ function recall() {
is _interpolating = 0 ;
is _interpolating = 0 ;
set _active _slot ( args [ 0 ] ) ;
set _active _slot ( args [ 0 ] ) ;
outlet ( 0 , 'recall' , args [ 0 ] ) ;
outlet ( 0 , 'recall' , args [ 0 ] ) ;
} else {
} else if ( args . length == 2 ) {
var src _slot = args [ 0 ] ;
if ( typeof ( args [ 0 ] ) == 'number' ) {
var trg _slot = args [ 1 ] ;
var src _slot = args [ 0 ] ;
var trg _slot = args [ 1 ] ;
for ( var i = 0 ; i < filled _slots . length ; i ++ ) {
slots [ filled _slots [ i ] ] [ 6 ] = - 1 ;
for ( var i = 0 ; i < filled _slots . length ; i ++ ) {
}
slots [ filled _slots [ i ] ] . interp = - 1 ;
if ( slots [ src _slot ] [ 4 ] != null && slots [ trg _slot ] [ 4 ] != null ) {
if ( ignore _slot _zero == 1 && src _slot == 0 ) {
// Set src_slot as if we were interpolating from the last recalled preset different than 0
// This way we can monitor which preset we come from even if we used preset 0 as intermediary preset
if ( previous _target != active _slot ) {
// If the last target preset was through interpollation or direct recall
src _slot = previous _active _slot ;
} else {
src _slot = active _slot ;
}
}
}
var interp = Math . min ( 1 , Math . max ( 0 , args [ 2 ] ) ) ;
if ( interp == 0.0 ) {
if ( slots [ src _slot ] . name != null && slots [ trg _slot ] . name != null ) {
slots [ src _slot ] [ 6 ] = - 1 ;
slots [ trg _slot ] [ 6 ] = - 1 ;
if ( ignore _slot _zero == 1 && src _slot == 0 ) {
is _interpolating = 0 ;
// Set src_slot as if we were interpolating from the last recalled preset different than 0
if ( previous _target != active _slot ) {
// This way we can monitor which preset we come from even if we used preset 0 as intermediary preset
previous _active _slot = active _slot ;
if ( previous _target != active _slot ) {
} else if ( args [ 0 ] != 0 ) {
// If the last target preset was through interpollation or direct recall
previous _active _slot = args [ 0 ] ;
src _slot = previous _active _slot ;
} else {
src _slot = active _slot ;
}
}
var interp = Math . min ( 1 , Math . max ( 0 , args [ 2 ] ) ) ;
if ( interp == 0.0 ) {
slots [ src _slot ] . interp = - 1 ;
slots [ trg _slot ] . interp = - 1 ;
is _interpolating = 0 ;
if ( previous _target != active _slot ) {
previous _active _slot = active _slot ;
} else if ( args [ 0 ] != 0 ) {
previous _active _slot = args [ 0 ] ;
} else {
previous _active _slot = previous _target ;
}
set _active _slot ( src _slot ) ;
} else if ( interp == 1.0 ) {
slots [ src _slot ] . interp = - 1 ;
slots [ trg _slot ] . interp = - 1 ;
is _interpolating = 0 ;
previous _target = trg _slot ;
set _active _slot ( trg _slot ) ;
} else {
} else {
previous _active _slot = previous _target ;
slots [ src _slot ] . interp = 1 - interp ;
slots [ trg _slot ] . interp = interp ;
is _interpolating = 1 ;
active _slot = 0 ;
// set_active_slot(0);
}
}
set _active _slot ( src _slot ) ;
outlet ( 0 , "recall" , src _slot , trg _slot , interp ) ;
} else if ( interp == 1.0 ) {
slots [ src _slot ] [ 6 ] = - 1 ;
slots [ trg _slot ] [ 6 ] = - 1 ;
is _interpolating = 0 ;
previous _target = trg _slot ;
set _active _slot ( trg _slot ) ;
} else {
slots [ src _slot ] [ 6 ] = 1 - interp ;
slots [ trg _slot ] [ 6 ] = interp ;
is _interpolating = 1 ;
active _slot = 0 ;
// set_active_slot(0);
}
}
outlet ( 0 , "recall" , src _slot , trg _slot , interp ) ;
}
}
// else {
// //typeof(args[0]) == 'string', so user just recalled a single parameter.
// }
}
}
@ -711,12 +859,12 @@ function recallmulti() {
for ( var i = 0 ; i < interp _slots . length ; i ++ ) {
for ( var i = 0 ; i < interp _slots . length ; i ++ ) {
var nb = interp _slots [ i ] [ 0 ] ;
var nb = interp _slots [ i ] [ 0 ] ;
if ( slots [ nb ] [ 4 ] != null ) {
if ( slots [ nb ] . name != null ) {
interp _slots [ i ] [ 1 ] /= summed _weight ;
interp _slots [ i ] [ 1 ] /= summed _weight ;
} else {
} else {
interp _slots [ i ] [ 1 ] = - 1 ;
interp _slots [ i ] [ 1 ] = - 1 ;
}
}
slots [ nb ] [ 6 ] = interp _slots [ i ] [ 1 ]
slots [ nb ] . interp = interp _slots [ i ] [ 1 ]
}
}
is _interpolating = 1 ;
is _interpolating = 1 ;
@ -729,11 +877,16 @@ function recallmulti() {
function store ( v ) {
function store ( v ) {
v = Math . floor ( v ) ;
v = Math . floor ( v ) ;
if ( v >= 0 ) {
if ( v >= 0 ) {
if ( slots [ v ] [ 5 ] > 0 ) {
if ( slots [ v ] . lock > 0 ) {
error ( 'cannot overwrite locked slot ' + v + '\n' ) ;
error ( 'cannot overwrite locked slot ' + v + '\n' ) ;
} else {
} else {
var recalc _rows _flag = scrollable && v > slots _highest ;
var recalc _rows _flag = scrollable && v > slots _highest ;
if ( color _pattr ) {
//Initialize preset color to default for new preset
color _pattr . message ( 0 ) ;
}
to _pattrstorage ( "store" , v ) ;
to _pattrstorage ( "store" , v ) ;
to _pattrstorage ( "getslotlist" ) ;
to _pattrstorage ( "getslotlist" ) ;
@ -749,6 +902,7 @@ function store(v) {
outlet ( 0 , "store" , v ) ;
outlet ( 0 , "store" , v ) ;
if ( v ) {
if ( v ) {
// We writagain only if stored preset is > 0
trigger _writeagain ( ) ;
trigger _writeagain ( ) ;
}
}
}
}
@ -775,11 +929,11 @@ function lock() {
function lockedslots ( ) {
function lockedslots ( ) {
var locked _slots = arrayfromargs ( arguments ) ;
var locked _slots = arrayfromargs ( arguments ) ;
for ( var i = 1 ; i < slots . length ; i ++ ) {
for ( var i = 1 ; i < slots . length ; i ++ ) {
slots [ i ] [ 5 ] = 0 ;
slots [ i ] . lock = 0 ;
}
}
if ( locked _slots . length ) {
if ( locked _slots . length ) {
for ( var i = 0 ; i < locked _slots . length ; i ++ ) {
for ( var i = 0 ; i < locked _slots . length ; i ++ ) {
slots [ locked _slots [ i ] ] [ 5 ] = 1 ;
slots [ locked _slots [ i ] ] . lock = 1 ;
if ( locked _slots [ i ] == selected _slot ) {
if ( locked _slots [ i ] == selected _slot ) {
select ( selected _slot ) ;
select ( selected _slot ) ;
}
}
@ -788,14 +942,20 @@ function lockedslots() {
}
}
function write ( ) {
function write ( ) {
var args = arrayfromargs ( arguments ) ;
if ( is _writing ) {
var filename = args [ 0 ] ;
is _writing = 0 ;
var state = args [ 1 ] ;
var args = arrayfromargs ( arguments ) ;
if ( state ) {
var filename = args [ 0 ] ;
post ( pattrstorage _name + ' pattrstorage: ' + filename + ' updated\n' ) ;
var state = args [ 1 ] ;
if ( state ) {
post ( pattrstorage _name + ' pattrstorage: ' + filename + ' updated\n' ) ;
} else {
error ( pattrstorage _name + ': error while writing ' + filename + '\n' ) ;
}
} else {
} else {
error ( pattrstorage _name + ': error while writing ' + filename + '\n' ) ;
error ( "Send your write messages directly to the pattrstorage instead.\n" ) ;
}
}
}
}
function read ( ) {
function read ( ) {
@ -806,6 +966,37 @@ function read() {
}
}
}
}
function subscriptionlist ( ) {
var client = arrayfromargs ( arguments ) [ 0 ] ;
if ( is _listening _to _subscriptionlist ) {
if ( client == "preset_color" ) {
// [pattr preset_color] subscribed
// post("preset_color pattr object found and subscribed to bound pattrstorage. Switching to color mode", color_mode_candidate, '\n');
is _listening _to _subscriptionlist = 0 ;
color _mode = color _mode _candidate ;
paint _base ( ) ;
} else if ( client == "done" ) {
error ( "A [pattr preset_color] object has been found but it isn't subscribed to your pattrstorage. Please add it to your subscribelist and try changing color mode again.\n" )
is _listening _to _subscriptionlist = 0 ;
}
}
}
function clientlist ( ) {
var client = arrayfromargs ( arguments ) [ 0 ] ;
if ( is _listening _to _clientlist ) {
if ( client == "preset_color" ) {
// post("preset_color pattr object found and client to bound pattrstorage. Switching to color mode", color_mode_candidate, '\n');
is _listening _to _clientlist = 0 ;
color _mode = color _mode _candidate ;
paint _base ( ) ;
} else if ( client == "done" ) {
error ( "A [pattr preset_color] object has been found but seems to be invisible to the pattrstorage.\n" )
is _listening _to _clientlist = 0 ;
}
}
}
function resync ( ) {
function resync ( ) {
set _active _slot ( 0 ) ;
set _active _slot ( 0 ) ;
slots _clear ( ) ;
slots _clear ( ) ;
@ -849,20 +1040,19 @@ function select(v) {
selected _slot = v ;
selected _slot = v ;
set _umenu ( selected _slot ) ;
set _umenu ( selected _slot ) ;
if ( selected _slot != 0 ) {
if ( selected _slot != 0 ) {
outlet ( 2 , "set" , slots [ selected _slot ] [ 4 ] ) ;
outlet ( 2 , "set" , slots [ selected _slot ] . name ) ;
} else {
} else {
outlet ( 2 , "set" ) ;
outlet ( 2 , "set" ) ;
}
}
outlet ( 3 , "set" , slots [ selected _slot ] [ 5 ] ) ;
outlet ( 3 , "set" , slots [ selected _slot ] . lock ) ;
}
}
}
}
function slots _clear ( ) {
function slots _clear ( ) {
slots [ 0 ] = [ 0 , 0 , 0 , 0 , "(tmp)" , 0 , - 1 ] ;
slots [ 0 ] . init ( ) ;
slots [ 0 ] . name = "(tmp)" ;
for ( var i = 1 ; i < slots . length ; i ++ ) {
for ( var i = 1 ; i < slots . length ; i ++ ) {
slots [ i ] [ 4 ] = null ;
slots [ i ] . clear ( ) ;
slots [ i ] [ 5 ] = 0 ;
slots [ i ] [ 6 ] = - 1 ;
}
}
}
}
slots _clear . local = 1 ;
slots _clear . local = 1 ;
@ -870,7 +1060,7 @@ slots_clear.local = 1;
function get _slot _index ( x , y ) {
function get _slot _index ( x , y ) {
// Returns which slot is hovered by the mouse
// Returns which slot is hovered by the mouse
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
for ( var i = 1 ; i <= slots _count _display ; i ++ ) {
if ( y > ( slots [ i ] [ 1 ] - half _spacing ) && y < ( slots [ i ] [ 3 ] + half _spacing ) && x > ( slots [ i ] [ 0 ] - half _spacing ) && x < ( slots [ i ] [ 2 ] + half _spacing ) ) {
if ( y > ( slots [ i ] . top - half _spacing ) && y < ( slots [ i ] . bottom + half _spacing ) && x > ( slots [ i ] . left - half _spacing ) && x < ( slots [ i ] . right + half _spacing ) ) {
return i ;
return i ;
}
}
@ -899,7 +1089,7 @@ function update_umenu() {
var nb = filled _slots [ i ] ;
var nb = filled _slots [ i ] ;
var txt = null ;
var txt = null ;
if ( ! menu _number _only ) {
if ( ! menu _number _only ) {
txt = slots [ filled _slots [ i ] ] [ 4 ] ;
txt = slots [ filled _slots [ i ] ] . name ;
}
}
outlet ( 1 , "append" , nb , txt ) ;
outlet ( 1 , "append" , nb , txt ) ;
}
}
@ -914,12 +1104,13 @@ function set_umenu(v) {
if ( menu _number _only ) {
if ( menu _number _only ) {
outlet ( 1 , "setsymbol" , v ) ;
outlet ( 1 , "setsymbol" , v ) ;
} else {
} else {
outlet ( 1 , "setsymbol" , v + ' ' + slots [ v ] [ 4 ] ) ;
outlet ( 1 , "setsymbol" , v + ' ' + slots [ v ] . name ) ;
}
}
}
}
function trigger _writeagain ( ) {
function trigger _writeagain ( ) {
if ( auto _writeagain && ! is _dragging ) {
if ( auto _writeagain && ! is _dragging ) {
is _writing = 1 ;
to _pattrstorage ( "writeagain" ) ;
to _pattrstorage ( "writeagain" ) ;
}
}
@ -969,7 +1160,7 @@ function onclick(x,y,but,cmd,shift,capslock,option,ctrl)
if ( option ) {
if ( option ) {
output = "delete" ;
output = "delete" ;
}
}
} else if ( slots [ last _hovered ] [ 4 ] == null ) {
} else if ( slots [ last _hovered ] . name == null ) {
return ;
return ;
}
}
if ( output == "store" ) {
if ( output == "store" ) {
@ -1004,7 +1195,7 @@ function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
{
{
if ( pattrstorage _name != null ) {
if ( pattrstorage _name != null ) {
y -= y _offset ;
y -= y _offset ;
if ( is _dragging == 0 && last _hovered > 0 && slots [ last _hovered ] [ 4 ] !== null ) {
if ( is _dragging == 0 && last _hovered > 0 && slots [ last _hovered ] . name !== null ) {
// To prevent mistakes, is_dragging is set to 1 only when dragging for more than 10 pixels
// To prevent mistakes, is_dragging is set to 1 only when dragging for more than 10 pixels
var dist _from _start = Math . sqrt ( ( x - last _x ) * ( x - last _x ) + ( y - last _y ) * ( y - last _y ) ) ;
var dist _from _start = Math . sqrt ( ( x - last _x ) * ( x - last _x ) + ( y - last _y ) * ( y - last _y ) ) ;
if ( dist _from _start > 10 ) {
if ( dist _from _start > 10 ) {
@ -1018,19 +1209,19 @@ function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
last _x = x ;
last _x = x ;
last _y = y ;
last _y = y ;
if ( ! but ) {
if ( ! but ) {
// Wehen to button is released, the dragging ceases
// When the button is released, the dragging ceases
if ( last _hovered > 0 && last _hovered != drag _slot ) {
if ( last _hovered > 0 && last _hovered != drag _slot ) {
var cur _active _slot = active _slot ;
var cur _active _slot = active _slot ;
var cur _prev _active _slot = previous _active _slot ;
var cur _prev _active _slot = previous _active _slot ;
var offset = ( ( last _hovered <= drag _slot ) && slots [ last _hovered ] [ 4 ] != null ) ? 1 : 0 ;
var offset = ( ( last _hovered <= drag _slot ) && slots [ last _hovered ] . name != null ) ? 1 : 0 ;
var offset _others = slots [ last _hovered ] [ 4 ] != null ? 1 : 0 ;
var offset _others = slots [ last _hovered ] . name != null ? 1 : 0 ;
var drag _slot _lock = slots [ drag _slot ] [ 5 ] ;
var drag _slot _lock = slots [ drag _slot ] . lock ;
// If the slot we wan to drag is locked, we need to temporarily unlock it.
// If the slot we wan to drag is locked, we need to temporarily unlock it.
if ( drag _slot _lock ) {
if ( drag _slot _lock ) {
lock ( drag _slot , 0 ) ;
lock ( drag _slot , 0 ) ;
}
}
// If new slot is empty we just move the drag preset here. If it's not, we move al next slots to the right
// If new slot is empty we just move the drag preset here. If it's not, we move al next slots to the right
if ( slots [ last _hovered ] [ 4 ] !== null ) {
if ( slots [ last _hovered ] . name !== null ) {
to _pattrstorage ( "insert" , last _hovered ) ;
to _pattrstorage ( "insert" , last _hovered ) ;
}
}
@ -1115,6 +1306,7 @@ if (ui_width == 64 && ui_height == 64) {
// Allows for dynamic resizing even in presentation mode (addressing the limitation of onresize())
// Allows for dynamic resizing even in presentation mode (addressing the limitation of onresize())
var pres _rect = new MaxobjListener ( this . box , "presentation_rect" , get _prect ) ;
var pres _rect = new MaxobjListener ( this . box , "presentation_rect" , get _prect ) ;
function get _prect ( prect ) {
function get _prect ( prect ) {
// post(this.patcher.wind.assoc.getattr("globalpatchername") == max.frontpatcher.wind.assoc.getattr("globalpatchername") ? 1 : 0, "\n")
onresize ( prect . value [ 2 ] , prect . value [ 3 ] )
onresize ( prect . value [ 2 ] , prect . value [ 3 ] )
}
}
get _prect . local = 1 ;
get _prect . local = 1 ;
@ -1450,12 +1642,34 @@ function getcolor_mode() {
return color _mode ;
return color _mode ;
}
}
function setcolor _mode ( v ) {
function setcolor _mode ( v ) {
if ( v == 1 ) {
v = Math . floor ( v ) ;
color _mode = 1 ;
v = Math . max ( 0 , Math . min ( 3 , v ) ) ;
// For color modes 2 and 3 (select and custom),
// we need to ensure there's a [pattr preset_color] somewhere to store the preset color
if ( v >= 2 ) {
if ( ! preset _color _pattr _exist ( ) ) {
v = 0 ;
color _mode = v ;
paint _base ( ) ;
} else {
if ( pattrstorage _obj != null && pattrstorage _obj . getattr ( 'subscribemode' ) == 1 ) {
// If the pattrstorage is in subscribe mode, we need to query its subscription list,
// ...and wait for the result to continue (see function subscribelist)
post ( pattrstorage _name , "subscribe mode detected. Checking for subscribed 'preset_color' client.\n" ) ;
is _listening _to _subscriptionlist = 1 ;
color _mode _candidate = v ;
to _pattrstorage ( "getsubscriptionlist" ) ;
} else {
// If not in subscribe mode
is _listening _to _clientlist = 1 ;
color _mode _candidate = v ;
to _pattrstorage ( "getclientlist" ) ;
}
}
} else {
} else {
color _mode = 0 ;
color _mode = v ;
paint _base ( ) ;
}
}
paint _base ( ) ;
}
}
declareattribute ( "color_1" , "getcolor1" , "setcolor1" , 1 ) ;
declareattribute ( "color_1" , "getcolor1" , "setcolor1" , 1 ) ;