Skip to content

Commit

Permalink
moving the play cursor inside TimeRuler
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Dec 3, 2011
1 parent cfc00b5 commit 6585ac1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
31 changes: 11 additions & 20 deletions MxTimeGui.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
29 changes: 27 additions & 2 deletions TimeRuler.sc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TimeRuler {

var <maxTime;
var view,zoomCalc,gridLines;
var <position;

*new { arg layout,bounds,maxTime;
^super.new.init(layout,bounds,maxTime)
Expand All @@ -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
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion ZoomCalc.sc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ZoomCalc {

var <>modelRange,<>displayRange,zoomedRange;
var <>modelRange,<>displayRange,<zoomedRange;
var displaySpec,zoomedSpec;

*new { arg modelRange,displayRange;
Expand Down

0 comments on commit 6585ac1

Please sign in to comment.