Old 03-03-2015, 09:56 PM   #1
J Reverb
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,071
Default Get set in both directions ?

This get's the selected tracks volume and changes the slider in the gfx gui. It also works the other way if you set instead.

Can this work both ways at the same time?
If you grab the gfx slider it snaps back to the track value of course.
Can one override the other without fighting?
I have had no success so far.
I want to read the value (gfx slider updates) and send the new value from the gfx slider(reaper updates) both ways.

Code:
@import spk_slider_class.eel

function init()
(
  gfx_init("Slider",300,150);
  gfx_setfont(1, "Tahoma", 24);
  sl1 = sl1.slider(40, 40, 10,value_get, 0, 1, gfx_w - 30, 0);
  char = gfx_getchar();
  gfx_update();
  defer("init();");
  track = GetSelectedTrack(0,0);
  value_get = GetMediaTrackInfo_Value(track, "D_VOL");      
);
init();
Ta !
J Reverb is offline   Reply With Quote
Old 03-04-2015, 02:10 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

So you just want the slider move in real time ?
Maybe it is just a question of where defer is place in the script. Try it at the bottom of your function.
But you will have to be careful and watch how undo points are created.
X-Raym is offline   Reply With Quote
Old 03-04-2015, 07:28 AM   #3
J Reverb
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,071
Default

Yes,
Thanks,

I can get it to work but the sliders are fighting for the value as value in is value out and viceversa , is there a way of preventing this happening?

Code:
function init()
(
  gfx_init("Slider",300,150);
  gfx_setfont(1, "Tahoma", 24);
  sl1 = sl1.slider(40, 40, 10,value_get, 0, 1, gfx_w - 30, 0);
  char = gfx_getchar();
  gfx_update();
  track = GetSelectedTrack(0,0);
  value_get = GetMediaTrackInfo_Value(track, "D_VOL"); 
  value_set = SetMediaTrackInfo_Value(track, "D_VOL", sl1.val); 
  defer("init();");    
);
init();
Thanks,

J.
J Reverb is offline   Reply With Quote
Old 03-04-2015, 08:33 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Probably with some conditional 'if slider is touched' to separate the get from the set. Not sure how to it in real code.
X-Raym is offline   Reply With Quote
Old 03-04-2015, 08:56 AM   #5
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Here's an (old) experimental "add sliders dynamically" -script:




Code:
function scale_x_to_slider_val(range_start, range_end, x_coord, x_start_offs, x_end_offs) local (scaled_x)
(
  scaled_x = range_start + (range_end - range_start) * (x_coord - x_start_offs) / (gfx_w - x_end_offs - x_start_offs);
  scaled_x > range_end ? scaled_x = range_end;
  scaled_x < range_start ? scaled_x = range_start;
  scaled_x;
);

function scale_slider_val_to_x(range_start, range_end, slider_val, x_start_offs, x_end_offs) local (x)
(
  x = x_start_offs + (slider_val - range_start) * (x_end_offs - x_start_offs) / (range_end - range_start);
);

// SLIDER ELEMENT
function slider(x_pos, y_pos, radius, val, range_start, range_end, slider_w, slider_id) local (m_x, s_w, s_h)
// Example: slider1_val = sl1.slider(20, 20, 6, sl1.val, -100, 100, gfx_w-20, 0);
// 
// x_pos: slider x position in window
// y_pos: slider y position in window
// radius: slider knob radius
// val: slider value (function returns this)
// range_start: slider min value
// range_end: slider max value
// slider_w: slider width
//    - can be absolute: sl1.slider_w = 400;
//    - or relative: sl1.slider_w = gfx_w - 20;
// slider_id: should be a unique int value (0,1,2,3 etc.)
(
  mouse_cap == 0 ? clicked_outside = 0; this.drag_started == 0;
  mouse_cap > 0 && (mouse_x < 0 || mouse_x > gfx_w || mouse_y > gfx_h || mouse_y < 0) ? clicked_outside = 1;

  this.x_pos = x_pos;
  this.y_pos = y_pos;
  this.radius = radius;
  this.val = max(min(val, range_end), range_start);
  this.range_start = range_start;
  this.range_end = range_end;
  this.slider_w = slider_w;
  //this.slider_id = slider_id;
  ////this.slider_id = -1;
 
  //m_x = mouse_x;
 
  ////gfx_a = 0.7;
  this.a = 0.7;
  gfx_r = 0.8;
  gfx_g = 0.8;
  gfx_b = 0.8;
  this.fill = 1;
  
  /*
  clicked_outside == 0 && lmb_down == 0 && (mouse_x >= this.x_pos - this.radius && mouse_x <= this.slider_w &&  mouse_y >= this.y_pos - this.radius && mouse_y <= this.y_pos + this.radius)
  || this.drag_started == 1 ? (*/
  
  clicked_outside == 0 && lmb_down == 0 && (mouse_x >= this.x_pos && mouse_x <= this.slider_w && mouse_y >= this.y_pos && mouse_y <= this.y_pos + 10)
  || this.drag_started == 1 ? (
    !mouse_cap ? last_slider_id = slider_id; // global
    //gfx_a = 0.9;
    //this.slider_id = slider_id;
    this.a = 0.8;
    gfx_b += 0.1;
    this.fill = 1;
    m_x = mouse_x;
    mouse_cap == 1 ? (
      //this.slider_id = slider_id;
      ////gfx_a = 1;
      this.a = 0.8;
      this.drag_started = 1;
      lmb_down = 1;
      //gfx_b += 0.2;
      mouse_x > this.slider_w ? m_x = this.slider_w;
      mouse_x < this.x_pos ? m_x = this.x_pos;
      slider_id == last_slider_id ? (
        this.val = scale_x_to_slider_val(this.range_start, this.range_end, m_x, this.x_pos, gfx_w - this.slider_w);
        last_val = this.val;
      );
      
      slider_last_x = m_x;
    ) : (
      //this.fill = 0;
      this.drag_started = 0;
      lmb_down = 0;
    );
  );

  this.x_coord = scale_slider_val_to_x(this.range_start, this.range_end, this.val, this.x_pos, this.slider_w);
  this.x_coord < this.x_pos ? x_coord = this.x_pos;
  this.x_coord > this.slider_w ? x_coord = this.slider_w;
  
  //gfx_roundrect(this.x_pos - this.radius, this.y_pos - this.radius, this.slider_w - this.x_pos + 2 * this.radius, 2 * this.radius, this.radius);
  gfx_a = this.a;//this.a;
  gfx_rect(this.x_pos, this.y_pos, this.x_coord-this.x_pos, 10);
  gfx_a -= 0.65;
  gfx_rect(this.x_pos, this.y_pos, this.slider_w-this.x_pos, 10);

  //gfx_circle(this.x_coord, this.y_pos, this.radius, this.fill);
  
  gfx_measurestr(sprintf(slider_val_str, "%0.4f", this.val), s_w, s_h);
  gfx_a = 1;
  ////gfx_x = this.x_coord - 0.5 * this.radius - 0.5 * s_w;
  gfx_x = this.x_coord - 0.5 * s_w;
  ////gfx_y = this.y_pos - this.radius - gfx_texth;
  gfx_y = this.y_pos - gfx_texth;
  gfx_printf(slider_val_str);
  //gfx_y += gfx_texth;
  //gfx_printf(sprintf(#, "%0.1f", this.x_coord));
  //gfx_y += gfx_texth;
  //gfx_printf(sprintf(#, "%0.1f", m_x));
 
  this.val;
);

//////////////////////////////////////////////


function main()
( 
  i = 0;
  loop(CountSelectedTracks(0),
    i.val = GetMediaTrackInfo_Value(GetSelectedTrack(0, i), "D_PAN");
    i.val = i.slider(30, 20+ i*30, 5, i.val, -1, 1, gfx_w - 30, i);
    i += 1;
  );
  
  mouse_cap == 1 ? (
    SetMediaTrackInfo_Value(GetSelectedTrack(0, last_slider_id), "D_PAN", last_val);
  );  

  gfx_update(); 
  gfx_getchar() >= 0 ? defer("main();");
);

function init()
(
  gfx_init("",450,300);
  gfx_setfont(1, "Verdana", 16);
);
init();
main();
(I'm currently working on Lua "slider element" and "mouse handling" code. This stuff is easier with Lua)
spk77 is offline   Reply With Quote
Old 03-04-2015, 09:05 AM   #6
J Reverb
Human being with feelings
 
Join Date: Jul 2009
Posts: 1,071
Default

That's it !

Thanks spk77 exactly what I need, cheers

Edit. In fact that's perfect ! nice one

Last edited by J Reverb; 03-04-2015 at 09:20 AM.
J Reverb 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 09:22 AM.


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