Prev: Presentations on-line - Ada&SPARK for Education&Research
Next: Thinking of using Ada for a job at home. Couple of questionsfirst.
From: John McCabe on 3 Mar 2010 11:19 Guys I was hoping you'd be able to help me. Some of this I could probably find out by re-reading my books but I'm sure this is the sort of thing some of you guys are doing every day so could probably give a clearer answer. The other one, I just don't know and a search on Google was a bit useless. Basically I have a synthesizer that's not very well supported on the software front, mainly because not many of them were sold and built. I'd like to create an application that runs on MS Windows, probably using Qt that will be able to manage, dump, load patches etc using MIDI. So the first question is do any of you know of any bindings to MS Windows MIDI (presumably the multimedia system) functions that already exist and are open source or something like that? I searched on Google for "ada midi" but it looks like there's a product called that so it came up with loads of stuff. I'm aware there are some binding to Win32 from Ada but, as I've not been doing Ada in anger for a long time, I'm not sure if there's something for Ada 2005. The second question is related to the implementation of the System Exclusive messages. Basically this is part of the reason I thought Ada would be good for this task. The SysEx messages basically consist of a smallish header and a variety of different structures that are differentiated by the "Function" type in the header. Now I seem to remember from when I did use Ada that it's possible to define the record representation of a variant record such that the discriminant is held within the body of the record. This would mean (I think) that I could read a block of data from the synthesizer straight in to a buffer that overlaid the variant record and essentially automatically created a record that could be read as the particular variant related to the incoming data. However I also seem to remember that's not quite a 'recommended' way of doing that sort of thing. The other thing that guided me in Ada's direction is that the structure of the SysEx messages requires a lot of bit-fields and I'm well aware that Ada's representation clauses are fantastic for that sort of thing. So, in principle, would that be the way to do this, or would you be able to suggest a better mechanism? Finally, is there a straightforward way to do that sort of thing using tagged records? E.g. could I define a record which is the header format, then extend that in a number of different tagged extensions to create each individual message as a separate tagged record and use the OO and dispatching facilities to work with them? Any advice you've got the time to give on this would be very much appreciated. John
From: Dmitry A. Kazakov on 3 Mar 2010 14:17 On Wed, 03 Mar 2010 16:19:31 +0000, John McCabe wrote: > So the first question is do any of you know of any bindings to MS > Windows MIDI (presumably the multimedia system) functions that already > exist and are open source or something like that? I searched on Google > for "ada midi" but it looks like there's a product called that so it > came up with loads of stuff. I'm aware there are some binding to Win32 > from Ada but, as I've not been doing Ada in anger for a long time, I'm > not sure if there's something for Ada 2005. I vaguely remember that there is no proper API for that (either in Ada or in C). It is communicated over the Windows messages or worse at the process level. I don't remember. Anyway if there exists proper C API, there is no problem to convert it to Ada. It is a matter of a pair minutes of work. > So, in principle, would that be the way to do this, or would you be > able to suggest a better mechanism? In practice that usually does not work well. The approach I am using is reading the octet stream or else what is natural for the device or the protocol at hand, and then constructing the necessary Ada objects on the fly. I don't mess with representation clauses. If 100 nanoseconds overhead impose a serious performance problem to your program it won't work anyway. And under Windows we are talking about 1ms jitter at least. So no reason to worry about that. > Finally, is there a straightforward way to do that sort of thing using > tagged records? Yes, as above. This is the way I usually do it. > E.g. could I define a record which is the header > format, then extend that in a number of different tagged extensions to > create each individual message as a separate tagged record and use the > OO and dispatching facilities to work with them? No, why do you need message objects? What for? Once a message is received and interpreted there is no need to keep it in any form, so to have a Message type [or an hierarchy of]. Instead of that you create a tagged Connection type, with primitive higher-level operations invoked by the driver as it reads incoming messages. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: John McCabe on 3 Mar 2010 15:09 Hi Jeff "Jeffrey R. Carter" <spam.jrcarter.not(a)spam.acm.org> wrote: >John McCabe wrote: >> >> The second question is related to the implementation of the System >> Exclusive messages. Basically this is part of the reason I thought Ada >> would be good for this task. The SysEx messages basically consist of a >> smallish header and a variety of different structures that are >> differentiated by the "Function" type in the header. Now I seem to >> remember from when I did use Ada that it's possible to define the >> record representation of a variant record such that the discriminant >> is held within the body of the record. This would mean (I think) that >> I could read a block of data from the synthesizer straight in to a >> buffer that overlaid the variant record and essentially automatically >> created a record that could be read as the particular variant related >> to the incoming data. However I also seem to remember that's not quite >> a 'recommended' way of doing that sort of thing. The other thing that >> guided me in Ada's direction is that the structure of the SysEx >> messages requires a lot of bit-fields and I'm well aware that Ada's >> representation clauses are fantastic for that sort of thing. >> >> So, in principle, would that be the way to do this, or would you be >> able to suggest a better mechanism? > >That is the way I would approach this, though I might keep the buffer and record >separate and use Unchecked_Conversion. Thanks for taking the time to answer that. The Unchecked_Conversion option was the other thing I was thinking of. >I can't tell you whether the tagged approach would work, because programming by >extension is a bad idea, and I avoid it whenever possible. It's a good laugh though, and can be a useful think to know about if your work doesn't involve anything that needs to be particularly fast, reliable or safe :-}
From: John McCabe on 3 Mar 2010 15:17 Hibou57 (Yannick Duch�ne) <yannick_duchene(a)yahoo.fr> wrote: >Le Wed, 03 Mar 2010 17:19:31 +0100, John McCabe ><john(a)nospam.assen.demon.co.uk> a �crit: >Hello, >> So the first question is do any of you know of any bindings to MS >> Windows MIDI (presumably the multimedia system) functions that already >> exist and are open source or something like that? I searched on Google >> for "ada midi" but it looks like there's a product called that so it >> came up with loads of stuff. I'm aware there are some binding to Win32 >> from Ada but, as I've not been doing Ada in anger for a long time, I'm >> not sure if there's something for Ada 2005. >If there are possible funding, I would enjoy to re-organize my time to >honor this target under whatever license you may request. Unfortunately there's not funding available. I've found a library called libjdkmidi that, if it would look easier to bind to than direct to Win32's mmsystem functions, might be worth doing. I suspect though that it encapsulates some of the functionality you mention later in relation to tasking etc, although I haven't looked that closely yet. >If you ever you are interested in another stuff in the same area, I've >also started some times ago, but not terminated, an Ada binding to the VST >architecture. I've temporarily dropped the project for an undetermined >amount of time, because I need a project which could give me some earn. I >can't give a date, however, I'm pretty sure I will come back to it in the >future (at least, I hope I could) Thanks, I'll bear that in mind. >> The second question is related to the implementation of the System >> Exclusive messages. Basically this is part of the reason I thought Ada >> would be good for this task. The SysEx messages basically consist of a >> smallish header and a variety of different structures that are >> differentiated by the "Function" type in the header. Now I seem to >> remember from when I did use Ada that it's possible to define the >> record representation of a variant record such that the discriminant >> is held within the body of the record. This would mean (I think) that >> I could read a block of data from the synthesizer straight in to a >> buffer that overlaid the variant record and essentially automatically >> created a record that could be read as the particular variant related >> to the incoming data. However I also seem to remember that's not quite >> a 'recommended' way of doing that sort of thing. >Excuse me, I'm not sure I've understood your words. Could you give a >concrete example of a process ? Well basically you define a variant record that contains variants that apply to all the SysEx messages then (dodgily) locate a buffer (e.g. of bytes, integers, whatever) in the same place and write the incoming data in to the buffer. When you come to read it later as a record object rather than just as bytes it's essentially a valid variant record (at least, I believe from what I remember that it is!). I think Jeff's Unchecked_Conversion is a more appropriate way to do it though. >Just to tell about what immediately comes into my mind : I'm not sure >variant record would be Ok for whole MIDI data sequences, as it comes into >sequence and not as a single block. The content of some MIDI messages are >splitted into multiple units which comes as a sequence. A variant record, >to be coherent, must be a whole, you cannot have something related to a >discriminant which remains dangling until some more data later arrives. The application I'm trying to do is a patch editor so it will essentially deal only with expected messages that are sent from the synth in response to requests. I don't think the synth intersperses any other midi data within those messages. It's a Kawai K1 by the way. >All this comment provided I've understood a bit of what you were to mean >(I apologize if I'm wrong). No need to apologise; if it's not clear to you then I'm sure there are others in the same position. >> The other thing that >> guided me in Ada's direction is that the structure of the SysEx >> messages requires a lot of bit-fields and I'm well aware that Ada's >> representation clauses are fantastic for that sort of thing. >Another reason to use Ada : Ada is also a good choice in this area, due to >its tasking capabilities. This kind of application typically heavily >relies on multiple tasks (and even more heavily if you have to deal with >multiple synthesizers, what is a common case) I don't need to deal with multiple synthesizers but yes, the tasking was another reason Ada sounded appropriate as the synth sends all sorts of junk while it's idling that I need to be able to receive and just dump, and I need a GUI as well. >> So, in principle, would that be the way to do this, or would you be >> able to suggest a better mechanism? >> >> Finally, is there a straightforward way to do that sort of thing using >> tagged records? E.g. could I define a record which is the header >> format, then extend that in a number of different tagged extensions to >> create each individual message as a separate tagged record and use the >> OO and dispatching facilities to work with them? >I gonna go back to my docs to remind me about what's the layout of these >messages exactly. > >> Any advice you've got the time to give on this would be very much >> appreciated. >You're welcome Thanks for taking the time to respond. Hope I've made it a little clearer but if not, just let me know.
From: John McCabe on 3 Mar 2010 15:38
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote: >> So, in principle, would that be the way to do this, or would you be >> able to suggest a better mechanism? > >In practice that usually does not work well. The approach I am using is >reading the octet stream or else what is natural for the device or the >protocol at hand, and then constructing the necessary Ada objects on the >fly. I don't mess with representation clauses. If 100 nanoseconds overhead >impose a serious performance problem to your program it won't work anyway. >And under Windows we are talking about 1ms jitter at least. So no reason to >worry about that. Thanks for that suggestion. >> E.g. could I define a record which is the header >> format, then extend that in a number of different tagged extensions to >> create each individual message as a separate tagged record and use the >> OO and dispatching facilities to work with them? > >No, why do you need message objects? What for? Once a message is received >and interpreted there is no need to keep it in any form, so to have a >Message type [or an hierarchy of]. Instead of that you create a tagged >Connection type, with primitive higher-level operations invoked by the >driver as it reads incoming messages. Well the data coming in represents synth patches, which I want to be able to save to a file (as raw bytes in a SysEx format - not sure if it's standard or not, but I've seen quite a few of them), or manipulate, or load back in or dump back to the synth. Essentially I want to be able to keep the patches in some format or other, because you can load a bank of patches at a time. The header though doesn't apply to a patch, it applies to a message. So you can load one patch in which you case you put a header on it and send it out, or a set of patches in which case you put on one header then send multiple patches. As for the tagged Connection type, I'm not sure what you mean. Would you mind elaborating on that please? BTW - in case anyone's interested, the MIDI format for the synth I'm interested in is defined at: http://www.kawaius-tsd.com/OM/K_SYNTH/K1WAVE~1.PDF |