Discussion:
OK, This newbie is stumped...
(too old to reply)
Charles Turner
2006-07-15 22:58:42 UTC
Permalink
Hi all-

Working on some code to utilize the Component Manager with Carbon
MacForth, and can't figure out where I've gone wrong. Below I attach
source which has some of the Component Manager data and function
declarations and below prior.stream,, some simple code that
demonstrates where I'm stuck.

I wanted to get the number of components, in this case AU output
plug-ins and for all of them on my machine, get their name and info
string. For some reason, when I call _GetComponentInfo a second time,
it returns "zero" plug-ins, it seems because my component description
struct had gotten trashed.

The code is commented, so you should be able to Command-K it and then
step through some lines that will demonstrate my trouble.

Any thoughts on what I'm doing wrong here?

Best and thanks, Charles

- - - - - - - - - - - - - - <snip>- - - - - - - - - - - -

\ Components
\ Created: 07/14/06 10:19:08 PM CWT
\ Last Revision: 07/14/06 10:19:08 PM CWT

(*
*************************************************************************

File: CarbonCore/Components.h

Contains: Component Manager Interfaces.

Version: CarbonCore-677~2

Copyright: © 1991-2005 by Apple Computer, Inc., all rights
reserved.

Bugs?: For bug reports, consult the following page on
the World Wide Web:

http://developer.apple.com/bugreporter/

*************************************************************************
*)

Only Forth Definitions
Decimal

anew --Components--

lacking CoreServices.Framework framework CoreServices.Framework

CoreServices.Framework


STRUCTURE ComponentDescription
LONG: +componentType \ A unique 4-byte code indentifying the
command set
LONG: +componentSubType \ Particular flavor of this instance
LONG: +componentManufacturer \ Vendor indentification
LONG: +componentFlags \ 8 each for
Component,Type,SubType,Manuf/revision
LONG: +componentFlagsMask \ Mask for specifying which flags
\ to consider in search, zero during registration
STRUCTURE.END

(* ******************************************************
* *
* APPLICATION LEVEL CALLS *
* *
******************************************************* *)
(* ******************************************************
* Component Database Add, Delete, and Query Routines
******************************************************* *)

\ * RegisterComponent()
\ * RegisterComponentResource()
\ * UnregisterComponent()

2 machofunc _FindNextComponent ( Component aComponent
ComponentDescription* looking
return Component )

1 machofunc _CountComponents ( ComponentDescription* looking
return long )

5 machofunc _GetComponentInfo ( Component aComponent
ComponentDescription* cd
Handle componentName
Handle componentInfo
Handle componentIcon
return OSErr )

\ * GetComponentListModSeed()
\ * GetComponentTypeModSeed()

(* *******************************************************
* Component Instance Allocation and dispatch routines
******************************************************* *)

2 machofunc _OpenAComponent ( Component aComponent
ComponentInstance* ci
return OSErr )

1 machofunc _OpenComponent ( Component aComponent
return ComponentInstance )

1 machofunc _CloseComponent ( ComponentInstance aComponentInstance
return OSErr )

1 machofunc _GetComponentInstanceError (
ComponentInstance aComponentInstance
return OSErr )

(* *******************************************************
* Component aliases
******************************************************* *)

\ * ResolveComponentAlias()

(* *******************************************************
* Component public resources and public string lists
******************************************************* *)

\ * GetComponentPublicResource()
\ * GetComponentPublicResourceList()
\ * GetComponentPublicIndString()

\ and more...

\ *************** comments and/or test code below ***************
prior.stream

\ ** ENTER all the data definitions between here and the asterisks ****

0 CONSTANT nil

ascii auou constant kAudioUnitType_Output

CREATE MyComponentDescription ComponentDescription ALLOT
kAudioUnitType_Output MyComponentDescription +componentType !
0 MyComponentDescription +componentSubType !
0 MyComponentDescription +componentManufacturer !
0 MyComponentDescription +componentFlags !
0 MyComponentDescription +componentFlagsMask !

VARIABLE componentName 4 _NewHandle componentName !
VARIABLE componentInfo 4 _NewHandle componentInfo !
VARIABLE componentIcon 4 _NewHandle componentIcon !

\ *********************************************************************

\ ENTER these lines one at a time and observe the stack

\ returns the number of kAudioUnitType_Output
MyComponentDescription _CountComponents

\ leaves the address of the first component found on stack
nil MyComponentDescription _FindNextComponent

\ takes address of prev component on stack and finds next
MyComponentDescription _FindNextComponent

\ ...and so on. Leaves 0 when it finds no more
MyComponentDescription _FindNextComponent
MyComponentDescription _FindNextComponent
MyComponentDescription _FindNextComponent
MyComponentDescription _FindNextComponent

\ MyComponentDescription OK
MyComponentDescription 32 CHARS DUMP


\ NOW: ENTER these lines one at a time and observe the stack

\ As above...
MyComponentDescription _CountComponents
nil MyComponentDescription _FindNextComponent

\ DUP the component address because _GetComponentInfo will consume it
DUP

\ Get info. We use nil to remove the influence of the handle defined
above.
\ DROP the return code...
MyComponentDescription nil nil nil _GetComponentInfo DROP

\ Find next component. Why does it return )?
MyComponentDescription _FindNextComponent

\ MyComponentDescription is trashed...
MyComponentDescription 32 CHARS DUMP
Charles Turner
2006-07-15 23:25:49 UTC
Permalink
Hahaha!! NEVERMIND...

It turns out that the call to _GetComponentInfo writes data into the
Component description, so I need one component description to retrieve
the component info data, and one to continue the search with...

Ah, APIs...

:-) Charles
ward mcfarland
2006-07-16 00:04:51 UTC
Permalink
Post by Charles Turner
nil MyComponentDescription _FindNextComponent
\ DUP the component address because _GetComponentInfo will consume it
DUP
\ Get info. We use nil to remove the influence of the handle defined
above.
\ DROP the return code...
MyComponentDescription nil nil nil _GetComponentInfo DROP
\ Find next component. Why does it return )?
MyComponentDescription _FindNextComponent
\ MyComponentDescription is trashed...
MyComponentDescription 32 CHARS DUMP
nil MyComponentDescription _FindNextComponent .s
( 1 ) \ 65558

MyComponentDescription 20 CHARS DUMP
0 1 2 3 4 5 6 7 8 9 A B C D E F
2017CA8: 61 75 6F 75 00 00 00 00 00 00 00 00 00 00 00 00
2017CB8: 00 00 00 00 00 2F FA 4C 00 2F FA 58 00 2F FA 5C

so far, so good.

dup MyComponentDescription nil nil nil _GetComponentInfo .
0 \ no error
MyComponentDescription 20 CHARS DUMP
0 1 2 3 4 5 6 7 8 9 A B C D E F
2017CA8: 61 75 6F 75 61 68 61 6C 61 70 70 6C 10 00 00 00
2017CB8: 00 01 00 16

GetComponentInfo has done what you asked and filled in the fields of
MyComponentDescription

Now, when you use FindNextComponent to look for the next companent of
componentType = 'auou'
componentSubType = 'ahal'
componentManufacturer = 'appl'
componentFlags = 0

It tells you that there is no other component that meets these criteria

Iterate the compnents first, then do GetComponentInfo on each
or reset the fields in MyComponentDescription after doing
GetComponentInfo if you want to get info on each as you go.

-- w
Charles Turner
2006-07-16 12:57:01 UTC
Permalink
Post by ward mcfarland
Iterate the compnents first, then do GetComponentInfo on each
or reset the fields in MyComponentDescription after doing
GetComponentInfo if you want to get info on each as you go.
Yeah, I figured this out (how typical!) MINUTES after my post. I chose
to define two component descriptors, one for the search and one for the
info, and keep the component address on the stack...

Hope you didn't spend more than a nanosecond replying, but thanks, it's
comforting to know a reply would have been waiting for me if the
lightning hadn't struck. ;-)

Best, Charles
ward mcfarland
2006-07-16 14:07:38 UTC
Permalink
Post by Charles Turner
Yeah, I figured this out (how typical!) MINUTES after my post.
Posting a request for help is often like making an appointment with the
dentist - suddenly, everything gets better ;-)
Charles Turner
2006-07-16 17:40:01 UTC
Permalink
Post by ward mcfarland
Posting a request for help is often like making an appointment with the
dentist - suddenly, everything gets better ;-)
Hahaha!! (Put your drill away, Ward!)

Loading...