1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Solution for drawing a straight line in MASCHINE

Discussion in 'MASCHINE Area' started by einfach Felix, Jun 14, 2018.

  1. einfach Felix

    einfach Felix NI Product Owner

    Messages:
    66
    hi,
    I know a lot of you want a simple feature for drawing straight lines in Maschine.
    here is the solution:
    -Download and install AutoHotkey https://autohotkey.com/download/
    -create an .ahk file
    -paste the following code:

    Code:
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    ; #Warn  ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    #IfWinActive ahk_class NINormalWindow0000000140000000
    
    a::
    
    KeyWait, LButton, D
    MouseGetPos, xpos, ypos
    sleep 100
    
    drawAutomation := true
    
    while(drawAutomation = true)
    {   
       
       if( GetKeyState("LButton", "P"))
       {   
         MouseGetPos, xpos2, ypos2
         sleep 100
         MouseClickDrag, L, %xpos%, %ypos%, %xpos2%, %ypos2%, 50
         xpos := xpos2
         ypos := ypos2
         sleep 100
       }
       if(GetKeyState("RButton","p"))
       {
         drawAutomation := false
         return
       }
    }
    
    return
    
    -use it like this (make shure that the brush is selected):
    1. press "A" on your keyboard
    2. click where you want the automation line to start
    3. click where you want tht automation line to end
    4. click the next point where your automation should go to OR right click to abort drawing more automation points.
    5. enjoy

    BTW. you can change "A" to anything else by just changing the "a::" to whatever you like, "k::" f.e.

    p.s. if you want the script to start everytime you start your pc - watch this: https://www.autohotkey.com/docs/FAQ.htm#Startup
     
    Last edited: Sep 3, 2018
    • Like Like x 5
  2. D-One

    D-One Well-Known Member

    Messages:
    10,075
    Thanks for sharing.
    PS. I bet you learned that by making cheat keybinds in games, CHEATER! :D
     
    • Funny Funny x 3
  3. D-J-K

    D-J-K NI Product Owner

    Messages:
    1,293
    Pretty cool little hack. Wondering if this can be done to achieve curves too?

    Still I find it sad that one has to go through this much trouble to do such a simple task that can be done almost unconsciously in most DAWs :(
     
    • Like Like x 1
  4. NTRLX

    NTRLX NI Product Owner

    Messages:
    151
    So you say NI does not have to implement drawing lines anymore since there is a workaround? :)
     
  5. AureVoir

    AureVoir NI Product Owner

    Messages:
    559
    this bug should be marked as "solved"
     
    • Funny Funny x 1
    • Informative Informative x 1
  6. Trickle2007

    Trickle2007 NI Product Owner

    Messages:
    48
    Hey Felix,
    what a great contribution to make things much easier!

    Does anyone know any way to do this on macOS? Might even be possible with stock / built in Automator or anything?

    Thanks and cheers :D
     
  7. einfach Felix

    einfach Felix NI Product Owner

    Messages:
    66
    hmm i guess one would need a visual representation then and I dont think ahk can draw on screen ... correct me if I'm wrong...
    I'll see what I can do ^^
     
  8. elmooso

    elmooso New Member

    Messages:
    14
    This can be replicated on OSX using keyboard maestro.

    Just load the 3 macros in the included zip file into keyboard maestro editor.

    hotkeys are as follows:
    Control+1 sets the start point of the line
    Control+2 sets the end point of the line
    Control+3 draws the line

    as with the AHK version brush needs to be selected.

    OP is awesome for coming up with this concept.

    edit: Deleted the files that were attached to this post, the macros posted further down the thread work better.
     
    Last edited: Sep 6, 2018
    • Like Like x 1
  9. einfach Felix

    einfach Felix NI Product Owner

    Messages:
    66
    elmooso very nice!

    D-J-K I updated the code - If you keep on clicking the left button the next point automatically connects to the previously clicked point.
    you can cancel this by right clicking.
    I think its a liitle more usable now :) also you can kinda draw curves with this pretty quickly.
     
  10. elmooso

    elmooso New Member

    Messages:
    14
    I've made a version of your update for Keyboard Maestro. To use it load the attached macros into the Keyboard Maestro editor and enable them, you need both of the macros in the file.

    control+a turns on the macro.
    clicking once sets a start point.
    clicking again sets an end point and draws the line.
    click again to add another point connected to the previous end point, repeat as needed.

    cancel with right click.

    you will see notifications when the macro turns on and off to let you know it started and exited (these can be removed by disabling the notification actions in the macros).

    ty again to felix, I'm just porting his logic over to a different engine so OSX users can benefit from it.

    Edit: Deleted the files that were attached to this post, updated versions are posted further down the thread.
     
    Last edited: Sep 6, 2018
    • Like Like x 3
  11. Trickle2007

    Trickle2007 NI Product Owner

    Messages:
    48
    elmooso thanks for your great work!

    Just bought Keyboard Maestro and installed the scripts - Tatahhh it works :)

    Only thing is, that my mouse pointer freezes after drawing one line... so this seems to bring back one bug of Maschine (2.7.7 btw.) I thought they fixed?

    But that one aside - it's great to have some kind of linear editing at least!!
     
  12. elmooso

    elmooso New Member

    Messages:
    14
    I'm going to clean up the macro and post another version sometime tomorrow, currently it closes using a bunch of assert checks which is messy and there are disabled notifications from debugging all over the macros. ill have a look at what could be causing the mouse to lock up while i'm at it

    Does right clicking release the mouse after its locked up?
     
    • Like Like x 1
  13. Trickle2007

    Trickle2007 NI Product Owner

    Messages:
    48
    Thank you so much for your effort - highly appreciated :)

    Unfortunately not - it freezes and is locked until I switch to another application with cmd+tab - and even after clicking back in the Maschine window it freezes again...
     
  14. elmooso

    elmooso New Member

    Messages:
    14
    odd. I just tested the macros on a fresh machine (borrowed my flatmates laptop) and they also worked there.

    I did have to move both the macros from the Maschine Automation Macro group into the Global Macro group in keyboard maestro to get them working correctly, so maybe give that a shot?
     
  15. Trickle2007

    Trickle2007 NI Product Owner

    Messages:
    48
    I'll give that a try asap ;-) Thanks for your support!
     
  16. Trickle2007

    Trickle2007 NI Product Owner

    Messages:
    48
    Ok, this seems to do the Trick ;-) Thanks elmooso :D
     
  17. elmooso

    elmooso New Member

    Messages:
    14
    Ok, cleaned up the macro for the multi segment version and added a simple one segment version that just uses one macro.
    If there are any issues with the multi segment version, or if you just want to draw one line it should work for that.

    To use, delete/disable the old versions if you have them in keyboard maestro editor then load and enable these. You need both the macros in the line tool v2 folder for the multi segment version. They should correctly load into the global macros group now (oops), but if not move them into that group.

    Controls for the multi segment version are the same as the previous version.

    Changes to the multi segment version:

    1. You can cancel the macro via right click before having to draw a line. The previous version would require at least one line to be drawn before it could be cancelled.
    2. Closes with a notification instead of an assert error message.


    Simple version works as follows once the macro is loaded and enabled:

    press control-z to start macro
    click once to set start point
    click again to set end point
    line will be drawn, macro will close.

    I've tested these on a few machines and they appear to work correctly, but let me know if there are any issues :)
     

    Attached Files:

  18. gsARCADE

    gsARCADE NI Product Owner

    Messages:
    57




    can you do a short video explaining this....im not good with coding and can you show the result on maschine...ive been asking ni for this feature for years
     
  19. StarSMASH

    StarSMASH NI Product Owner

    Messages:
    965
    I'll try this later.
     
  20. Blindeddie

    Blindeddie Well-Known Member

    Messages:
    3,665
    I tried it last night and it works perfectly... just remember if you need to type anything with an “A” in it, you need to suspend the macro... gonna try changing the hot key to something less commonly used, maybe the tilde (~). Kudos to the OP for sharing!!!:thumbsup:

    Peace,

    Blindeddie