update copyrights and bump library version
[AROS.git] / test / camdtree.c
blob47bd4bdfac22fc3fd65f4099ec98c225e8335095
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include <proto/exec.h>
8 #include <proto/camd.h>
9 #include <midi/camd.h>
11 #define TABSIZE 4
13 struct Library *CamdBase=NULL;
15 #ifndef GetMidiLinkAttrs
16 ULONG GetMidiLinkAttrs(struct MidiLink *ml, Tag tag, ...){
17 return GetMidiLinkAttrsA(ml, (struct TagItem *)&tag );
19 #endif
21 #ifndef GetMidiAttrs
22 ULONG GetMidiAttrs(struct MidiNode *ml, Tag tag, ...){
23 return GetMidiAttrsA(ml, (struct TagItem *)&tag );
25 #endif
27 struct MidiLink *GetMidiLinkFromOwnerNode(struct MinNode *node){
28 struct MidiLink dummy;
29 return (struct MidiLink *)((char *)((char *)(node)-((char *)&dummy.ml_OwnerNode-(char *)&dummy)));
32 void printSpaces(int level){
33 int lokke;
34 for(lokke=0;lokke<level*TABSIZE;lokke++){
35 printf(" ");
39 void printLink_brancheNodes(struct MidiLink *midilink,int level,int maxlevel);
40 void printLink_brancheClusters(struct MidiLink *midilink,int level,int maxlevel);
41 void printCluster(struct MidiCluster *cluster,int level,int maxlevel);
44 void printNode(struct MidiNode *midinode,int level,int maxlevel){
45 char *nodename=NULL;
46 struct MinNode *node;
48 if(level==maxlevel) return;
50 GetMidiAttrs(midinode,MIDI_Name,(IPTR)&nodename,TAG_END);
52 printSpaces(level);
53 printf(
54 "%p, -%s-\n",
55 midinode,
56 nodename
59 if(level+1==maxlevel) return;
61 if( ! (IsListEmpty((struct List *)&midinode->mi_OutLinks))){
62 printSpaces(level);
63 printf(" -OutLinks:\n");
64 node=midinode->mi_OutLinks.mlh_Head;
65 while(node->mln_Succ!=NULL){
66 printLink_brancheClusters(GetMidiLinkFromOwnerNode(node),level+1,maxlevel);
67 node=node->mln_Succ;
71 if( ! (IsListEmpty((struct List *)&midinode->mi_InLinks))){
72 printSpaces(level);
73 printf(" -InLinks:\n");
74 node=midinode->mi_InLinks.mlh_Head;
75 while(node->mln_Succ!=NULL){
76 printLink_brancheClusters(GetMidiLinkFromOwnerNode(node),level+1,maxlevel);
77 node=node->mln_Succ;
83 BOOL printLink(struct MidiLink *midilink){
84 char *linkname=NULL;
86 if(midilink->ml_Node.ln_Type==NT_USER-MLTYPE_Receiver || midilink->ml_Node.ln_Type==NT_USER-MLTYPE_Sender){
87 GetMidiLinkAttrs(midilink,MLINK_Name,(IPTR)&linkname,TAG_END);
88 printf(
89 "%p, -%s-\n",
90 midilink,
91 linkname
93 return TRUE;
96 printf("%p, <driverdata> (private)\n",midilink);
97 return FALSE;
100 void printLink_brancheNodes(struct MidiLink *midilink,int level,int maxlevel){
101 struct MidiNode *midinode;
103 if(level==maxlevel) return;
105 printSpaces(level);
106 if(printLink(midilink)==TRUE){
107 midinode=midilink->ml_MidiNode;
108 printSpaces(level);
109 printf(" -Owner (MidiNode): \n");
110 printNode(midinode,level+1,maxlevel);
114 void printLink_brancheClusters(struct MidiLink *midilink,int level,int maxlevel){
115 if(level==maxlevel) return;
117 printSpaces(level);
118 printLink(midilink);
120 if(level+1==maxlevel) return;
122 printSpaces(level);
123 printf(" -Cluster: \n");
124 printCluster(midilink->ml_Location,level+1,maxlevel);
128 void printCluster(struct MidiCluster *cluster,int level,int maxlevel){
129 struct MidiLink *midilink;
131 if(level==maxlevel) return;
133 printSpaces(level);
134 printf("clustername: -%s-\n",cluster->mcl_Node.ln_Name);
136 if(level+1==maxlevel) return;
138 if(!(IsListEmpty(&cluster->mcl_Receivers))){
139 printSpaces(level);
140 printf(" ");
141 printf("-Receiver links:\n");
143 midilink=(struct MidiLink *)cluster->mcl_Receivers.lh_Head;
144 while(midilink->ml_Node.ln_Succ!=NULL){
145 printLink_brancheNodes(midilink,level+1,maxlevel);
146 midilink=(struct MidiLink *)midilink->ml_Node.ln_Succ;
150 if(!(IsListEmpty(&cluster->mcl_Senders))){
151 printSpaces(level);
152 printf(" ");
153 printf("-Sender links:\n");
154 midilink=(struct MidiLink *)cluster->mcl_Senders.lh_Head;
155 while(midilink->ml_Node.ln_Succ!=NULL){
156 printLink_brancheNodes(midilink,level+1,maxlevel);
157 midilink=(struct MidiLink *)midilink->ml_Node.ln_Succ;
163 int main(){
165 APTR lock;
166 struct MidiCluster *cluster;
168 CamdBase=OpenLibrary("camd.library",40L);
170 if(CamdBase!=NULL){
172 lock=LockCAMD(CD_Linkages);
174 cluster=NextCluster(NULL);
175 if(cluster==NULL){
177 printf("No clusters available.\n");
179 }else{
181 printf("-Clusters:\n\n");
183 printCluster(cluster,1,6);
184 printf("\n");
185 cluster=NextCluster(cluster);
186 }while(cluster!=NULL);
190 UnlockCAMD(lock);
191 CloseLibrary(CamdBase);
193 }else{
194 printf("Could not open at least V40 of camd.library.\n");
195 return 1;
198 return 0;