Home Forums General Programming Lua – Counter and Clock input ?

Tagged: 

This topic contains 10 replies, has 2 voices, and was last updated by  human fly 5 months, 1 week ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #71876

    human fly
    Participant

    just a little idea to try out. something i’m curious about
    as well: programming a simple sequence display with a
    row of latching gate onoff buttons with leds.

    for now, it is to use a momentary button, ‘step’, as the clock
    trigger. (would also like to know how to program a clock,
    of course, but ‘manual’ step is ok to start with)

    leds use xor logic, so that, at rest, all gate’on’ have their
    leds on, but when the sequencer led runs, it switches them
    off momentarily as it passes, and you get the ‘chaselight’
    thing.

    so i thought, for now, have a horizontal slider, say 8steps,
    so 1-8 value range, and the ‘step’ button needs a lua to
    increment the 1-8 slider each time it receives a ‘true’
    pulse from the ‘step’ momentary button.

    then have the gate buttons call a method that ‘xors’ the
    gate button state with the count of the horizontal 1-8 slider.
    so what should happen is that each click on step will advance
    the led along the row.(and of course some comparator ‘until’
    or ‘while<' so that it can loop round to start at the beginning again) ... so haha how does this all work then? ;o)

    #71877

    human fly
    Participant
    #72103

    human fly
    Participant

    for your fleeting entertainment…
    a little macro (if that’s the correct term) wrapped
    as an exe(win64). got something working that looks
    and behaves like a sequencer gaterow with leds, which
    is stepped by momentary button input at present:

    incrementor v008
    https://app.box.com/s/1y24jwj7olvvfz5dudrd52a9lg7pbawq

    can upload a bpanelz with the led rezource, as this can
    bear much optimizing and further development.

    i would like to generate some sort of autotrigger/clock
    next, with a rate control. just for the hell of it.

    #72141

    human fly
    Participant

    updated the file, same link:

    https://app.box.com/s/1y24jwj7olvvfz5dudrd52a9lg7pbawq

    now has some extra bits, and is a bpanelz.
    for purpose of discussion. if anyone is interested.
    or just a bit of messing around with another application
    of ctrlr, etc.

    this is all really hamfisted beginner’s ‘coding'(hoho), so i’m
    aiming to abbreviate it when i learn how.
    (nb: just added the ‘cv’ modulators, and they are not
    linked to anything yet. aiming to send their value to
    ‘current step’ label modulator next)

    #72147

    human fly
    Participant

    ok: i found this in the github pages:

    class CtrlrMasterClock : public Thread
    {
    	public:
    		CtrlrMasterClock();
    		void run();
    		int getElapsedMilliseconds (const int64 ticksStart, const int64 ticksEnd = 0);
            void adjustDrift();
    		bool isRunning();
    		void start();
    		void stop();
    		void pause();
    		void reset();
    
    	private:
    		bool running;
    		int64 ticksCurrent;
    		int64 ticksPerSecond;
    		int64 ticksNextClock;
    		int64 ticksStart;
    		int64 ticksElapsed;
    		int64 ticksLast;
    };
    
    #endif

    so there’s a class called MasterClock, a class called Run,
    and Start,Stop,Pause,Reset, isRunning(true/false), and it’s in
    milliseconds elapsed. not sure what int64start/end are.

    somehow i need to call masterclock, call run+start/stop/pause,
    and set a bpm … – looks like all the bits’n’pieces are there.

    #72149
    Possemo
    Possemo
    Participant

    I think Roman said once that Ctrlr is not suited for making a sequencer – it won’t work properly.

    Anyway, I made a simple sequencer using timers (if you want to have a look I attached the panel to this post). Timing is not really defined and there is no sync to midiclock or whatever but to my knowledge it is the only way because Ctrlr’s Lua can only run one script at a time. When you start a script that runs forever (e.g. start the sequencer until you wan’t to stop it) there will be no way to stop it. It will freeze everything else in Ctrlr and it will play the sequence forever. Timers are an exception as they are run every x millisecond (you can define this parameter). In this gap, when the timer is not running, Ctrlr is still responsive. Furthermore you can define when to stop the timer.

    • This reply was modified 5 months, 1 week ago by Possemo Possemo.
    Attachments:
    You must be logged in to view attached files.
    #72154

    human fly
    Participant

    downloaded, thanks! interested to check out what you did.
    ok, well it is not a serious sequencer project. it’s more
    to get a bit of practice getting things to happen.
    a bit of parameter animation or something could be fun.

    so far, i’ve just gone, ‘oh, let’s see if i can do that..’,
    -trying to reproduce stuff i’m familiar with –
    and it worked, so it’s about adding little things as i go.

    i’d like to see if i can get a counter running anyway.
    it doesn’t have to be the event generator: i mean i’m
    not trying to make a 96ppqn thing, just a series of
    memory slots that the thing can step to when it receives
    a trigger. and: absolutely gratuitous, no reason for it
    at all at this point :o)
    if i can start it and stop it, and get it to produce a
    trigger my ‘clock’ button at intervals – and then see
    what happens.

    #72155

    human fly
    Participant

    impressive panel 😉 thanks for giving a look at it all.
    hehe, i see you’ve already considered the chord thing.
    that is certainly something that could be done.
    (fan of Bomer’s Mouse Keyboard v2)

    so:

    timer:setCallback(3,PlaySeqCallback)
     timer:startTimer(3,300)

    oh: i see: “timerID” …you can number timers, and
    keep them separate(?)..and timing interval is ms.

    are those inbuilt classes? where do i find them in
    the *.h files?

    #72163

    human fly
    Participant

    i’m gonna say it again: that is a great panel. loads of
    stuff to look at in there – it’s a bit bewildering.. !
    matrix: speaking of keanu reaves films, it’s a bit like
    ‘johnny mnemonic’-uses his empty brain as storage for
    smuggling data 😉

    so there’s how you do popups, and how to build tables,
    which i shall try to do something with. your organisation of
    methods, with a ‘library’ is interesting (for newb’)..much
    else..

    and the ‘infos’ dummy method, enumerating the timerIDs, ok,
    i see that, and see that each is called for different actions,
    mainly for helping midi data transfer. still trying to figure
    out what is a ctrlr class, and what is a function created by
    you somewhere 🙂 -so timer is a class.. whereby you can create
    timers when you need them. still looking for more info in *.h
    files, etc.

    figuring out how to use it. going to have another look at your
    sequencer – mine involves AND-ing count and the gate buttons.
    if count and gate are both true, the led goes true. that’s it
    for now, have not figured out an output yet – nor how to fetch
    the values for the semitone combos (i’m onto that, possibly).

    current stage, i think, i should try to ping the ‘clock’ button
    at timed intervals, so that that can ‘inc’ the ‘count’ modulator,
    so it can run automatically rather than manually/per click.

    maybe the clock could already be free-running- if ‘Run’ ANDs with
    that, it should auto-clock – not synced to midi or anything,
    but just so that it can run in loops, stop and start with a count
    reset from the top. if the clock is running faster than needed,
    ie: 60000 and it then divided down by a tempo control.. -are
    you saying you can’t have a timer running all the time while the
    others stop and start when they have their own jobs to do? soz :),
    i’m trying to conceive of it all.. MasterClock is then a separate
    thing you leave alone, of course.. (think i’ve seen a global tempo
    control in main Ctrlr globals?)

    so say i make Timer1 and it’s clocking at 500ms intervals, its
    params are (1,500) – what is the ‘output’ that i can use?
    how can i make it generate a 1 or True? i’ll go and have a
    think about that…

    #72167
    Possemo
    Possemo
    Participant

    I learned a lot from Carl Licroy (Prophet 08 panel). Without his panels mine would probably look much different e.g. a lot simpler without librarians etc. If I remember well Goodweather explained me the timers which are a very nice way to workaround Ctrlr bugs and ad features that wouldn’t be possible otherwise.

    I don’t know where to find the classes. You found out most things yourself:

    timer:setCallback(3,PlaySeqCallback) <- This defines a timer with the ID 3, and the timer-method is called "PlaySeqCallback". Look in this method how to set it up. At the end you must somehow stop the timer otherwise it will run forever. timer:startTimer(3,300) <- This starts the timer with the ID 3 and repeats all 300 msec. Yes you can run several timers at the same time, but keep in mind that there will always be just one of them running at a time. When one timer is running, all others will wait (and delay) until the running one stops. You can see that on the Matrix-panel: obviously moving faders has priority, so when you move a fader the pseudo-sequencer will "hiccup".

    #72168

    human fly
    Participant

    ‘You found out most things yourself’ – *not without the help
    i’ve had from you guys !* – and i still have a good way to
    go applying and comprehending some fundamental principles of
    programming – which i’m going to post about again on that
    Lua beginner’s thread: eg: ‘arguments'(..jargon!), variables,
    ..it is only just beginning to come into focus. otherwise,
    i’m just copying and amending, with a rough notion, until
    i get a result 🙂

    i think it would be good to collect all that info, and a
    library of standard methods (such as have been provided
    by previous users ) as a general Ctrlr resource – at some
    point, or as an ongoing thing. – well, it does exist, since
    there’s a library of panels that is a huge resource.

    i learnt synthedit by going through hundreds of examples
    for a while, there was a very good library at that point
    – sadly i got into that just too late to nag jeff about a few
    things in the 1.1 version, so i’m a v1.017 die-hard –
    so that’s probably a good learning format for musicians ..
    you need a bit of gratification getting things to work as
    you learn.

    lol so i spent yesterday figuring out how the popup menus
    work as a brief detour – now that looks full of possibilities..
    any idea where the menu properties are? i can change the
    vertical height of rows, eg: change 20 to 15. can popups have
    a colour? text colour? opacity/alpha? i also see an entry for
    (image) – does this mean you could have there a list with an
    image for each item on the list? it would be a good solution
    for my D-series ‘structure’ selector, where you ideally want
    to see what the algorithm looks like (as you would with an
    FM synth too) when you select options numerically.

    have also seen and reproduced how you do tables – so i now
    have parameter tables done for the D-110, it didn’t take
    too long once i got stuck in, and is ready for renumbering
    – and recycling for different uses –
    if i ever get to figure out the bulk dump formats. ah, but
    that is way down the line, i hardly dare hope to send and
    retrieve presets and have an offline library at this point.

    i can see how the timers are used, roughly. can that be referred
    to as an ‘interrupt’? pause something while another process
    completes, so that the result is available when the process
    resumes? i found the order of some methods interesting: it
    seems like some things should come after something it depends
    on, but if you try to move the order, it doesn’t work anymore.

    i have also found i can create some functions on startup and
    use them later – but other functions created like that don’t
    work (yet?). i quite like the idea of creating a load of small
    accessory functions on load, to be called by function name
    later. it can be confusing having to look through different
    methods to find out where a function is defined.

    for the timer, i need to have another look. i still haven’t
    figured out how to ‘handle’ it, or what the available parameters
    and commands are – yes, i see start/stop/pause but ummm..
    if i get a chance today.. cool-io, though: i now have popups !
    (and tables)

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Comments are closed.