Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moving the play cursor inside TimeRuler

  • Loading branch information...
commit 6585ac195f20f1dee0a7531feb90e36289be0501 1 parent cfc00b5
@crucialfelix authored
Showing with 39 additions and 23 deletions.
  1. +11 −20 MxTimeGui.sc
  2. +27 −2 TimeRuler.sc
  3. +1 −1  ZoomCalc.sc
View
31 MxTimeGui.sc
@@ -5,7 +5,7 @@ MxTimeGui : ObjectGui {
var <from,<to,<maxTime,zoomCalc,playZoomCalc;
var xScale;
var <>laneHeight=150;
- var zoom,playHead,timeRuler,updater,units;
+ var zoom,timeRuler,updater,units;
writeName {}
guiBody { arg layout;
@@ -59,19 +59,24 @@ MxTimeGui : ObjectGui {
zoomCalc = ZoomCalc([0,maxTime],[0,width]);
playZoomCalc = ZoomCalc([0,maxTime],[0,1.0]);
- makeSidebar.value(nil,
+ makeSidebar.value({ arg s;
+ // goto start
+ ActionButton(s,"|<",{model.gotoBeat(0,1)})
+ },
{ arg m;
timeRuler = TimeRuler(m,Rect(0,0,m.bounds.width,buttonHeight * 2),maxTime);
});
timeRuler.keyDownAction = kdr;
-
+ timeRuler.mouseDownAction = { arg beat, modifiers, buttonNumber, clickCount;
+ model.gotoBeat( beat.trunc(4) )
+ };
this.prSetFromTo(0.0,maxTime);
// zoom controls
makeSidebar.value({ arg s;
ActionButton(s,"<-zoom->",{this.zoom(0,maxTime,true)})
},{ arg m;
- zoom = SCRangeSlider(m,m.bounds.width@buttonHeight);
+ zoom = RangeSlider(m,m.bounds.width@buttonHeight);
});
zoom.lo = 0.0;
zoom.hi = 1.0;
@@ -80,24 +85,10 @@ MxTimeGui : ObjectGui {
zoom.keyDownAction = kdr;
zoom.focusColor = focusColor;
- makeSidebar.value({ arg s;
- // goto start
- ActionButton(s,"|<",{model.gotoBeat(0,1)})
- },{ arg m;
- playHead = SCSlider(m,m.bounds.width@buttonHeight);
- });
- playHead.background = Color(0.36241707801819, 0.55301971435547, 0.60233759880066, 1);
- playHead.knobColor = Color.black;
- playHead.thumbSize = buttonHeight / 3.0;
- playHead.action = { arg mg;
- model.gotoBeat( playZoomCalc.displayToModel(mg.value).trunc(4) )
- };
- playHead.keyDownAction = kdr;
- playHead.focusColor = focusColor;
updater = Updater(model.position,{ arg pos;
{
- if(playHead.isClosed.not,{// in case closed while deferring
- playHead.value = playZoomCalc.modelToDisplay(pos.current) ? 0;
+ if(timeRuler.isClosed.not,{
+ timeRuler.position = pos.current;
})
}.defer
}).removeOnClose(layout);
View
29 TimeRuler.sc
@@ -16,6 +16,7 @@ TimeRuler {
var <maxTime;
var view,zoomCalc,gridLines;
+ var <position;
*new { arg layout,bounds,maxTime;
^super.new.init(layout,bounds,maxTime)
@@ -31,8 +32,20 @@ TimeRuler {
view = UserView(layout,bounds);
gridLines = GridLines(view,bounds,nil,[0.0,maxTime].asSpec,true,false);
view.drawFunc = {
- gridLines.draw
- }
+ gridLines.draw;
+ if((position ? -1).inclusivelyBetween(*zoomCalc.zoomedRange),{
+ Pen.use {
+ var x;
+ Pen.width = 1;
+ Pen.color = Color.blue;
+ x = zoomCalc.modelToDisplay(position);
+ Pen.moveTo( x@0 );
+ Pen.lineTo( x@bounds.height );
+ Pen.stroke;
+ }
+ })
+ };
+ view.focusColor = GUI.skin.focusColor ? Color.clear;
}
refresh {
view.refresh
@@ -47,7 +60,19 @@ TimeRuler {
zoomCalc.modelRange = [0.0,maxTime];
gridLines.domainSpec = [0.0,maxTime].asSpec;
}
+ position_ { arg p;
+ position = p;
+ view.refresh;
+ }
keyDownAction_ { arg f;
view.keyDownAction = f;
}
+ mouseDownAction_ { arg f;
+ view.mouseDownAction = { arg view,x,y,modifiers,buttonNumber,clickCount;
+ f.value( zoomCalc.displayToModel(x), modifiers,buttonNumber,clickCount )
+ }
+ }
+ isClosed {
+ ^view.isClosed
+ }
}
View
2  ZoomCalc.sc
@@ -2,7 +2,7 @@
ZoomCalc {
- var <>modelRange,<>displayRange,zoomedRange;
+ var <>modelRange,<>displayRange,<zoomedRange;
var displaySpec,zoomedSpec;
*new { arg modelRange,displayRange;
Please sign in to comment.
Something went wrong with that request. Please try again.