2 * omnplay.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include <gdk/gdkkeysyms.h>
36 #include "omplrclnt.h"
38 static gboolean
on_main_window_delete_event( GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
44 omnplay_instance_t
* omnplay_create(int argc
, char** argv
)
47 omnplay_instance_t
* app
;
49 /* prepare application instance */
50 app
= (omnplay_instance_t
*)malloc(sizeof(omnplay_instance_t
));
51 memset(app
, 0, sizeof(omnplay_instance_t
));
53 /* load parameters from command line */
54 if(!omnplay_opt(argc
, argv
, app
) && app
->players
.count
)
55 app
->window
= ui_omnplay(app
);
62 void omnplay_destroy(omnplay_instance_t
* app
)
67 static void omnplay_update_status(omnplay_player_t
* player
, OmPlrStatus
*prev
, OmPlrStatus
*curr
)
69 char tc_cur
[32], tc_rem
[32], state
[32], status
[32];
74 frames2tc(curr
->pos
- curr
->minPos
, 25.0, tc_cur
);
75 frames2tc(curr
->maxPos
- curr
->pos
, 25.0, tc_rem
);
76 strcpy(status
, "ONLINE");
77 clip
= curr
->currClipName
;
81 case omPlrStateStopped
: strcpy(state
, "STOPPED"); break;
82 case omPlrStateCuePlay
: strcpy(state
, "CUE_PLAY"); break;
83 case omPlrStatePlay
: strcpy(state
, "PLAY"); break;
84 case omPlrStateCueRecord
: strcpy(state
, "CUE_RECORD"); break;
85 case omPlrStateRecord
: strcpy(state
, "RECORD"); break;
94 strcpy(status
, "OFFLINE");
98 gtk_label_set_text(GTK_LABEL (player
->label_tc_cur
), tc_cur
);
99 gtk_label_set_text(GTK_LABEL (player
->label_tc_rem
), tc_rem
);
100 gtk_label_set_text(GTK_LABEL (player
->label_state
), state
);
101 gtk_label_set_text(GTK_LABEL (player
->label_status
), status
);
102 gtk_label_set_text(GTK_LABEL (player
->label_clip
), clip
);
106 memcpy(prev
, curr
, sizeof(OmPlrStatus
));
109 static void* omnplay_thread_proc(void* data
)
112 OmPlrStatus st_curr
, st_prev
;
113 omnplay_player_t
* player
= (omnplay_player_t
*)data
;
116 pthread_mutex_lock(&player
->lock
);
117 r
= OmPlrOpen(player
->host
, player
->name
, (OmPlrHandle
*)&player
->handle
);
118 pthread_mutex_unlock(&player
->lock
);
121 fprintf(stderr
, "ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n",
122 player
->host
, player
->name
, r
);
127 /* setup to do not reconnect */
128 pthread_mutex_lock(&player
->lock
);
129 OmPlrSetRetryOpen((OmPlrHandle
)player
->handle
, 0);
130 pthread_mutex_unlock(&player
->lock
);
132 /* setup directory */
133 if(player
->app
->players
.path
[0])
135 pthread_mutex_lock(&player
->lock
);
136 // r = OmPlrClipSetDirectory((OmPlrHandle)player->handle, player->app->players.path);
137 pthread_mutex_unlock(&player
->lock
);
141 fprintf(stderr
, "ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n",
142 player
->app
->players
.path
, r
);
144 pthread_mutex_lock(&player
->lock
);
145 OmPlrClose((OmPlrHandle
)player
->handle
);
146 pthread_mutex_unlock(&player
->lock
);
153 for(r
= 0 ; !player
->app
->f_exit
&& !r
;)
159 pthread_mutex_lock(&player
->lock
);
160 st_curr
.size
= sizeof(OmPlrStatus
);
161 r
= OmPlrGetPlayerStatus((OmPlrHandle
)player
->handle
, &st_curr
);
162 pthread_mutex_unlock(&player
->lock
);
165 fprintf(stderr
, "ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r
);
167 if(memcmp(&st_curr
, &st_prev
, sizeof(OmPlrStatus
)))
168 omnplay_update_status(player
, &st_prev
, &st_curr
);
171 pthread_mutex_lock(&player
->lock
);
172 OmPlrClose((OmPlrHandle
)player
->handle
);
173 pthread_mutex_unlock(&player
->lock
);
178 static gboolean
omnplay_button_click(omnplay_instance_t
* app
, control_buttons_t button
)
182 case BUTTON_PLAYLIST_ITEM_ADD
:
183 case BUTTON_PLAYLIST_ITEM_DEL
:
184 case BUTTON_PLAYLIST_ITEM_EDIT
:
185 case BUTTON_PLAYLIST_LOAD
:
186 omnplay_playlist_load(app
);
188 case BUTTON_PLAYLIST_SAVE
:
189 omnplay_playlist_save(app
);
191 case BUTTON_PLAYLIST_BLOCK_SINGLE
:
192 case BUTTON_PLAYLIST_BLOCK_LOOP
:
193 case BUTTON_PLAYLIST_ITEM_UP
:
194 case BUTTON_PLAYLIST_ITEM_DOWN
:
195 case BUTTON_PLAYER_CUE
:
196 case BUTTON_PLAYER_PLAY
:
197 case BUTTON_PLAYER_PAUSE
:
198 case BUTTON_PLAYER_STOP
:
199 case BUTTON_LIBRARY_ADD
:
200 case BUTTON_LIBRARY_REFRESH
:
207 static gboolean
on_button_click(GtkWidget
*button
, gpointer user_data
)
210 omnplay_instance_t
* app
= (omnplay_instance_t
*)user_data
;
212 for(i
= 1; i
< BUTTON_LAST
; i
++)
213 if(app
->buttons
[i
] == button
)
214 return omnplay_button_click(app
, (control_buttons_t
)i
);
219 void omnplay_init(omnplay_instance_t
* app
)
223 gtk_signal_connect( GTK_OBJECT( app
->window
), "destroy",
224 GTK_SIGNAL_FUNC(on_main_window_delete_event
), app
);
226 for(i
= 0; i
< app
->players
.count
; i
++)
229 pthread_mutex_init(&app
->players
.item
[i
].lock
, NULL
);
231 /* create a omneon status thread */
232 pthread_create(&app
->players
.item
[i
].thread
, NULL
,
233 omnplay_thread_proc
, &app
->players
.item
[i
]);
237 pthread_mutex_init(&app
->playlist
.lock
, NULL
);
239 /* attach buttons click */
240 for(i
= 1; i
< BUTTON_LAST
; i
++)
241 gtk_signal_connect(GTK_OBJECT(app
->buttons
[i
]), "clicked",
242 GTK_SIGNAL_FUNC( on_button_click
), app
);
246 void omnplay_release(omnplay_instance_t
* app
)
253 for(i
= 0; i
< app
->players
.count
; i
++)
255 /* create a omneon status thread */
256 pthread_join(app
->players
.item
[i
].thread
, &r
);
259 pthread_mutex_destroy(&app
->players
.item
[i
].lock
);
264 pthread_mutex_destroy(&app
->playlist
.lock
);