简体   繁体   English

将 MouseDown 与 SuperCollider 一起使用:非 GUI 实现

[英]Using MouseDown with SuperCollider: non-GUI implementation

I want to use MouseDown in SuperCollider and am having a helluva time.我想在 SuperCollider 中使用 MouseDown 并且玩得很开心。 Is it the case that only mouseDownAction actually works with anything?是否只有 mouseDownAction 真正适用于任何东西? I want to be able to click anywhere on the screen, and have the mouse coordinates print, eg, to the post window:我希望能够单击屏幕上的任意位置,并打印鼠标坐标,例如,打印到 window 后:

Server.default=s=Server.local;
s.boot;
s.mouseDownAction = { x = {|t_poll=0| var x_val, y_val;
    x_val = {MouseX.kr};
    y_val = {MouseY.kr};
    Poll.kr(t_poll, [x_val, y_val], ["x_val", "y_val"]);

}.play };
s.mouseUpAction = { x.set(\t_poll,1) };

Of course, this does not work, because mouseDownAction seems reserved as a property of the 'View' class ie only clicking within a specific window, as the below working [albeit not quite what I want] code:当然,这不起作用,因为 mouseDownAction 似乎保留为“查看”class 的属性,即仅在特定的 window 内单击,因为下面的工作 [虽然不是我想要的] 代码:

w = Window.new("Mouse Coordinates", Rect(1300,600,50,50));
b = Button.new(w,Rect(10,10,40,25)).states_([["off"],["on"]]);
b.mouseDownAction = { x = {|t_poll=0| var x_val, y_val;
    x_val = {MouseX.kr};
    y_val = {MouseY.kr};
    Poll.kr(t_poll, [x_val, y_val], ["x_val", "y_val"]);
}.play };
b.mouseUpAction = { x.set(\t_poll,1) };
w.front;

Some things I want to know:我想知道的一些事情:

  1. Can I modify the first snippet to actually work?我可以修改第一个片段以实际工作吗?
  2. Is there a way to get MouseDown to work to give me these coordinates as I click anywhere on the screen?当我点击屏幕上的任何位置时,有没有办法让 MouseDown 工作给我这些坐标?
  3. How can I figure out how to 'get' the mouse coordinates (calling on which functions [already tried 'output', 'postln', &.c])?我怎样才能弄清楚如何“获取”鼠标坐标(调用哪些函数[已经尝试过“输出”、“postln”、&.c])?

Thanks!!!谢谢!!!

There is a Ugen for the mouse button https://doc.sccode.org/Classes/MouseButton.html有一个用于鼠标按钮的Ugen https://doc.sccode.org/Classes/MouseButton.html

This is the example from the linked helpfile:这是链接帮助文件中的示例:

(
SynthDef( \mousexyb, { |out=0|
    var mousex, mousey, mousebutton;
    mousex = MouseX.kr( 500, 1000 ); // this will determine the frequency of the sound (minimum value, maximum value, warp, lag)
    mousey = MouseY.kr( 0, 0.3 ); // this will determine the amplitude of the sound
    mousebutton = MouseButton.kr( 0, 1, 2 ); // this will turn the sound on or off (minimum value, maximum value, lag)
    Out.ar( out, SinOsc.ar( mousex, 0, mousey ) * mousebutton );
}).add
)

What you could do is have the server generate an OSC message when the button is pressed and have the language listen for that.您可以做的是让服务器在按下按钮时生成一条 OSC 消息并让语言监听它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VC ++中用于非GUI应用程序的计时器 - Timer in VC++ for Non-GUI Applications 在 C++ 非 GUI 应用程序中检测 USB 插入/移除 - Detecting USB insertion/Removal in C++ non-GUI application 从另一个非GUI线程启动QTimer - Start QTimer from another non-gui thread 在Visual Studio中创建非GUI服务器应用程序 - Make Non-GUI server application in Visual Studio 如何在非GUI线程上正确创建QUdpSocket? 已读未发出 - How to properly create QUdpSocket on non-gui thread ? Readyread not emitted 在非GUI线程中获取文件图标(QFileIconProvider :: icon) - Getting file icons (QFileIconProvider::icon) in non-gui thread 在仍然进行非GUI工作的同时,如何以预定间隔更新GUI? - How to update the GUI at a pre-determined interval, while still doing non-GUI work? 如何从non_GUI类和我们可以在主GUI类中检测到的非GUI线程发出信号 - how to emit a signal from a non_GUI class and from a non-GUI thread which we can detect in main GUI class 在* nix下,非GUI应用程序的体面事件库是什么? (C ++) - What's a decent events library for non-GUI applications under *nix? (C++) Dock Icon两次相同实例和Non-Gui进程错误地标记为“不响应” - Dock Icon twice of same instance and Non-Gui process wrongly tagged “not responding”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM