[sdiy] OT (but very synthy): C question
Tim Daugard
daugard at cox.net
Tue Mar 29 16:57:54 CEST 2011
> lfo.h:
>
> #ifndef PATH_TO_LFO_H_
> #define PATH_TO_LFO_H_
>
> /* We only need a forward declaration here, no need to include the
I use LFO_H_ because it's easy to remember. A declaration xxx_H_
is only defined in the header file that contains it. That way any
file that needs that function can include it. I.E.
[file LFO.h]
#ifndef LFO_H_ // has this file been called before?
#define LFO_H_ // first time through
. . .
// we need midi data
#ifndef MIDI_H_
#include "MIDI.h"
#endif
. . .
now we can set up what we need that uses MIDI.h
. . .
> full MIDI declaration */
> typedef struct MIDI MIDI;
>
> struct LFO {
> uint32_t phase_;
> };
>
> void process_lfo(LFO* lfo, MIDI* midi);
>
> #endif /* PATH_TO_LFO_H_ */
> midi.h:
>
> #ifndef PATH_TO_MIDI_H_
> #define PATH_TO_MIDI_H_
>
> /* Includes in headers are bad, but there's no other option here
> because MIDI_MESSAGE
> can be left as an incomplete type - we must know what it is made of to
> know
> the right size of the MIDI struct */
> #include "midi_message.h"
>
> /* We only need a forward declaration here, no need to include the
> full LFO declaration */
> typedef struct LFO LFO;
>
> struct MIDI {
> uint8_t running_status_;
> uint8_t data_[8]; /* whatever */
> MIDI_MESSAGE last_message_;
> };
and then the big question is why are we processing
midi and LFO in the MIDI header?
>
> void process_midi(MIDI* midi, LFO* lfo);
This should be at a higher level either the main.c
or a sub-level that includes both MIDI.h and LFO.h.
>
> #endif /* PATH_TO_MIDI_H_ */
Tim Daugard
AG4GZ 30.4078N 86.6227W Alt: 12 feet above MSL
http://members.cox.net/synthfred/h_toctop.htm (Fred's online edition)
More information about the Synth-diy
mailing list