Re: reading Midi from AU
Re: reading Midi from AU
- Subject: Re: reading Midi from AU
- From: Philippe Wicker <email@hidden>
- Date: Sun, 11 Jan 2004 19:35:07 +0100
On Sunday, January 11, 2004, at 06:53 PM, jacques couzteau wrote:
Thank you Marc,
Am 11.01.2004 um 18:14 schrieb Marc Poirier:
But anyway, as to your C++ problem, I think it's just that you're
missing
the static keyword before the function prototype in your class
definition.
you are right on this one as well.
i needed to declare
MIDIPortRef gOutPort;
MIDIEndpointRef gDest;
int gChannel;
outside of my class in order to use it in the static function.
Why can a static memberfunction not access private or public member
variables?
A static method or data member is shared by all the instances of your
class. You don't need to have a pointer or a reference to any instance
to access static members. There's just like "classic" C global
functions or variables, except that they are defined in a name scope
which is the name of your class.
To call a non static method or to access a non static data member you
need a pointer or a reference to a particular instance of the class. A
small example will make it clear.
class A {
public:
void method1();
int member1;
static void method2();
static int member2;
};
To access method1 or member1 you write something like:
A a = new A;
....
a->method1();
int i = a->member1;
....
You need the pointer "a" to the instance to do this.
To access static method2 or member2 you write something like:
A::method2();
int i = A::member2;
In that case you don't need a particular instance. Note that writing:
a->method2();
int i = a->member2;
is also legal in modern C++.
Don't forget that there is always a hidden parameter which is passed to
any non static method. It is called "this" as you probably know. It is
the pointer on the instance on which you make the call. This is why you
can use a non static member within a non static method body either by
typing this->member1 or simply member1.
I thought static just causes the compiler to allocate memory on the
heap instead of the stack for the function an limits it's scope to the
current module. Does it need to be in the same block of memory in order
to access members?
The meaning of static has evolved when C++ was invented. The definition
you give is still valid in C++ but applies to variables declared out of
any scope (this is the C meaning of static).
The memory needed for a static class data member **must** be explicitly
allocated. For instance in the simple example above, you **need** to
write:
int A::member2;
somewhere in a .cpp file otherwise you will get an unresolved reference
at link time.
Does the function need to be static in order to be passed as a
function-pointer to another function?
Yes, because of the hidden "this" parameter for non static methods.
greetz
jacques
Marc
On Sun, 11 Jan 2004, jacques couzteau wrote:
Hello,
I'm trying to enable my AU (derived from SampleEffectUnit) to read
MIDIInput in order to set parameters. I use the SampleTools-Projects
which implements a MIDIEcho in the file echo.cpp as an Example.
There A MIDI-in-port is created with the command MIDIInputPortCreate
from CoreMIDI-Framework with the following Line:
MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL,
&inPort);
In this line the Function E is passed as a FunctionPointer as
argument to MIDIInputPortCreate.
I have added MyReadProc to my SampleEffectKernel so it's definition
looks like:
class SampleEffectKernel : public AUKernelBase{
...
private:
...
void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void
*connRefCon);
...
static void SampleEffectUnit::SampleEffectKernel::MyReadProc(const
MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
...
}
If i use that code in my C++ implementaion of my AU i get compile
problems in the line where i create my MIDIInPort during
instanciation
of my SampleEffectKernel
MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL,
&inPort);
because the use of my MyReadProc doesn't match its definition.
I believe the compiler thinks i want to pass the
(non-existant)return-value of MyReadProc to MIDIInputPortCreate.
Instead of Passing the function that is supposed to process
MIDI-Input.
How do i get this to work?
thank you
jacques
ps: I'm new to c++ so i might be missing something obvious.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
Philippe Wicker
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.