From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!news2.arglkargh.de!news.mixmin.net!aioe.org!not-for-mail From: John McCabe Newsgroups: comp.lang.ada Subject: This MIDI stuff, would someone be interested in reviewing my code? Date: Mon, 08 Mar 2010 11:40:16 +0000 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: RXEkuaSUwmKe0XIGFYSK7A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 2.0/32.652 Xref: g2news1.google.com comp.lang.ada:9462 Date: 2010-03-08T11:40:16+00:00 List-Id: Hi It's still early days but, if I'm going to be using Ada to try to build this app I want, it would be nice to write it in a style that looks appropriate. I'm aware of the Q&S guide but I was hoping that someone could take a quick look at the code I've written (it's only 80 lines or so, and it's down below) and see if there's anything obviously stupid I'm doing. My specific thoughts on this are: 1) Perhaps I should be using limited withs in some places to get access to the primitive operators/functions of the stuff in Interfaces.C/.strings and Win32 etc. 2) The for loops: for devId in Win32.UINT range 0..(NumOutputDevices - 1) etc. These are protected by a "if NumOutputDevices < 0" condition but before I realised my mistake I found that when NumOutputDevices is 0, the loop executes as many times as it can before it crashed. This was obviously because NumOutputDevices was 0, so the range "0..(NumOutputDevices - 1)" was 0..4929blahblah due to Win32.UINT being a modular type. I looked at the option to use something like: for index in Win32.UINT range 1..NumOuputDevices loop declare devId : Win32.UINT := index - 1; begin ... end; end loop; but stuck with the original with the conditional round it. 3) Would it be more appropriate to use something like Win32.UINT'Image() instead of getting an instantiation of the Modular_IO package? Anyway - thanks to anyone who can be bothered to look at this. It will be much appreciated, and thanks for everyone's help so far. John =================== with Ada.Text_IO; with Ada.Unchecked_Deallocation; with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; use Interfaces.C.Strings; with Win32; use Win32; with Win32.Mmsystem; use Win32.Mmsystem; procedure MidiDevs is NumInputDevices : Win32.UINT; NumOutputDevices : Win32.UINT; res : Win32.Mmsystem.MMRESULT; midiInCaps : Win32.Mmsystem.LPMIDIINCAPS; midiOutCaps : Win32.Mmsystem.LPMIDIOUTCAPS; package UINTText_IO is new Ada.Text_IO.Modular_IO(Win32.UINT); package MMText_IO is new Ada.Text_IO.Modular_IO(Win32.Mmsystem.MMRESULT); procedure Free is new Ada.Unchecked_Deallocation(Win32.Mmsystem.MIDIINCAPS, Win32.Mmsystem.LPMIDIINCAPS); procedure Free is new Ada.Unchecked_Deallocation(Win32.Mmsystem.MIDIOUTCAPS, Win32.Mmsystem.LPMIDIOUTCAPS); begin NumInputDevices := Win32.Mmsystem.midiInGetNumDevs; NumOutputDevices := Win32.Mmsystem.midiOutGetNumDevs; midiInCaps := new Win32.Mmsystem.MIDIINCAPS; midiOutCaps := new Win32.Mmsystem.MIDIOUTCAPS; Ada.Text_IO.Put("There are "); UINTText_IO.Put(NumInputDevices, 0); Ada.Text_IO.Put(" input devices available, and "); UINTText_IO.Put(NumOutputDevices, 0); Ada.Text_IO.Put_Line(" output devices available."); if NumInputDevices > 0 then Ada.Text_IO.New_Line; Ada.Text_IO.Put("The "); UINTText_IO.Put(NumInputDevices, 0); Ada.Text_IO.Put_Line(" input devices are:"); Ada.Text_IO.New_Line; for devId in Win32.UINT range 0..(NumInputDevices - 1) loop res := Win32.Mmsystem.midiInGetDevCaps(devId, midiInCaps, (Win32.Mmsystem.MIDIINCAPS'size * Win32.BYTE'size)); UINTText_IO.Put(devId, 0); Ada.Text_IO.Put(") "); if res = Win32.Mmsystem.MMSYSERR_NOERROR then Ada.Text_IO.Put("szPname = "); Ada.Text_IO.Put_Line(To_Ada(To_C(midiInCaps.szPname))); else Ada.Text_IO.Put("Query Failed. Returned "); MMText_IO.Put(res, 0); end if; Ada.Text_IO.New_Line; end loop; end if; if NumOutputDevices > 0 then Ada.Text_IO.New_Line; Ada.Text_IO.Put("The "); UINTText_IO.Put(NumOutputDevices, 0); Ada.Text_IO.Put_Line(" output devices are:"); Ada.Text_IO.New_Line; for devId in Win32.UINT range 0..(NumOutputDevices - 1) loop res := Win32.Mmsystem.midiOutGetDevCaps(devId, midiOutCaps, (Win32.Mmsystem.MIDIOUTCAPS'size * Win32.BYTE'size)); UINTText_IO.Put(devId, 0); Ada.Text_IO.Put(") "); if res = Win32.Mmsystem.MMSYSERR_NOERROR then Ada.Text_IO.Put("szPname = "); Ada.Text_IO.Put_Line(To_Ada(To_C(midiOutCaps.szPname))); else Ada.Text_IO.Put("Query Failed. Returned "); MMText_IO.Put(res, 0); end if; Ada.Text_IO.New_Line; end loop; end if; Free(midiInCaps); Free(midiOutCaps); end MidiDevs;