If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Shapes, Mouse Events, Ruby...
10 posts
• Page 1 of 1
Shapes, Mouse Events, Ruby...
Hello everyone!
I've been browsing the forum but to no avail. If there is a tread, please point me to it?
I not very good a programming, but I was wandering if there is a way, through ruby, to be able to click on the display window and draw a rectangle (or any other shape) that can receive mouse events. For example: dragging and creating a rectangle (multiple times) with certain settings, then being able to click it and retrieve those settings?
Thank you for any replay!
I've been browsing the forum but to no avail. If there is a tread, please point me to it?
I not very good a programming, but I was wandering if there is a way, through ruby, to be able to click on the display window and draw a rectangle (or any other shape) that can receive mouse events. For example: dragging and creating a rectangle (multiple times) with certain settings, then being able to click it and retrieve those settings?
Thank you for any replay!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
That's difficult, but not impossible. How good are you at programming in Ruby? You would need to make use of the method isInMousePoint, by setting up exactly the areas that were drawn before. You also need to differentiate between a simple mouse click and click'n'drag to be able to draw a rectangle, without that being interpreted as a click on another rectangle.
The logic would be to draw a rectangle and fill a hash or array with its boundaries. The hash would then be used in isInMousePoint to check for valid clicks on existing rectangles or the drawing of a new one.
The logic would be to draw a rectangle and fill a hash or array with its boundaries. The hash would then be used in isInMousePoint to check for valid clicks on existing rectangles or the drawing of a new one.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Shapes, Mouse Events, Ruby...
Thank your for the response tulamide! I read on the forum you're the guru when it comes to ruby!
I've been experimenting with some codes I've found on arpeggiators and I have a decent (I hope) idea on how to handle mouse events. To be more specific. I wanted to make something similar to the piano roll in a DAW but the codes I've found are more on the side of arpeggiators and the note rectangle is locked in the step and if I try to change the step, the whole thing resizes.
If I understood properly: I have to save the boundaries into an array right? Then my complication would be on how to make sure I'm getting the right boundary when clicking a rectangle right? I'll try it and see If my little skills are sufficient! Thanks again! I'll post again if any or no result.
I've been experimenting with some codes I've found on arpeggiators and I have a decent (I hope) idea on how to handle mouse events. To be more specific. I wanted to make something similar to the piano roll in a DAW but the codes I've found are more on the side of arpeggiators and the note rectangle is locked in the step and if I try to change the step, the whole thing resizes.
If I understood properly: I have to save the boundaries into an array right? Then my complication would be on how to make sure I'm getting the right boundary when clicking a rectangle right? I'll try it and see If my little skills are sufficient! Thanks again! I'll post again if any or no result.
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
I have to say, I tried to create a class that would contain the area and the mouse events plus other data. I could instance the class but it couldn't draw the rectangle because it had no access to the viewport. It gave an error when calling the v.createRectangle
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
aefa wrote:I wanted to make something similar to the piano roll in a DAW
For that you don't really need all the complex isInMousePoint checks. Goes to show, how important it is, to ask precisely matching to your real issue
Having a visual piano keyboard and being able to scroll it, but still referencing the correct midi key, is that the task?
If so, there have indeed been examples already, that might help you on the way?
http://www.dsprobotics.com/support/viewtopic.php?f=3&t=12519
aefa wrote:I have to say, I tried to create a class that would contain the area and the mouse events plus other data. I could instance the class but it couldn't draw the rectangle because it had no access to the viewport. It gave an error when calling the v.createRectangle
Of course. v is a local variable. Just provide your class's draw method with the view. For example,
- Code: Select all
def my_draw_method(view)
view.drawRectangle [...]
end
Then in the RubyEdit's draw method call yours, with whatever variable you defined, for example
- Code: Select all
def draw(v)
myClass.my_draw_method(v)
end
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Shapes, Mouse Events, Ruby...
My apologies! I didn't mean a piano roll as in the piano keys. Got the terminology mixed. I meant the grid where the notes are drawn!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
Thanks again tulamide! that line of code to reference the viewport is something that I was missing completely!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
Hello Everyone!
tulamide!
I've got some progress in the project. Still I ended up doing the mouse events through schematics but so far (after coughing blood couple of time... ) is working properly. I want to get the region detection working and then I'll post the project for review
Have a nice day!
p.s.:
My regards to Spogg who has helped me a lot in the past, and everyone that always takes their time to help noobs like me!
tulamide!
I've got some progress in the project. Still I ended up doing the mouse events through schematics but so far (after coughing blood couple of time... ) is working properly. I want to get the region detection working and then I'll post the project for review
Have a nice day!
p.s.:
My regards to Spogg who has helped me a lot in the past, and everyone that always takes their time to help noobs like me!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Shapes, Mouse Events, Ruby...
aefa wrote:My regards to Spogg who has helped me a lot in the past, and everyone that always takes their time to help noobs like me!
Thank you!
I think we all like to help each other out whether noobs or not. You got the right guy on the case!
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: Shapes, Mouse Events, Ruby...
OK. So far...
Click to add. Click to delete. Drag to extend/add. Play with steps.
No other functionality added yet (I have to learn a lot more to manage them )
Please let me know if it is on the right track!
Click to add. Click to delete. Drag to extend/add. Play with steps.
No other functionality added yet (I have to learn a lot more to manage them )
Please let me know if it is on the right track!
- Attachments
-
- grid schematic 04.fsm
- (3.56 KiB) Downloaded 603 times
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 57 guests