Skip to content

Commit

Permalink
#226 controller disable, mouse follow indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesholdenmusic committed Jan 23, 2025
1 parent d0d65d5 commit edc9e9d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 32 deletions.
2 changes: 2 additions & 0 deletions code/blockmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ var param_defaults = [];

var automap = {
available_c : -1,
voice_c : -1,
available_k : -1,
available_k_block : -1,
already_k : 0, //if the keyboard is already connected to the current block don't auto
Expand All @@ -303,6 +304,7 @@ var automap = {
offset_range_c : 0,
c_cols : 4,
c_rows : 4,
mouse_follow : 0,
sidebar_row_ys : [], //gets populated if mouse_follow on to speed up the hover check
q_gain : 0.125, //default gain for cue auto connections
available_q : -1, //for cue (listen) automapping - holds the audio out(s) cue should go to
Expand Down
80 changes: 54 additions & 26 deletions code/display_pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3118,7 +3118,7 @@ function draw_sidebar(){
}
}

automap.count = (automap.mapped_c!=-1) + (automap.mapped_k>-1) + (automap.mapped_q!=-1) + ((automap.mapped_k==-1)+(automap.available_k_block>-1));
automap.count = (automap.mapped_k>-1) || (automap.mapped_q!=-1) || ((automap.devicename_c!="")&&(block_name!="core.input.control.auto")) || ((automap.mapped_k==-1)||(automap.available_k_block>-1));

if(automap.count) draw_automap_headers(sx, block);

Expand Down Expand Up @@ -3304,7 +3304,8 @@ function draw_sidebar(){
}
}
}

if(getmap) automap.sidebar_row_ys[0] = y_offset;

for(i=0;i<groups.length;i++){
var this_group_mod_in_para=[];
colour=block_colour;
Expand Down Expand Up @@ -3673,7 +3674,7 @@ function draw_sidebar(){
y_offset=namelabely+fontheight*0.2;
}
if(getmap==1){
automap.sidebar_row_ys[map_y]=y_offset;
automap.sidebar_row_ys[map_y+1]=y_offset;
if(map_x!=0){ //wrap round to the next row, padding maplist with -1s if still inside the row limit
if((map_y>=0)){// && (map_y<automap.c_rows)){
for(var tm=0;tm<(automap.c_cols-map_x);tm++){
Expand Down Expand Up @@ -3710,6 +3711,26 @@ function draw_sidebar(){
note_poly.message("setvalue", automap.available_c,"buttonmaplist",-1);
}
}
if(automap.offset_range_c>0){
var ii=automap.sidebar_row_ys[i+automap.offset_c+1];
var sbx = mainwindow_width-4;
lcd_main.message("frgb",greydark);
var rc=0;//count how many controller rows per screen row..?
for(var i = 0;i<automap.c_rows;i++){
if(i+automap.offset_c < automap.sidebar_row_ys.length){
var iii = automap.sidebar_row_ys[i+automap.offset_c];
if(iii!=undefined){
post("\nrow i",i,"from",ii,"to",iii,"over ",rc+1,"rows");
lcd_main.message("moveto",sbx,ii+8);
lcd_main.message("lineto",sbx,iii-8);
ii=iii;
rc=0;
}else{
rc++;
}
}
}
}
}
colour=block_colour;
y_offset += fontheight * 4 * knob_y;
Expand Down Expand Up @@ -6959,7 +6980,7 @@ function draw_automap_headers(sx, block) {
if ((automap.already_k == 0)&&((automap.mapped_k>-1) || ((automap.available_k_block>-1)&&(sidebar.mode=="block")&&(automap.mapped_k==-1)))){
//DRAW KEYBOARD AUTOMAP HEADER LINE
click_zone(automap_k_click, -1, -1, sidebar.x, y_offset, sidebar.x + 22, y_offset + fontheight * 0.5, mouse_index, 1);
if (!usermouse.ctrl && (usermouse.clicked2d == mouse_index - 1)) {
if (!usermouse.ctrl && (usermouse.clicked2d == mouse_index - 1) &&(automap.mapped_k>-1)) {
lcd_main.message("frgb", automap.colours_k.colour);
lcd_main.message("paintrect", sidebar.x + fo1, y_offset + 2.5 * fo1, sidebar.x + 22 - fo1, y_offset + fontheight * 0.45, automap.colours_k.colour);
lcd_main.message("moveto", sidebar.x + 1.5 * fo1, y_offset + (2.5 - 1.5 * automap.lock_k) * fo1);
Expand Down Expand Up @@ -6995,7 +7016,6 @@ function draw_automap_headers(sx, block) {
if(automap.mapped_k==-1){
lcd_main.message("moveto", sidebar.x + 26, y_offset + 0.2 * fontheight);
lcd_main.message("write", "automap");
lcd_main.message("frgb", greycolour);
lcd_main.message("moveto", sidebar.x + 26, y_offset + 0.4 * fontheight);
lcd_main.message("write", "off");
sx = sidebar.x + 26 + 2.4 * fontheight;
Expand Down Expand Up @@ -7101,10 +7121,9 @@ function draw_automap_headers(sx, block) {
if(linewrap) sx = sidebar.x2;
}
}

if (automap.mapped_c != -1) {
if ((automap.mapped_c != -1) || ((automap.voice_c>-1)&&(blocks.get("blocks["+sidebar.selected+"]::name")!="core.input.control.auto"))){
if(sx!=sidebar.x){
var chw = 26 + fontheight * 0.8;// * 1.2;
var chw = 26 + 4 + fontheight * (0.8 + 0.4 * (automap.mapped_c == -1));// * 1.2;
if(automap.lock_c && block != automap.mapped_c) {
var labl = blocks.get("blocks[" + automap.mapped_c + "]::label");
chw += (0.1 + labl.length * 0.18) * fontheight;
Expand All @@ -7119,14 +7138,20 @@ function draw_automap_headers(sx, block) {
// DRAW AUTOMAP HEADER LINE
var hf = 0.25 * fontheight;
click_zone(automap_c_click, null, -1, sx, y_offset, sx + 22, y_offset + fontheight * 0.5, mouse_index, 1);
if (!usermouse.ctrl && (usermouse.clicked2d == mouse_index - 1)) {
if(!usermouse.ctrl && (usermouse.clicked2d == mouse_index - 1)) {
lcd_main.message("frgb", automap.colours_c.colour);
lcd_main.message("moveto", sx + 1.5 * fo1, y_offset + (2.5 - 1.5 * automap.lock_k) * fo1);
lcd_main.message("lineto", sx + 1.5 * fo1, y_offset + fo1 * (1 - 0.5 * automap.lock_k));
lcd_main.message("lineto", sx + 20 - 1.5 * fo1, y_offset + fo1 * (1 - 0.5 * automap.lock_k));
lcd_main.message("lineto", sx + 20 - 1.5 * fo1, y_offset + 2.5 * fo1);
} else {
if (automap.lock_c) {
if(automap.mapped_c<0){
lcd_main.message("frgb", greydark);
lcd_main.message("moveto", sx+26, y_offset + 0.2 * fontheight);
lcd_main.message("write", "automap");
lcd_main.message("moveto", sx+26, y_offset + 0.4 * fontheight);
lcd_main.message("write", "off");
}else if (automap.lock_c) {
lcd_main.message("frgb", automap.colours_c.colour);
} else {
lcd_main.message("frgb", automap.colours_c.dark);
Expand All @@ -7137,27 +7162,29 @@ function draw_automap_headers(sx, block) {
lcd_main.message("lineto", sx + 0.106 * fontheight + 9, fo1 * 1.44 + y_offset);
}
sx += 26;
if (automap.lock_c && block != automap.mapped_c) {
var labl = blocks.get("blocks[" + automap.mapped_c + "]::label");
//lcd_main.message("paintrect", sx + fontheight * 2.1, y_offset, sidebar.x2, y_offset + fontheight * 0.5, automap.colours_c.darkest);
if(automap.mapped_c>-1){
if (automap.lock_c && block != automap.mapped_c) {
var labl = blocks.get("blocks[" + automap.mapped_c + "]::label");
//lcd_main.message("paintrect", sx + fontheight * 2.1, y_offset, sidebar.x2, y_offset + fontheight * 0.5, automap.colours_c.darkest);
lcd_main.message("frgb", automap.colours_c.dark);
lcd_main.message("moveto", sx, y_offset + 0.2 * fontheight);
lcd_main.message("write", "locked to");
lcd_main.message("frgb", automap.colours_c.colour);
lcd_main.message("moveto", sx, y_offset + 0.4 * fontheight);
lcd_main.message("write", labl);
var osx = sx;
sx += (0.1 + labl.length * 0.18) * fontheight;
click_zone(select_block, null, automap.mapped_c, osx - 2, y_offset, sx, y_offset + fontheight * 0.5, mouse_index, 1);
}
lcd_main.message("frgb", automap.colours_c.dark);
lcd_main.message("moveto", sx, y_offset + 0.2 * fontheight);
lcd_main.message("write", "locked to");
lcd_main.message("write", "rows");
lcd_main.message("frgb", automap.colours_c.colour);
lcd_main.message("moveto", sx, y_offset + 0.4 * fontheight);
lcd_main.message("write", labl);
var osx = sx;
sx += (0.1 + labl.length * 0.18) * fontheight;
click_zone(select_block, null, automap.mapped_c, osx - 2, y_offset, sx, y_offset + fontheight * 0.5, mouse_index, 1);
lcd_main.message("write", automap.offset_c + 1, "-", automap.offset_c + automap.c_rows);
click_zone(cycle_automap_offset, 1, null, sx - 2, y_offset, sidebar.x2, y_offset + 0.5 * fontheight, mouse_index, 1);
sx += fontheight * 0.8;// * 1.2;
}
lcd_main.message("frgb", automap.colours_c.dark);
lcd_main.message("moveto", sx, y_offset + 0.2 * fontheight);
lcd_main.message("write", "rows");
lcd_main.message("frgb", automap.colours_c.colour);
lcd_main.message("moveto", sx, y_offset + 0.4 * fontheight);
lcd_main.message("write", automap.offset_c + 1, "-", automap.offset_c + automap.c_rows);
click_zone(cycle_automap_offset, 1, null, sx - 2, y_offset, sidebar.x2, y_offset + 0.5 * fontheight, mouse_index, 1);
sx += fontheight * 0.8;// * 1.2;
}

if (automap.mapped_q != -1) {
Expand Down Expand Up @@ -7243,6 +7270,7 @@ function do_automap(type, voice, onoff, name){ // this is called from outside
automap.mapped_c = -1;
}else{
automap.available_c = voice;
automap.voice_c = voice;
redraw_flag.flag |= 2;
}
automap.devicename_c = name;
Expand Down
5 changes: 3 additions & 2 deletions code/init_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function initialise_dictionaries(hardware_file){
METER_TINT = config.get("METER_TINT");
SELECTED_BLOCK_Z_MOVE = config.get("SELECTED_BLOCK_Z_MOVE");
SELECTED_BLOCK_DEPENDENTS_Z_MOVE = config.get("SELECTED_BLOCK_DEPENDENTS_Z_MOVE");
automap.mouse_follow = config.get("AUTOMAP_MOUSE_FOLLOW");
sidebar.scrollbar_width = config.get("sidebar_scrollbar_width");
sidebar.width_in_units = config.get("sidebar_width_in_units");
sidebar.width = fontheight*sidebar.width_in_units;
Expand Down Expand Up @@ -738,9 +739,9 @@ function load_config_colours(){
menudarkest = [ menucolour[0]* dimm, menucolour[1]*dimm, menucolour[2]*dimm ];
var avg = (menucolour[0]+menucolour[1]+menucolour[2])/3;
greycolour = [avg,avg,avg];
avg *= 0.5;
avg *= 0.4;
greydark = [avg,avg,avg];
avg *= 2*bg_dark_ratio;
avg *= 2.5*bg_dark_ratio;
greydarkest = [avg,avg,avg];
backgroundcolour = config.get("palette::background");
backgroundcolour_blocks = config.get("palette::background_blocks");
Expand Down
2 changes: 1 addition & 1 deletion code/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ function omouse(x,y,leftbutton,ctrl,shift,caps,alt,e){
}
}
}
}else if((usermouse.x > sidebar.x) && !automap.lock_c && (automap.offset_range_c>0) && (sidebar.mode=="block") && (usermouse.got_t == 2) && config.get("AUTOMAP_MOUSE_FOLLOW") && (mouse_click_actions[usermouse.got_i]==sidebar_parameter_knob)){
}else if((usermouse.x > sidebar.x) && !automap.lock_c && (automap.offset_range_c>0) && (sidebar.mode=="block") && (usermouse.got_t == 2) && automap.mouse_follow && (mouse_click_actions[usermouse.got_i]==sidebar_parameter_knob)){
var r = -1;
for(var tr=0;tr<automap.sidebar_row_ys.length;tr++){
if(usermouse.y>automap.sidebar_row_ys[tr]) r = tr-1;
Expand Down
39 changes: 36 additions & 3 deletions code/mouse_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3656,22 +3656,28 @@ function automap_k_click(p,v){
}else{
automap.lock_k = (v!=0);
}
if((automap.available_k==-1))automap.lock_k = 0;
if(automap.lock_k==0){
if(sidebar.selected!=automap.mapped_k) automap.mapped_k = -1;
}
}
}

function automap_c_click(p,v){
if(usermouse.ctrl){
if(usermouse.alt){
select_block_by_name("core.input.control.auto");
}else if(usermouse.ctrl){
toggle_automap_c_enable();
}else{
//lock
if(v==-1){
automap.lock_c = 1 - automap.lock_c;
}else{
automap.lock_c = (v!=0);
}
if(automap.available_c==-1){
toggle_automap_c_enable();
}
if(automap.lock_c==0){
if(sidebar.selected!=automap.mapped_c) automap.mapped_c = -1;
}
Expand Down Expand Up @@ -3786,7 +3792,7 @@ function start_keyboard_looper(){

function disable_automap_k(p,v){
if(automap.available_k_block>-1){
post("\nturning off automap, block is",automap.available_k_block);
//post("\nturning off automap, block is",automap.available_k_block);
parameter_value_buffer.poke(1, MAX_PARAMETERS*automap.available_k_block+2,0.1);
automap.lock_k = 0;
redraw_flag.deferred = 132;
Expand All @@ -3795,8 +3801,35 @@ function disable_automap_k(p,v){

function enable_automap_k(p,v){
if(automap.available_k_block>-1){
post("\nturning on automap");
parameter_value_buffer.poke(1, MAX_PARAMETERS*automap.available_k_block+2,0.8);
redraw_flag.deferred = 132;
}
}

function toggle_automap_c_enable(){
post("\nauto",automap.available_c,automap.mapped_c);
if(automap.available_c>-1){
automap.mapped_c=-1;
automap.available_c=-1;
automap.lock_c=0;
for(var i=0;i<MAX_BLOCKS;i++){
if(blocks.get("blocks["+i+"]::name")=="core.input.control.auto"){
parameter_value_buffer.poke(1, MAX_PARAMETERS*i+1,0.1);
post("\off",i);
break;
}
}
}else{
automap.mapped_c=-1;
automap.available_c=automap.voice_c;
automap.lock_c=0;
for(var i=0;i<MAX_BLOCKS;i++){
if(blocks.get("blocks["+i+"]::name")=="core.input.control.auto"){
parameter_value_buffer.poke(1, MAX_PARAMETERS*i+1,0.8);
post("\non",i);
break;
}
}
}
redraw_flag.deferred = 132;
}

0 comments on commit edc9e9d

Please sign in to comment.