Midi Activity Led
-
This still appears to be broken. I've made a test project using Greg's snippet and images.
-
@d-healey Bump.
-
@d-healey I've made some progress on this in
FrontendPanelTypes
, and it seems the images are somehow not loaded properly.
If I just paint the background with a colour it works:void ActivityLedPanel::paint(Graphics &g) { g.fillAll(isOn ? Colours::red : Colours::black); // THIS WORKS g.setFont(getFont()); if (showMidiLabel) g.drawText("MIDI", 0, 0, 100, getHeight(), Justification::centredLeft, false); if (auto img = isOn ? on.getData() : off.getData()) // maybe getData() doesn't works or the problem is in the header... { g.drawImageWithin(*img, showMidiLabel ? 38 : 2, 2, 24, getHeight(), RectanglePlacement::centred); } }
-
-
@Christoph-Hart Need a wee bit of help trying to upgrade the
ActivityLedPanel
for using a custom path instead of an image...I got it to work when loading a path directly in the constructor but I get an
'Array<juce::var>' to 'const void *'
conversion issue when I want to load the path from theData
object:void ActivityLedPanel::fromDynamicObject(const var& object) { FloatingTileContent::fromDynamicObject(object); showMidiLabel = getPropertyWithDefault(object, (int)SpecialPanelIds::ShowMidiLabel); useMidiPath = getPropertyWithDefault(object, (int)SpecialPanelIds::UseMidiPath); auto data = getPropertyWithDefault(object, SpecialPanelIds::MidiIconPathData); if (data.isArray()) { midiIconData.clear(); midiIconData.addArray(*data.getArray()); } midiIconPath.loadPathFromData (midiIconData, sizeof(midiIconData)); // -> No viable conversion from 'Array<juce::var>' to 'const void *' }
Declared in class as:
===== class ActivityLedPanel ====== private: Array<var> midiIconData;
Trying this gives the same error
midiIconData = getPropertyWithDefault(object, (int)SpecialPanelIds::MidiIconPathData); midiIconPath.loadPathFromData (midiIconData, sizeof(midiIconData));
-
@ustk Have you tried an explicit cast (if relevant)?
-
@clevername27 Thanks, but could you enlight me with this please, I'm noob in C++
-
@clevername27 well I think I see what you mean but I don't know exactly how to write it...
something like
const_cast<blabla>(midiIconData)
maybe?EDIT:
tried this with no luck
const void *mid = midiIconData; midiIconPath.loadPathFromData (&mid, sizeof(&mid));
and same with this
midiIconPath.loadPathFromData (const_cast<const void *>(midiIconData), sizeof(const_cast<const void *>(midiIconData)));
-
@ustk @Christoph-Hart Could this be the cause of the issue?
-
@d-healey I don't think so. In fact I had it working and I can draw anything like an ellipse for instance. But I stopped because I don't know how to draw a path which I thought would have been more trivial...
In fact I'd like to put a path in the data property so we don't need an image. I have made pretty much all the necessary modifications but got stuck at one point and I don't have much time atm.
This gives an idea if you want to give it a go:
-
@d-healey In the end it would be even better if we can set a path from API like
FloatingTile.setPath(path)
but that would be even harder to implement. So placing it in the data property might still be a good workaround, but not a conventional one I confess. -
@ustk It won't work like that. The load path from data expects a consecutive memory block of 8bit integers (
char
oruint8
) and thevar
type is much bigger so casting a pointer will make it interpret garbage.If you're converting the path with the SVG converter in HISE you also get the ability of using a Base64 encoded string instead of the number array (which is recommended anyway because it will be shorter so the Javascript parser has much less to do in the onInit BTW). With this string it could work, then all you need to do is to create a MemoryBlock and parse the Base64 string
var propertyFromJSON("2124.dlaklasdf8laksdjh32fkaldshfasjdfsfd"); String funkyPath = propertyFromJSON.toString(); MemoryBlock mb; mb.fromBase64Encoding(funkyPath); Path p; p.loadPathFromData(mb.getData(), mb.getSize());
otherwise you would have to convert it to a new
Array<uint8>
manually by iterating over theArray<var>
and push each value after casting it to auint8
. Then you can useArray<uint8>::getRawDataPointer()
to get a pointer to the byte-aligned data for the path. -
@Christoph-Hart awesome! I'll give this a second chance then :)
-
@Christoph-Hart Alright so I'm trying this direct approach in the paint routine to "get more chance" but I feel idiot it does not work...
Maybe I need to scale the path... Please bring me to school Chris :)
if (useMidiPath) { //var propertyFromJSON(base64MidiPath); var propertyFromJSON("678.t0V8.ZBQPJkgCIFl3+AQPJkgC0ipZPDQuC4P8npFD4++cNjX8npFDoKDqNDl3+AQt0ZsCUOflPjasV6PhIUBsPjasV6PsdkLDoKDqNDqWICQ9+emCIVqWICQD8NjCIUBsPDjRY3P0CnIDAoTFNzXsUOflPDzWg3PhIQerPDzWg3PhLULDY7ARNjHSECQ9+emCIlHSECQ3fepCIQerPjKnN6P0CnID4BpyNjXYSHHD4BpyNj2rtAQ3fepC4MqaPj++24Ph4MqaPjwGH4PYSHHDA8UHNT8.ZBQPeEhCMVa0CnIDMqWuMjXBJxGDMqWuMzV8cAQBsRfC05oQPD3Np3Ph4ezKPTexO4PMi7ADk1UcNTyHe.QocUmCwF..d.Q..fmCwVyHe.QXhpmCIVyHe.QXhpmC4ezKPzfMf5PsdZDDARbwNjXa02ED4K05Njfh7AQmBEwCUOflPjoPQ7Phg12sPjoPQ7PjJXMD4K05NzTXsCQfDWrCIl.tDDQD1.pCMyMEQDln54PybSQDgIpdNDa..XQDA..dNDaybSQDk1UcNjXybSQDk1UcNj.tDDQ8I+jCMEV6PD3Np3PhQpf0PjPqD3Po8cKDMqWuMj8.ZBQy50aCMVa0CnIDQSZyMjXP5VKDQSZyMzFzSCQRHtfCwWs5Pz.kv3Ph4oP.Qz3ST4P5R8PDgKXcNDvYPDQ9+emCIltTODQD8omC4oP.QjFra5P7UqNDou1uNjXaPOMDsdG4NDjt0BQNdjvCUOflPjiGI7Phs0jePjiGI7Pju.FDsdG4NDgJIAQ5q8qCIVX8x.QavtoCUzJIPjQe54P+XNBD4++cNjXEsRBDkKXcNTX8x.QiOQkCQnRRPDAkv3PhQ9BXPjDhK3PaM4GDUSZyMT8.ZBQ0j1bCMVY"); String midiIconPath = propertyFromJSON.toString(); MemoryBlock mb; mb.fromBase64Encoding(midiIconPath); Path p; p.loadPathFromData(mb.getData(), mb.getSize()); g.fillPath(p); } else g.fillEllipse(getWidth()-getHeight(), 0, getHeight(), getHeight());
-
Oh wait I almost got it to work! I forgot to scale the path in the resized function...
But it looks a bit weird for now so stay tuned -
Gotcha!
-
@d-healey @clevername27 @Christoph-Hart Pull Request made
https://github.com/christophhart/HISE/pull/374 -
-
@ustk @Christoph-Hart If interested, I posted an efficient, working and configurable MIDI indicator widget a couple months back.