Build a perfect Virtual Piano using buttons only


(joule) #21

Yes. By making a class you can include smart properties (“first_octave”, “last_octave” et c) and make sure that these will refresh the whole piano view whenever they are changed.

… allowing a syntax that would look something like this:

local piano_widget = PianoWidget { first_octave = 2, last_octave = 7 } -- creates an object by the PianoWidget class
piano_widget.first_octave = 3 -- set a new value for first_octave. in the class, a property setter function is used to refresh the piano view

A class can be used as an interface that makes dynamic behavior like this a breeze. You can imagine how simple it would be to scroll, increase or decrease number of octaves by just pressing a button, and with this kind of automatic rebuilding.

PS. I noticed that you linked a tutorial on LUA classes previously. However, Renoise allows a nicer syntax than the one found in conventional lua tutorials.


(Raul (ulneiz)) #22

If you want to do a virtual-midi keyboard alike thing with MIDI input, you’ll need for the tool to configure it’s own MIDI input.

There is an example on how to do this here:

https://github.com/renoise/xrnx/blob/master/Snippets/Midi.lua

It lets you receive raw MIDI data, which you can then do whatever with you want.

All the basic MIDI messages (so, not sysex and such stuff) is really just three bytes of data - so quite simple to process.

(check the MIDI input panel to investigate incoming messages)

If you want to trigger notes in realtime, this is done through the OSC server, no matter what

Remember, you tool defines it’s own MIDI input port - independently of Renoise.

You can send messages using the OSC server in two ways:

  1. “Raw” midi message which is received by whichever instrument is selected

  2. “Extended” message which targets a specific instrument and/or track

The “extended” message is dealing with triggering notes only, so if you want to pass CC data from the keyboard (mod wheel?) to Renoise (or other tools), then you need to send as “raw” midi

Raw MIDI works like incoming midi message and can be MIDI mapped to any element that light up when pressing CTRL+M (MIDI mapping mode).

Hope this helps!

I have not gone into depth to control a specific tool with MIDI input.Thinking about a virtual piano, the only thing that would need to be controlled is the reaction of a button according to the note pressed with the MIDI keyboard.That’s 120 buttons on the tool related keys 120 notes of the MIDI keyboard.In the end, the code is summarized in configuring a single button with the MIDI input code. Then add the remaining 119.

The MIDI code that is needed to run the tool, will serve for any model MIDI keyboard?


(Raul (ulneiz)) #23

Yes. By making a class you can include smart properties (“first_octave”, “last_octave” et c) and make sure that these will refresh the whole piano view whenever they are changed.

… allowing a syntax that would look something like this:

local piano_widget = PianoWidget { first_octave = 2, last_octave = 7 } -- creates an object by the PianoWidget class
piano_widget.first_octave = 3 -- set a new value for first_octave. in the class, a property setter function is used to refresh the piano view

A class can be used as an interface that makes dynamic behavior like this a breeze. You can imagine how simple it would be to scroll, increase or decrease number of octaves by just pressing a button, and with this kind of automatic rebuilding.

PS. I noticed that you linked a tutorial on LUA classes previously. However, Renoise allows a nicer syntax than the one found in conventional lua tutorials.

I’ve been looking at this.It is also possible to do it as follows:

function pw_build(first_octave, last_octave) --range 0 to 9 (10 octaves)
    local piano_widget = vb:row { margin = 5, spacing = -2 }
  
    for octave = first_octave, last_octave do
      piano_widget:add_child( pw_build_octave(octave) )
    end
  
    return piano_widget
  end
  
  my_pianowidget_content = pw_build(3,6)

Withpw_build(3,6) octaves 3, 4, 5, 6 appear.It is thus possible to easily change or move it.Move one octave to the left would bepw_build(2,5).Maximize:pw_build(0,9).Only one octave (octave 4): pw_build(4,4)


(joule) #24

Yes, of course you can use function oriented programming for anything if you want to, but it’s not a very good (flexible and future friendly) way of designing the code.


#25

So I take it you won’t be touching Clojure then Joule? :wink:

C
    You shoot yourself in the foot. 

Assembly Language
    You crash the OS and overwrite the root disk. The system administrator arrives and shoots you in the foot.
    After a moment of contemplation, the administrator shoots himself in the foot and then hops around the room rabidly shooting at everyone in sight. 

C++
    You accidentally create a dozen instances of yourself and shoot them all in the foot. 
    Providing emergency medical care is impossible since you can't tell which are bitwise copies and which are just 
    pointing at others and saying "that's me, over there."

I like good ol’ assembly language :slight_smile:


(Raul (ulneiz)) #26

Lately I’ve been busy with another tool. I leave here a screenshot that shows the appearance of a tool with two virtual pianos, one horizontal and one vertical.

7549 VPDpro_v1.0.png

Both pianos have been constructed using the methodology of this topic.The vertical virtual piano could be used in any tool similar to a piano roll.


(frenetic_friend) #27

It looks so complicated. You must have used a lot of selfmade bitmaps.

This tool is for users with midicontrollers, right?


(Raul (ulneiz)) #28

It looks so complicated. You must have used a lot of selfmade bitmaps.

No, actually I’ve only used a couple of templates to create the images. As it is a repetitive process it is very simple.On the other hand, I have a hobby to create new icons. I like it.

This tool is for users with midicontrollers, right?

Yes. With a Midi controller keyboard you can compose with live recording, but not edit.This tool allows editing with the mouse and with the midi Input.In fact, you could compose a song without using an alphanumeric USB keyboard.Also, I added the ChordPad with the same capacity. You can add chords with the mouse or with any Midi pad.The tool is designed to be compact.You can select the columns you want to display.

It may seem a bit complex. But the compressed tool does not occupy more than 100KB.


(frenetic_friend) #29

The tool is designed to be compact

Did you try it on tablets?


(Raul (ulneiz)) #30

Did you try it on tablets?

No.I’m working using Windows 10 and a normal monitor.But I guess on a touch screen could be controlled. That is, composing a song through the tool from the touch screen.It is designed to take advantage of the maximum height in a monitor of 1024 x 768, at least.For the touch screen it would be necessary to add a crosshead or joystick(up down right left).It could work…

The advantage of this tool is that it offers a large area to view and edit all the parameters that you can use within the pattern editor, except the parameters derived from the automation of the effects chains.Actually, the tool “shows a zoom” of one line of the selected note column.It allows better understanding of the parameters used and available…


(Akiz) #31

Yes, of course you can use function oriented programming for anything if you want to, but it’s not a very good (flexible and future friendly) way of designing the code.

Why? I am asking as a clojure developer :slight_smile:


(joule) #32

It’s more practical when making something that is more complex. This means that it will likely take less time to add new features in the future (it’s not uncommon to realize that a lot of stuff must be restructured when adding some new feature to function oriented code). Also, it’s a more true representation of the actual behavior of a software, I think. In addition, the classes can be more reusable as they are likely more simple to implement in other sotware.


(Sparky) #33

Hi Raul. Do you still have the .xrnx file for the basic virtual piano you had a screenshot of? Would you mind making that available please if you do? I just want to enter notes with both the track window and piano keys visible at the same time. Normally I’d use my Midi keyboard but this is for an academic exercise on my laptop while away from home.


(Raul (ulneiz)) #34

Hi Raul. Do you still have the .xrnx file for the basic virtual piano you had a screenshot of? Would you mind making that available please if you do? I just want to enter notes with both the track window and piano keys visible at the same time. Normally I’d use my Midi keyboard but this is for an academic exercise on my laptop while away from home.

Hi Sparky! Currently the closest thing is the KangarooX120 tool.Among other things, it has a horizontal virtual piano with all the octaves that allows to introduce any note with the mouse from each key of the piano.You can also map it for your MIDI Input.

If you are not interested in the pads panel,you can minimize it, to show only this virtual piano:

[sharedmedia=core:attachments:8135]


(Sparky) #35

Hi Sparky! Currently the closest thing is the KangarooX120 tool.Among other things, it has a horizontal virtual piano with all the octaves that allows to introduce any note with the mouse from each key of the piano.You can also map it for your MIDI Input.

If you are not interested in the pads panel,you can minimize it, to show only this virtual piano:

Excellent! Thanks for that. Although I am interested in playing with Lua another time, I was just wanting a music keyboard for today. That’s great - just what I needed, thank you.


(Raul (ulneiz)) #36

Excellent! Thanks for that. Although I am interested in playing with Lua another time, I was just wanting a music keyboard for today. That’s great - just what I needed, thank you.

I’m glad it serves you. If you intend to play with the LUA code, maybe KangarooX120 is not an easy tool to start with. Use custom buttons (many) and several classes to define specific objects. But if you want to learn how to make a virtual piano for Renoise, it is possible to make a very basic tool so that the code is easy to understand and simpler (fewer letters to read).