9 struct annotation
* annotations
= NULL
;
11 struct annotation
* current_annotation
= NULL
;
13 struct annotation
* selected_annotation
= NULL
;
15 // find the last annotation before this frame (if any)
16 struct annotation
* annotationAt(jack_nframes_t frame
)
18 struct annotation
* current
= annotations
;
19 struct annotation
* previous
= NULL
;
20 while (current
!= NULL
)
22 if (current
->frame
> frame
)
27 current
= current
->next
;
32 void addannotation(struct annotation
* annotation
)
34 struct annotation
* previous
= annotationAt(annotation
->frame
);
37 annotation
->next
= annotations
;
38 annotations
= annotation
;
42 annotation
->prev
= previous
;
43 if (previous
->next
!= NULL
)
45 previous
->next
->prev
= annotation
;
47 previous
->next
= annotation
;
49 selected_annotation
= annotation
;
52 void createannotation(jack_nframes_t frame
, int indentation
, char* text
)
54 struct annotation
* new_annotation
= (struct annotation
*) malloc(sizeof(struct annotation
));
55 new_annotation
->frame
= frame
;
56 new_annotation
->indentation
= 0;
57 new_annotation
->text
= text
;
58 new_annotation
->next
= NULL
;
59 new_annotation
->prev
= NULL
;
60 addannotation(new_annotation
);
64 void editannotation(jack_client_t
* client
)
66 if (selected_annotation
== NULL
)
68 mvprintw(0,0,"Enter text for this annotation: ");
70 getnstr(selected_annotation
->text
, size
);
75 void newannotation(jack_client_t
* client
)
77 jack_nframes_t frame
= transport_refresh(client
);
78 char* text
= (char*) malloc(size
* sizeof(char));
79 mvprintw(0,0,"Enter text for new annotation: ");
85 createannotation(frame
, 0, text
);
90 bool quitRequested
= false;
91 jack_client_t
* client
= jack_client_open("sannot", JackNullOption
, NULL
);
94 fprintf(stderr
, "could not create JACK client\n");
98 // Main loop: when a command is entered or when the jack transport reaches
99 // a new annotation, handle this and refresh the screen.
101 refresh_ui(transport_refresh(client
));
102 while (!quitRequested
)
104 struct annotation
* new_annotation
= annotationAt(transport_refresh(client
));
105 refresh_ui(transport_refresh(client
));
106 if (new_annotation
!= current_annotation
)
108 current_annotation
= new_annotation
;
109 refresh_ui(transport_refresh(client
));
111 // waits for the next command - times out if none arrives, so
112 // we can check if we need to view another annotation. At some point we
113 // might want to implement this as a 'real' multi-threaded event loop, but
114 // for now this should do fine.
115 switch (getCommand())
120 quitRequested
= true;
123 transport_start(client
);
126 transport_stop(client
);
128 case toggle_startstop
:
129 transport_toggle(client
);
131 case transport_rewind
:
132 transport_move(client
, -40000);
134 case transport_forward
:
135 transport_move(client
, 40000);
138 transport_moveto(client
, 0);
141 editannotation(client
);
142 refresh_ui(transport_refresh(client
));
145 newannotation(client
);
146 refresh_ui(transport_refresh(client
));
149 if (selected_annotation
!= NULL
&& selected_annotation
->prev
!= NULL
)
150 selected_annotation
= selected_annotation
->prev
;
153 if (selected_annotation
!= NULL
&& selected_annotation
->next
!= NULL
)
154 selected_annotation
= selected_annotation
->next
;
157 if (selected_annotation
!= NULL
)
158 selected_annotation
->indentation
++;
161 if (selected_annotation
!= NULL
&& selected_annotation
->indentation
> 0)
162 selected_annotation
->indentation
--;
169 jack_client_close(client
);