atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_sequencer.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'w_sequencer.c'
24*
25* Contains:
26*
27
28 - The functions to create the MD sequencer window
29
30*
31* List of functions:
32
33 static gboolean animate (gpointer data);
34 static gboolean seq_wait_for_stop (gpointer data);
35
36 void set_player_title (glwin * view);
37 void update_selection (glwin * view, int o_step);
38 void update_step_button (glwin * view);
39 void sequence (glwin * view, int o_step, int n_step);
40
41 G_MODULE_EXPORT void seq_go_previous (GtkButton * but, gpointer data);
42 G_MODULE_EXPORT void seq_go_next (GtkButton * but, gpointer data);
43 G_MODULE_EXPORT void seq_go_first (GtkButton * but, gpointer data);
44 G_MODULE_EXPORT void seq_go_last (GtkButton * but, gpointer data);
45 G_MODULE_EXPORT void seq_go_to (GtkEntry * res, gpointer data);
46 G_MODULE_EXPORT void seq_jump (GtkButton * but, gpointer data);
47 G_MODULE_EXPORT void seq_play (GtkButton * but, gpointer data);
48 G_MODULE_EXPORT void seq_stop (GtkButton * but, gpointer data);
49 G_MODULE_EXPORT void seq_loop (GtkButton * but, gpointer data);
50 G_MODULE_EXPORT void seq_faster (GtkButton * but, gpointer data);
51 G_MODULE_EXPORT void seq_slower (GtkButton * but, gpointer data);
52 G_MODULE_EXPORT void window_sequencer (GtkWidget * widg, gpointer data);
53
54*/
55
56#include "global.h"
57#include "interface.h"
58#include "callbacks.h"
59#include "glview.h"
60#include "glwindow.h"
61
70{
71 int step = view -> anim -> last -> img -> step + 1;
72 gchar * str = g_strdup_printf ("%s - player - step %d", prepare_for_title (get_project_by_id(view -> proj) -> name), step);
73 gtk_window_set_title (GTK_WINDOW(view -> player -> win), str);
74 g_free (str);
75}
76
85void update_selection (glwin * view, int o_step)
86{
87 int i, j, k;
88 i = view -> anim -> last -> img -> step;
89 project * this_proj = get_project_by_id(view -> proj);
90 for (k=0; k<2; k++)
91 {
92 view -> anim -> last -> img -> selected[k] -> selected = 0;
93 view -> anim -> last -> img -> selected[k] -> first = NULL;
94 view -> anim -> last -> img -> selected[k] -> last = NULL;
95 for (j=0; j<this_proj -> natomes; j++)
96 {
97 if (this_proj -> atoms[o_step][j].pick[k])
98 {
99 this_proj -> atoms[i][j].pick[k] = FALSE;
100 process_selected_atom (this_proj, view, j, 0, 0, k);
101 }
102 if (this_proj -> atoms[o_step][j].label[k])
103 {
104 this_proj -> atoms[i][j].label[k] = TRUE;
105 }
106 }
107 update_all_selections (view, k);
108 }
109}
110
119{
120 if (view -> anim -> last -> img -> step == get_project_by_id(view -> proj) -> steps - 1)
121 {
122 widget_set_sensitive (view -> player -> first, 1);
123 widget_set_sensitive (view -> player -> prev, 1);
124 widget_set_sensitive (view -> player -> last, 0);
125 widget_set_sensitive (view -> player -> next, 0);
126 }
127 else if (view -> anim -> last -> img -> step == 0)
128 {
129 widget_set_sensitive (view -> player -> first, 0);
130 widget_set_sensitive (view -> player -> prev, 0);
131 widget_set_sensitive (view -> player -> last, 1);
132 widget_set_sensitive (view -> player -> next, 1);
133 }
134 else
135 {
136 widget_set_sensitive (view -> player -> first, 1);
137 widget_set_sensitive (view -> player -> prev, 1);
138 widget_set_sensitive (view -> player -> last, 1);
139 widget_set_sensitive (view -> player -> next, 1);
140 }
141}
142
152void sequence (glwin * view, int o_step, int n_step)
153{
154 int i;
155 for (i=0; i<2; i++) save_all_selections (view, i);
156 view -> anim -> last -> img -> step = n_step;
157 update_selection (view, o_step);
158 for (i=0; i<NGLOBAL_SHADERS; i++)
159 {
160 if (in_md_shaders (get_project_by_id(view -> proj), i)) view -> n_shaders[i][n_step] = -1;
161 }
163 set_player_title (view);
164 update_step_button (view);
165 update (view);
166}
167
176G_MODULE_EXPORT void seq_go_previous (GtkButton * but, gpointer data)
177{
178 glwin * view = (glwin *) data;
179 if (view -> anim -> last -> img -> step > 0)
180 {
181 sequence (view, view -> anim -> last -> img -> step, view -> anim -> last -> img -> step - 1);
182 }
183}
184
193G_MODULE_EXPORT void seq_go_next (GtkButton * but, gpointer data)
194{
195 glwin * view = (glwin *) data;
196 project * this_proj = get_project_by_id(view -> proj);
197 if (view -> anim -> last -> img -> step < this_proj -> steps-1)
198 {
199 sequence (view, view -> anim -> last -> img -> step, view -> anim -> last -> img -> step + 1);
200 }
201}
202
211G_MODULE_EXPORT void seq_go_first (GtkButton * but, gpointer data)
212{
213 glwin * view = (glwin *) data;
214 sequence (view, view -> anim -> last -> img -> step, 0);
215}
216
225G_MODULE_EXPORT void seq_go_last (GtkButton * but, gpointer data)
226{
227 glwin * view = (glwin *) data;
228 sequence (view, view -> anim -> last -> img -> step, get_project_by_id(view -> proj) -> steps - 1);
229}
230
239G_MODULE_EXPORT void seq_go_to (GtkEntry * res, gpointer data)
240{
241 glwin * view = (glwin *) data;
242 const gchar * m = entry_get_text (res);
243 int s = (int)string_to_double ((gpointer)m);
244 project * this_proj = get_project_by_id(view -> proj);
245 if (s > 0 && s <= this_proj -> steps)
246 {
247 sequence (view, view -> anim -> last -> img -> step, s-1);
248 }
249 update_entry_int (res, this_proj -> modelgl -> anim -> last -> img -> step+1);
250}
251
260G_MODULE_EXPORT void seq_jump (GtkButton * but, gpointer data)
261{
262 glwin * view = (glwin *) data;
263 GtkWidget * win = dialogmodal ("Enter a step number", GTK_WINDOW(view -> player -> win));
264 GtkWidget * vbox = dialog_get_content_area (win);
265 GtkWidget * hbox = create_hbox (0);
266 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, TRUE, 0);
267 gchar * str = g_strdup_printf ("Step number [%d-%d]: ", 1, get_project_by_id(view -> proj) -> steps);
268 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, gtk_label_new (str), TRUE, TRUE, 0);
269 g_free (str);
270 GtkWidget * step = create_entry (G_CALLBACK(seq_go_to), 100, 15, TRUE, (gpointer)view);
271 update_entry_int (GTK_ENTRY(step), view -> anim -> last -> img -> step+1);
272 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, step, FALSE, FALSE, 0);
273 run_this_gtk_dialog (win, G_CALLBACK(run_destroy_dialog), NULL);
274}
275
283static gboolean animate (gpointer data)
284{
285 glwin * view = (glwin *) data;
286 if (view -> play)
287 {
288 if (view -> anim -> last -> img -> step < get_project_by_id(view -> proj) -> steps-1)
289 {
290 sequence (view, view -> anim -> last -> img -> step, view -> anim -> last -> img -> step+1);
291 }
292 else if (view -> loop)
293 {
294 sequence (view, view -> anim -> last -> img -> step, 0);
295 }
296 else
297 {
298 view -> play = FALSE;
299 view -> stop = TRUE;
300 }
301 }
302 else
303 {
304 view -> play = FALSE;
305 view -> stop = TRUE;
306 }
307 return view -> play;
308}
309
318G_MODULE_EXPORT void seq_play (GtkButton * but, gpointer data)
319{
320 glwin * view = (glwin *) data;
321 if (! view -> play)
322 {
323 view -> play = TRUE;
324 view -> stop = FALSE;
325 g_timeout_add (view -> speed, (GSourceFunc) animate, view);
326 }
327}
328
337G_MODULE_EXPORT void seq_stop (GtkButton * but, gpointer data)
338{
339 glwin * view = (glwin *) data;
340 view -> play = FALSE;
341}
342
351G_MODULE_EXPORT void seq_loop (GtkButton * but, gpointer data)
352{
353 glwin * view = (glwin *) data;
354 if (view -> loop)
355 {
356 view -> loop = FALSE;
358 }
359 else
360 {
361 view -> loop = TRUE;
363 }
364 show_the_widgets (GTK_WIDGET(but));
365}
366
374static gboolean seq_wait_for_stop (gpointer data)
375{
376 glwin * view = (glwin *) data;
377
378 if (view -> stop)
379 {
380 seq_play (NULL, data);
381 return FALSE;
382 }
383 else
384 {
385 return TRUE;
386 }
387}
388
397G_MODULE_EXPORT void seq_faster (GtkButton * but, gpointer data)
398{
399 glwin * view = (glwin *) data;
400 int oldspeed;
401 if (view -> play && view -> speed > 4)
402 {
403 oldspeed = view -> speed;
404 if (view -> speed == 5)
405 {
406 view -> speed -= 1;
407 }
408 else
409 {
410 view -> speed -= 5;
411 }
412 view -> play = FALSE;
413 g_timeout_add (oldspeed, (GSourceFunc) seq_wait_for_stop, view);
414 }
415}
416
425G_MODULE_EXPORT void seq_slower (GtkButton * but, gpointer data)
426{
427 glwin * view = (glwin *) data;
428 int oldspeed;
429 if (view -> play && view -> speed < 10000)
430 {
431 oldspeed = view -> speed;
432 if (view -> speed == 1)
433 {
434 view -> speed = 5;
435 }
436 else
437 {
438 view -> speed += 5;
439 }
440 view -> play = FALSE;
441 g_timeout_add (oldspeed, (GSourceFunc) seq_wait_for_stop, view);
442 }
443}
444
453G_MODULE_EXPORT void window_sequencer (GtkWidget * widg, gpointer data)
454{
455 //int p;
456 glwin * view = (glwin *) data;
457 if (view -> player == NULL)
458 {
459 //p = view -> proj;
460 view -> player = g_malloc0 (sizeof*view -> player);
461 view -> player -> win = create_win (" ", view -> win, FALSE, FALSE);
462 set_player_title (view);
463 GtkWidget * vbox = create_vbox (BSEP);
464 add_container_child (CONTAINER_WIN, view -> player -> win, vbox);
465 // First line
466 GtkWidget * hboxa = create_hbox (0);
467 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hboxa, TRUE, TRUE, 0);
468 // First
469 view -> player -> first = create_button ("First", IMG_STOCK, MEDIA_FIRST, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_go_first), view);
470 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, view -> player -> first, TRUE, TRUE, 0);
471 // Previous
472 view -> player -> prev = create_button ("Previous", IMG_STOCK, MEDIA_PREV, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_go_previous), view);
473 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, view -> player -> prev, TRUE, TRUE, 0);
474 // Next
475 view -> player -> next = create_button ("Next", IMG_STOCK, MEDIA_NEXT, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_go_next), view);
476 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, view -> player -> next, TRUE, TRUE, 0);
477 // Last
478 view -> player -> last = create_button ("Last", IMG_STOCK, MEDIA_LAST, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_go_last), view);
479 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, view -> player -> last, TRUE, TRUE, 0);
480 // JumpTo
481 view -> player -> jump = create_button ("Go to", IMG_STOCK, MEDIA_GOTO, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_jump), view);
482 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxa, view -> player -> jump, TRUE, TRUE, 0);
483
484 // Second line
485 GtkWidget * hboxb = create_hbox (0);
486 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hboxb, TRUE, TRUE, 0);
487 // Play
488 view -> player -> play = create_button ("Play", IMG_STOCK, MEDIA_PLAY, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_play), view);
489 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxb, view -> player -> play, TRUE, TRUE, 0);
490 // Stop
491 view -> player -> stop = create_button ("Stop", IMG_STOCK, MEDIA_STOP, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_stop), view);
492 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxb, view -> player -> stop, TRUE, TRUE, 0);
493 // Loop
494 view -> player -> loop = create_button ("Loop", IMG_STOCK, MEDIA_LOOP, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_loop), view);
495 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxb, view -> player -> loop, TRUE, TRUE, 0);
496 // Faster
497 view -> player -> fast = create_button ("Faster", IMG_STOCK, MEDIA_FAST, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_faster), view);
498 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxb, view -> player -> fast, TRUE, TRUE, 0);
499 // Slower
500 view -> player -> slow = create_button ("Slower", IMG_STOCK, MEDIA_SLOW, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(seq_slower), view);
501 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hboxb, view -> player -> slow, TRUE, TRUE, 0);
502 add_gtk_close_event (view -> player -> win, G_CALLBACK(hide_this_window), NULL);
503 show_the_widgets (view -> player -> win);
504 update_step_button (view);
505 }
506 else
507 {
508 show_the_widgets (view -> player -> win);
509 }
510}
Callback declarations for main window.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
void process_selected_atom(project *this_proj, glwin *view, int id, int ac, int se, int pi)
process selected atom
Definition selection.c:514
int atoms[NUM_STYLES][2]
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
void recreate_all_shaders(glwin *view)
re-initialize all OpenGL shaders
@ IMG_STOCK
Definition global.h:264
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
#define MEDIA_PREV
Definition global.h:183
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
#define MEDIA_NEXT
Definition global.h:182
#define MEDIA_LOOP
Definition global.h:189
project * proj
#define MEDIA_FIRST
Definition global.h:185
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
#define BSEP
Definition global.h:245
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:614
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
Definition gtk-misc.c:2371
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2387
#define MEDIA_LAST
Definition global.h:184
#define MEDIA_FAST
Definition global.h:192
@ CONTAINER_WIN
Definition global.h:250
#define MEDIA_PLAY
Definition global.h:187
#define MEDIA_SLOW
Definition global.h:191
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1863
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
void button_set_image(GtkButton *but, gchar *text, int format, gpointer image)
Add an image to a GtkButton.
Definition gtk-misc.c:1677
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
#define MEDIA_ULOOP
Definition global.h:190
G_MODULE_EXPORT void run_destroy_dialog(GtkDialog *dialog, gint response_id, gpointer data)
to destroy a GtkDialog when the dialog emit the closing signal
Definition gtk-misc.c:2102
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
gboolean in_md_shaders(project *this_proj, int id)
is this shader MD dependent ?
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
#define MEDIA_GOTO
Definition global.h:186
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
#define MEDIA_STOP
Definition global.h:188
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
gboolean pick
int step
Definition ogl_draw.c:70
void update_all_selections(glwin *view, int pi)
update the selection data: bonds, angles and dihedrals
Definition selection.c:387
void save_all_selections(glwin *view, int pi)
save all selection data
Definition selection.c:372
#define NGLOBAL_SHADERS
Definition glwin.h:69
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
Definition glwin.h:875
GtkWidget * res[2]
Definition w_encode.c:212
G_MODULE_EXPORT void seq_jump(GtkButton *but, gpointer data)
jump to frame dialog
G_MODULE_EXPORT void seq_loop(GtkButton *but, gpointer data)
loop the animation
void update_selection(glwin *view, int o_step)
match and udpate selected atom()s from o_step to the active step
Definition w_sequencer.c:85
G_MODULE_EXPORT void seq_go_first(GtkButton *but, gpointer data)
go to first frame
G_MODULE_EXPORT void seq_go_to(GtkEntry *res, gpointer data)
jump to frame
G_MODULE_EXPORT void seq_go_previous(GtkButton *but, gpointer data)
go to previous frame
G_MODULE_EXPORT void seq_stop(GtkButton *but, gpointer data)
stop
G_MODULE_EXPORT void seq_go_next(GtkButton *but, gpointer data)
go to next frame
G_MODULE_EXPORT void seq_play(GtkButton *but, gpointer data)
play
void update_step_button(glwin *view)
correct widget buttons sensitivity based on MD step
void sequence(glwin *view, int o_step, int n_step)
sequence to next step
G_MODULE_EXPORT void seq_go_last(GtkButton *but, gpointer data)
got to last frame
G_MODULE_EXPORT void seq_slower(GtkButton *but, gpointer data)
go slower
void set_player_title(glwin *view)
set sequencer window title
Definition w_sequencer.c:69
G_MODULE_EXPORT void seq_faster(GtkButton *but, gpointer data)
go faster
G_MODULE_EXPORT void window_sequencer(GtkWidget *widg, gpointer data)
create the sequencer window
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72