-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MidiFx #64
base: main
Are you sure you want to change the base?
MidiFx #64
Conversation
wow, thanks for the contribution @hfnukal |
Sure, I will put some comments. Basically I want to know it anybody interested in MIDI control for MusicBeam. This is working for me. I can improve GUI and doc if there is interest. |
Hi @hfnukal sorry it took me so long to get into this. It was just a lot to wrap my head around, especially since I don't do much Java these days. Before I start, let me say: I absolutely love what you did there! I don't want to get into the code yet, I want to discuss concept first. I do love the idea of having configurable effects. People are often asking if they could write their own effects or are asking for more effects. Having them in a JSON or YAML format would be amazing. Adding MIDI support is also great and was highly requested. Here is my suggestion: Sounds good? Best |
Hi Joe, thanks for answer. I thing this PR has nearly what you request. There is single effect (MusicBeam/Midi_Effect.pde) that implements custom effect implementation. It is configurable by JSON. In MusicBeam/Effect.pde I adjust size of buttons to fit new switch for this effect. there is also implementation of midi messages. In MusicBeam/Strobe_Effect.pde is added mapping for midi messages. You can control controls Strobe_Effect with midi messages. It toggle buttons for effect. It is similar to keyCode mapping. Back to Midi_Effect. There is few buttons for controlling. Most useful is button for reloading configuration also mapped to "§" key. It reload JSON configuration without need to restart app. Draw method cycle in fxBuffer array and draws Fx. Also remove Fx when its finished. Lets describe Fx class. This is root class for effect definition. Basic concept for Fx is, that it has duration. When triggered, it plays some sequence for its duration and than Fx quits. Idea of duration is that 1 is one beat. It is calculated using framerate and BPM. So far BPM is constant. In future it can be detected or passed by midi. To be able to configure Fx, there is GoboFx class. It uses Gobo as basic curve. This curve is then modified by position, rotation and scale from Fx. First attempt was to use it in code. Then I came with JSON configuration. It is then easy to adjust without need of changing code and recompiling. JSON configuration is in MusicBeam/fxconfig.json Here is example of ScreenFx config:
Here comes the fun with Gobos. Gobos are defined separately in the beginning of config file. For easier editing, coordinates are from -100 to 100. Coordinates are vertex point. See example:
LINE_GOBO is line from point -100,0 to 100,0. First and last coordinates are for vertex. See Processing doc https://processing.org/reference/vertex_.html
Once we have gobos defined lets use it with GoboFx:
LineFlyLeft configuration definition. It start on top of screen on left side. No rotation and default scale. End position is in down right corner, rotate full circle and scale to 17. Another GoboFx:
Try to adjust parameters and reload with "§" key. Trigger by key or midi. Here is parabola with smooth rendering. You can try change smooth to nosmooth to see different.
Be careful with edits. So far no JSON checking is implemented so JSON must be valid. You need to restart MusicBeam to recover after attempt to load non valid JSON config. Sometime scaling, rotation and position morphing is not enough. There is possible to add modifiers. Modifiers are inherited from Mod class. See ModRotate for example. Mod class takes 4 parameters and modify any parameter of Fx in mod method. Return modified Fx instance. ModRotate add rotation to path. See Triangel Fx. I hope this explain concept a bit more. You can play with Fx live with midi or keyboard or connect to sequencer (Ableton Live, Logic, Cubase, etc) to get max power of it. |
Hi @hfnukal thanks for the long answer. I think I wasn't clean enough in with my question. I know that everything I am asking for is already implemented in your PR. I did already try it out. |
Oh. I didn't dare to remove existing effects ;)
If you can throw some ideas or preference, it would be great. This is just what was momentary on my mind. |
Currently we only detect beats not BPM. That should be possible though.
Yes. Maybe it makes sense to have one active that is looping, but if you trigger one manually (key/midi) it is only triggered once.
Sequences would be great, but complex to build. I would go with random selection for now. This should keep it simple an you can just run MusicBeam without being a pro.
Would be cool, but also hard to build. I would implement this at a later point too.
JSON is fine, that works for most people. Some things should be configurable thought. Maybe the inputs could be defined in the JSON too?
Maybe defined in the JSON as previously mentioned. You either specify a hard coded value in the JSON or a color input.
That isn't really needed. Line thickness should be always relative to the viewport to yield good looking results.
Very important! I am all for advancing the features, but this is a beginners tool.
Yes. I only want one concept for effects, not many. It is going to be hard to replace some effects with JSON config.
That's going to be the tricky part ;)
I guess so.
I hope this helps. Keep the example simple. Once we nailed the UX and JSON schema, we can go nuts on effects. |
Control MusicBeam effects with midi (or keys)
Run, switch to Midi Effect [0] and try with [asdfghjk] keys.
This is working concept of controlling MusicBeam via MIDI.
So far midi device is hardcoded. You can change it in MusicBeam class.
There is introduced new concept of defining effects. Definition is in fxconfig.json file.
You can define Gobo curve. It is array of vector points in range from -100 to 100.
Curve is defined as array of points under "curves" key fxconfig.json:
"SQUARE_GOBO": [0,100, 100,0, 0,-100, -100,0, 0,100],
See Processing vector() function
"fx" key defines each FX. Combination of gobo, start and stop state, duration and modificators you can create lot of variation of effects.
Fx is sequence that has duration. Duration 1 is one beat of 120 BPM. So far BPM is hardcoded, but ready to be exposed in GUI. start and end defines [x, y, rotation, scale]. To be able to address various resolutions, 0,0 is centre of screen, 1 is top, -1 bottom. Left and right borders depends on projector screen aspect ratio (eg. 16/9). Angle is decimal. For angle 0 is basic position, 1 is full rotation. Scale 1 is basic size, lower then 1 is smaller, greater then one is bigger.
You can use different approach. Most universal is to use GoboFx. GoboFx uses curves and displays it on screen in start position, moving to end position for duration. For GoboFx you need to define gobo. CurveGobo can be smooth or nosmooth, you can define gobo size and shape.
Example of Fx definition:
"PolyCircleGrow": { // name of Fx
"midinote": 49, // Midi note number to trigger Fx
"key": "s", // just for config, not used in code
"keyCode": 83, // keycode to trigger Fx
"FX": { // basic Fx definition
"GoboFx": { // GoboFx uses gobo. You can use custom Fx
"gobo": { // parameter for GoboFx, gobo
"CurveGobo": { // CurveGobo draws lines between points
"curve": "CIRCLE_GOBO", // curve definition for CurveGobo
"gobosize": 0.14, // initial size of Gobo
"nosmooth": null // Use line, smoots use vector
}
},
"hue": 220, // FX parametr for hue
"duration": 4, // duration of fx is 4 beats of 120 BPM
"start": [0, 0, 0, 1], // start position, angle and scale [x, y, angle, scale]) of the gobo in this case
"end": [0, 0, 1, 7] // end position, angle and scale
}
}
},
Description: By note 49 you trigger Fx. It starts with CIRCLE_GOBO, which basic size is 14% of screen defined by gobosize. No smooth draws circle with lines. This draws polygon. It will be visible 4 beats, duration parameter. Start in centre with no rotation and scale 1. Ends in full rotation and scale 7. Collor is defined by hue parameter.
Modificators can dynamically modify path of gobo from start to end. Eg modRotate ads rotation.
You can define you own Fx by extending Fx class.
For each Effect there is midi and key specification. Key midinote defines MIDI Note number, which triggers this Fx. keycode is key code to trigger fx from keyboard (key is required by not used, its for quick reference in configuration).
How I use it:
Run MusicBeamMidiFx and switch to MIDI EFFECT. Then trigger effects by midi messages. I use IAC Driver on Mac to control Fx by Ableton. You can setup IAC Driver in Audio MIDI Setup.app
You can reload config with button on GUI or by pressing "§" key. So its easy to tune your Fx definition.
There is lot of other features, I can describe if there is demand for it.
Some functions:
The MidiBus 8 Library by Severin Smith is required for development.
Good luck, I hope somebody find this useful. Leave me comments, if there is interest I can continue with GUI and so on.