hopefully someone can reply to this (jules?) i won’t start a new thread about it that’d be messy!
i have a midioutput created in my ‘MidiHandler’ class, which gets used by a midilearn class i’ve created. two ‘portselector’ components link to the handler which allow the input and output ports to be selected from those available.
however, i wish for some of my other classes contained in various components to be able to directly send midi messages to the output contained in the midihandler class.
i’d thought about making a new messaging class from the JUCE message bases (so something similar to actionbroadcaster/listener, but specifically for midi messages) so that the midihandler can be a midilistener that will send any messages sent by a midibroadcaster directly to its output port. is this something that is worthwhile? i’d very much like to hear your opinion.
while i’m designing the classes and getting them to work, it is extremely cumbersome to make sure that the objects i want to be able to send messages have a pointer to the output port; it’s only assigned when the program is running, and that means that the midihandler needs to update every other component with the new currently selected midi port pointer… something that is a bitch to do when you’re just trying out ideas.
for now, i’ve simply made a global pointer which gets updated when a port is opened. this saves me the trouble of having to make a pointer updating network for now, as they can directly use this from anywhere. as it’s a port that will be used by the whole program, in “mad person’s theory” it’s quite sensible to have it as a globally accessible pointer. however, understandably “je n’aime pas” having to rely on a global pointer. i guess it’s not SO bad as it wouldn’t compile if it weren’t there, but having classes depend on stuff that may just not exist is a little daunting.
i’d really like to hear your opinion on this jules… perhaps you can give me an idea as to a sensible way to structure the program with regards to midi port access?
at the moment my midi learn system uses ‘targets’ (a base class which can be inherited into any component/class). a target has a virtual function ‘respond(int value)’ which is called by the learner when a learned message is recieved (the target’s pointer is found from a table as 'the right target for this message). a ‘becomeTarget()’ can be called from the object to focus the learner on that object as the destination for the next recieved message; adapting a slider to ‘becomeTarget()’ when it is right clicked means that the next midi message will be automatically mapped to that slider; here, respond() simply sets the value of the slider according to the input midi value.
however i also have a target based class which is to simply generate an output message from a learned input. a table of these targets holds the MCU midi commands, and the learner allows you to map these to input messages - thus when the learned messages are recieved, the command target’s respond() function is called, which should send a message to the selected output port.
hopefully this illustrates my problem?