/* * Copyright (C) 2004-2005 Vadim Berezniker * http://www.kryptolus.com * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ #include "stdafx.h" #include "common.h" #include "sabbu.h" #include "gui_main_video.h" #include "gui_workspace.h" #include "gui_waveforms.h" #include "gui_status_bar.h" #include "gui_event_list.h" #include "kry_waveform_group_item.h" #include "sound.h" extern struct sabbu app; extern krySabbu *appObj; gboolean gui_workspace_open(char *filename) { gboolean audio_loaded = FALSE; kryListIterator iter; GtkTreePath *path; kryPrefManager *prefs = new kryPrefManager(); if(!prefs->Load(filename)) { delete prefs; return FALSE; } char *audio, *video, *script; GList *ptr; if(!prefs->GetString("Audio", "File") && !prefs->GetString("Video", "File") && !prefs->GetString("Script", "File") && !prefs->GetString("Script", "Selection")) { delete prefs; return FALSE; } //gui_main_update_pane_position(gtk_notebook_get_current_page(app.ui.notebook)); g_signal_handlers_block_by_func(app.ui.paned_list, (void *) gui_main_text_paned_move_cb, NULL); g_signal_handlers_block_by_func(app.ui.paned_notebook, (void *) gui_main_text_paned_move_cb, NULL); kry_waveform_group_disable_draw(app.ui.waveform_group); prefs->SetSection("Audio"); audio = prefs->GetString("File"); if(audio && gui_audio_open(audio)) { int counter = 0; int wave_count = prefs->GetInt("WaveCount", 0); int i; audio_loaded = TRUE; GList *waves = kry_waveform_group_waveform_get_list(app.ui.waveform_group); for(i = 0; i < wave_count; i++) { gboolean sync_zoom = TRUE; KryWaveformGroupItem *item = NULL; char *key = kry_strdup_printf(KRY_LOC "Wave%dParent", counter); int val; val = prefs->GetInt(key, -1); kry_free(key); if(val == -1) { item = KRY_WAVEFORM_GROUP_ITEM(g_list_nth_data(waves, i)); if(!item) break; } if(i != 0) { int sync_scale, sync_scroll; if(val != -1) { item = KRY_WAVEFORM_GROUP_ITEM(g_list_nth_data(waves, val)); gui_waveforms_waveform_clone(item); item = KRY_WAVEFORM_GROUP_ITEM(g_list_nth_data(waves, i)); if(!item) break; } key = kry_strdup_printf(KRY_LOC "Wave%dSyncZoom", counter); sync_zoom = prefs->GetInt(key, 1); if(!sync_zoom) kry_waveform_group_item_set_zoom_sync(item, FALSE); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dSyncScale", counter); sync_scale = prefs->GetInt(key, 1); if(!sync_scale) kry_waveform_group_item_set_scale_sync(item, FALSE); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dSyncScroll", counter); sync_scroll = prefs->GetInt(key, 1); if(!sync_scroll) kry_waveform_group_item_set_scroll_sync(item, FALSE); kry_free(key); } key = kry_strdup_printf(KRY_LOC "Wave%dZoomFactor", counter); val = prefs->GetInt(key, 1); kry_waveform_set_zoom(kry_waveform_group_item_get_waveform(item), val / 100.0); if(i == 0) kry_waveform_group_set_zoom(app.ui.waveform_group, val / 100.0); if(i == 0 || sync_zoom) kry_waveform_group_item_set_zoom_sync(item, TRUE); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dScale", counter); val = prefs->GetInt(key, 1); kry_waveform_set_scale(kry_waveform_group_item_get_waveform(item), val); kry_free(key); counter++; } } if(audio_loaded) { prefs->SetSection("Audio"); long marker_start = prefs->GetInt("MarkerStart", -1); long marker_end = prefs->GetInt("MarkerEnd", -1); kry_marker_set_value(app.ui.marker_event_start, marker_start); kry_marker_set_value(app.ui.marker_event_end, marker_end); gui_main_set_time_modified(FALSE); GList *list = kry_waveform_group_waveform_get_list(app.ui.waveform_group); int wave_count = prefs->GetInt("WaveCount", 0); for(int i = 0; i < wave_count; i++) { char *key; int val; GtkAdjustment *adj; KryWaveformGroupItem *item = KRY_WAVEFORM_GROUP_ITEM(g_list_nth_data(list, i)); key = kry_strdup_printf(KRY_LOC "Wave%dLeft", i); val = prefs->GetInt(key, 0); adj = kry_waveform_get_adjustment(kry_waveform_group_item_get_waveform(item)); if(adj) gtk_adjustment_set_value(adj, val); kry_free(key); } } kry_waveform_group_enable_draw(app.ui.waveform_group); prefs->SetSection("Video"); video = prefs->GetString("File"); if(video) { gui_video_open(video); if(prefs->GetInt("MarkKeyframes", 0)) gui_main_menu_video_keyframes_mark(NULL, 0, NULL); } prefs->SetSection("Script"); script = prefs->GetString("File"); if(script) { int time_modified = prefs->GetInt("TimeModified", 0); if(time_modified) gui_main_set_time_modified(TRUE); g_object_set_data(G_OBJECT(gui_event_list_get_view(app.ui.event_list)), "disable-auto-focus", (gpointer) 1); if(appObj->ScriptOpen(script)) { ptr = prefs->GetList("Selection"); if(ptr) gtk_tree_selection_unselect_all(gui_event_list_get_selection(app.ui.event_list)); for(; ptr; ptr = ptr->next) { kryPrefValue *pref = (kryPrefValue *) ptr->data; path = gtk_tree_path_new_from_string((char *) pref->GetData()); gtk_tree_selection_select_path(gui_event_list_get_selection(app.ui.event_list), path); gtk_tree_path_free(path); } while(gtk_events_pending()) gtk_main_iteration(); GtkAdjustment *adj = gtk_tree_view_get_vadjustment(gui_event_list_get_view(app.ui.event_list)); gtk_adjustment_set_value(adj, prefs->GetInt("EventListPos", 0)); } g_object_set_data(G_OBJECT(gui_event_list_get_view(app.ui.event_list)), "disable-auto-focus", (gpointer) 0); app.script->SetModifiedFlag(FALSE); } prefs->SetSection("ShiftTimes"); struct _gui_shift_times_options *opts = &app.gui_shift_times_options; opts->shift_type = (enum shift_type) prefs->GetInt("Type", SHIFT_BY_TIME); if(opts->shift_type == SHIFT_BY_TIME) { opts->offset_mili = prefs->GetInt("OffsetMili", 0); } else if(opts->shift_type == SHIFT_BY_FRAME) { opts->offset_frames = prefs->GetInt("OffsetFrames", 0); if(opts->fps) kry_free(opts->fps); opts->fps = kry_strdup(prefs->GetString("FPS")); } opts->shift_direction = (enum shift_direction) prefs->GetInt("Direction", SHIFT_FORWARD); opts->shift_affected_rows = (enum shift_affected_rows) prefs->GetInt("AffectedRows", SHIFT_FROM_SELECTED); opts->shift_affected_times = (enum shift_affected_times) prefs->GetInt("AffectedTimes", SHIFT_START_END); //while(gtk_events_pending()) // gtk_main_iteration(); app.workspace = kry_strdup(filename); gui_main_title_update(); delete prefs; gui_main_recent_list_add(app.ui.menu.script.open_recent_workspace, &app.ui.list_recent_workspaces, app.ui.cb_recent_workspaces, filename); gui_main_focus_on_wave(); gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.save_workspace_as), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.close_workspace), TRUE); while(gtk_events_pending()) gtk_main_iteration(); g_signal_handlers_unblock_by_func(app.ui.paned_list, (void *) gui_main_text_paned_move_cb, NULL); g_signal_handlers_unblock_by_func(app.ui.paned_notebook, (void *) gui_main_text_paned_move_cb, NULL); return TRUE; } /* * Callback for the 'Script -> Open Recent Workspace' menu items. */ void gui_workspace_openrecent_cb(GtkWidget *menu, char *filename) { if(!gui_workspace_open(filename)) gui_error(_("The workspace file '%s' could not be opened"), filename); } /* * Callback for the 'Script -> Open Workspace' menu item. */ void gui_workspace_open_cb(GtkWidget *menu_item, guint param) { char *filename = gui_main_open_file(__("FileDialog|Open Workspace"), file_filter_workspace); if(!filename) return; if(app.workspace) if(!gui_workspace_save(app.workspace) && !gui_warning_yes_no(_("Error saving current workspace.\n\nWould you like to open the selected one anyway?"))) return; gui_workspace_open(filename); } /* * Callback for the 'Script -> Close Workspace' menu item. */ void gui_workspace_close_cb(GtkWidget *menu_item, guint param) { if(!app.workspace) return; if(!gui_workspace_save(app.workspace) && !gui_warning_yes_no(_("Error saving current workspace.\n\nWould you like to continue closing anyway?"))) return; if(!appObj->ScriptClose()) return; appObj->ScriptNew(); gui_main_audio_close(); gui_main_video_close(); gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.save_workspace_as), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.close_workspace), FALSE); kry_free(app.workspace); app.workspace = NULL; gui_main_title_update(); } gboolean gui_workspace_save(char *filename) { GtkTreeModel *model; GtkTreeSelection *selection = gui_event_list_get_selection(app.ui.event_list); GList *sel_items = gtk_tree_selection_get_selected_rows(selection, &model); gboolean mark_keyframes = FALSE; kryPrefManager *prefs = new kryPrefManager(); GList *ptr; if(!filename) filename = gui_main_save_file(__("FileDialog|Save Workspace"), file_filter_workspace, "sabbu"); else filename = kry_strdup(filename); if(!filename) { g_list_foreach (sel_items, (GFunc) gtk_tree_path_free, NULL); g_list_free(sel_items); delete prefs; return TRUE; } prefs->SetSection("Identity"); prefs->SetString("Type", "Sabbu Workspace"); char *version = kry_strdup_printf(KRY_LOC "sabbu %s", app.version); prefs->SetString("Version", version); kry_free(version); prefs->SetSection("Script"); if(app.script && app.script->GetFilename()) prefs->SetString("File", app.script->GetFilename()); if(app.ui.karaoke_mode == KARAOKE_MODE_LINE) { char *str = kry_strdup_printf(KRY_LOC "%d", app.ui.karaoke_parent_event->GetIndex()); prefs->SetListAddString("Selection", str); kry_free(str); } else { for(ptr = sel_items; ptr; ptr = ptr->next) { int index = gtk_tree_path_get_indices((GtkTreePath *) ptr->data)[0]; char *str = kry_strdup_printf(KRY_LOC "%d", index); prefs->SetListAddString("Selection", str); kry_free(str); } } prefs->SetInt("TimeModified", app.ui.time_modified); g_list_foreach (sel_items, (GFunc) gtk_tree_path_free, NULL); g_list_free(sel_items); GtkAdjustment *adj = gtk_tree_view_get_vadjustment(gui_event_list_get_view(app.ui.event_list)); prefs->SetInt("EventListPos", (int) gtk_adjustment_get_value(adj)); prefs->SetSection("Audio"); if(app.ui.sound_info) { GList *list = kry_waveform_group_waveform_get_list(app.ui.waveform_group); KryWaveformGroupItem *item; int counter = 0; prefs->SetInt("WaveCount", g_list_length(list)); prefs->SetInt("MarkerStart", kry_marker_get_value(app.ui.marker_event_start)); prefs->SetInt("MarkerEnd", kry_marker_get_value(app.ui.marker_event_end)); prefs->SetString("File", app.ui.sound_info->filename); for(GList *ptr = list; ptr; ptr = ptr->next) { item = KRY_WAVEFORM_GROUP_ITEM(ptr->data); GtkAdjustment *adj = kry_waveform_get_adjustment(kry_waveform_group_item_get_waveform(item)); int adj_val = (int) gtk_adjustment_get_value(adj); if(kry_waveform_get_keyframe_list(kry_waveform_group_item_get_waveform(item))) mark_keyframes = TRUE; char *key = kry_strdup_printf(KRY_LOC "Wave%dLeft", counter); prefs->SetInt(key, adj_val); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dZoomFactor", counter); prefs->SetInt(key, (int) (kry_waveform_get_zoom(kry_waveform_group_item_get_waveform(item)) * 100)); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dScale", counter); prefs->SetInt(key, (int) (kry_waveform_get_scale(kry_waveform_group_item_get_waveform(item)) * 100)); kry_free(key); if(item->parent_item || counter > 0) { int parent_idx = g_list_index(list, item->parent_item); char *key = kry_strdup_printf(KRY_LOC "Wave%dParent", counter); prefs->SetInt(key, parent_idx); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dSyncZoom", counter); prefs->SetInt(key, item->zoom_sync); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dSyncScale", counter); prefs->SetInt(key, item->scale_sync); kry_free(key); key = kry_strdup_printf(KRY_LOC "Wave%dSyncScroll", counter); prefs->SetInt(key, item->scroll_sync); kry_free(key); } counter++; } } prefs->SetSection("Video"); if(app.ui.tab_video.video) prefs->SetString("File", app.ui.tab_video.video->filename); else mark_keyframes = FALSE; if(mark_keyframes) prefs->SetString("MarkKeyframes", "1"); prefs->SetSection("ShiftTimes"); struct _gui_shift_times_options *opts = &app.gui_shift_times_options; prefs->SetInt("Type", opts->shift_type); if(opts->shift_type == SHIFT_BY_TIME) { prefs->SetInt("OffsetMili", opts->offset_mili); } else if(opts->shift_type == SHIFT_BY_FRAME) { prefs->SetInt("OffsetFrames", opts->offset_frames); prefs->SetString("FPS", opts->fps); } prefs->SetInt("Direction", opts->shift_direction); prefs->SetInt("AffectedRows", opts->shift_affected_rows); prefs->SetInt("AffectedTimes", opts->shift_affected_times); if(!prefs->Save(filename)) { gui_warning("Error saving workspace"); delete prefs; return FALSE; } gui_main_recent_list_add(app.ui.menu.script.open_recent_workspace, &app.ui.list_recent_workspaces, app.ui.cb_recent_workspaces, kry_strdup(filename)); delete prefs; if(app.workspace) kry_free(app.workspace); app.workspace = filename; gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.save_workspace_as), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(app.ui.menu.script.close_workspace), TRUE); gui_status_bar_push_text_with_color(app.ui.status_bar, STATUS_WORKSPACE_SAVED, __("Status|Workspace Saved"), app.ui.status_bar_color_table->Get(STATUS_COLOR_SUCCESS)); gui_main_title_update(); return TRUE; } /* * Callback for the 'Script -> Save Workspace' menu item. */ void gui_workspace_save_cb(GtkWidget *menu_item, guint param) { if(!gui_workspace_save(app.workspace)) gui_error(_("Error saving workspace")); } void gui_workspace_save_as_cb(GtkWidget *menu_item, guint param) { if(!gui_workspace_save(NULL)) gui_error(_("Error saving workspace")); }