Shapes, Mouse Events, Ruby...

For general discussion related FlowStone
Post Reply
aefa
Posts: 48
Joined: Wed Mar 26, 2014 12:52 pm

Shapes, Mouse Events, Ruby...

Post by aefa »

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! :D
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Shapes, Mouse Events, Ruby...

Post by tulamide »

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.
"There lies the dog buried" (German saying translated literally)
aefa
Posts: 48
Joined: Wed Mar 26, 2014 12:52 pm

Re: Shapes, Mouse Events, Ruby...

Post by aefa »

Thank your for the response tulamide! I read on the forum you're the guru when it comes to ruby! :D
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...

Post by aefa »

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
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Shapes, Mouse Events, Ruby...

Post by tulamide »

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)
aefa
Posts: 48
Joined: Wed Mar 26, 2014 12:52 pm

Re: Shapes, Mouse Events, Ruby...

Post by aefa »

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...

Post by aefa »

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...

Post by aefa »

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!
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: Shapes, Mouse Events, Ruby...

Post by Spogg »

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!
aefa
Posts: 48
Joined: Wed Mar 26, 2014 12:52 pm

Re: Shapes, Mouse Events, Ruby...

Post by aefa »

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 :D )
Please let me know if it is on the right track!
Attachments
grid schematic 04.fsm
(3.56 KiB) Downloaded 736 times
Post Reply