📄 uif_sfont.c
字号:
/*================================================================== * uif_sfont.c - Sound font user interface routines * * Smurf Sound Font Editor * Copyright (C) 1999-2001 Josh Green * * 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 * of the License, 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA or point your web browser to http://www.gnu.org. * * To contact the author of this program: * Email: Josh Green <jgreen@users.sourceforge.net> * Smurf homepage: http://smurf.sourceforge.net *==================================================================*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <sys/stat.h>#include <unistd.h>#include <string.h>#include <time.h>#include <gtk/gtk.h>#include "uif_sfont.h"#include "glade_interface.h"#include "uif_menutbar.h"#include "uif_sftree.h"#include "uif_piano.h"#include "uif_pianospan.h"#include "uif_sfgen.h"#include "uif_samview.h"#include "uiface.h"#include "pixmap.h"#include "sfont.h"#include "wavetable.h"#include "sequencer.h"#include "sample.h"#include "sffile.h"#include "sfdump.h"#include "sfundo.h"#include "sfdofunc.h"#include "smurfcfg.h"#include "util.h"#include "vbank.h"#include "i18n.h"#include "widgets/popdog.h"GList *uisf_sfonts = NULL; /* list of loaded sound fonts (UISFont *) */GList *uisf_vbanks = NULL; /* list of loaded virtual banks (VBnkData *) *//* the following variables reflect the currently selected sftree item */UISFont *uisf_selected_uisfont = NULL; /* currently selected sound font */UIVBank *uisf_selected_uivbank = NULL; /* currently selected virtual bank */gpointer uisf_selected_elem = NULL; /* selected element (preset/inst/sample) */gint uisf_selected_elem_type = NODE_NONE; /* type of element selected */SFZone *uisf_selected_zone = NULL; /* zone selected */static gchar *uisf_sfont_save_path = NULL; /* path to last saved sound font */static gchar *uisf_sfont_load_path = NULL; /* path to last loaded sound font */gboolean uisf_piano_follows = TRUE; /* piano follows sftree selection */gboolean uisf_auto_temp_audible = TRUE; /* auto load temporary audible */static gint untitlecount = 0; /* untitled counter (new sound fonts) */static void uisf_cb_open_sfont_okay (GtkWidget * filewin);static void uisf_close_sfont_save_yes (gpointer data, GtkWidget *popdog);static void uisf_cb_close_sfont_savewin_destroy (GtkWidget * savewin, GtkWidget * popdog);static void uisf_close_sfont_save_no (gpointer data, GtkWidget *popdog);static void uisf_cb_saveas_dialog_okay (GtkWidget * btn, SFItemID itemid);static void uisf_cb_save_ovrwrite_okay (gpointer data, GtkWidget *popdog);static gint uisf_cb_save_continue (gchar * fname, SFItemID itemid);static void uisf_cb_newmod_preset_cbfunc (GtkWidget * psetwin);static void uisf_cb_newmod_inst_cbfunc (GtkWidget * instwin);static void uisf_cb_modify_sample_cbfunc (GtkWidget * samwin);static void uisf_cb_sfitem_delete_okay (gpointer data, GtkWidget *popdog);static void uisf_cb_find_optype_selection_done (GtkWidget * menu, GtkWidget * findwin);static void uisf_cb_find_search (GtkWidget * btn, GtkWidget * findwin);static gint uisf_find_pzone_by_inst_compare (SFTreeRef * nref, GSList * pinst);static gint uisf_find_izone_by_sample_compare (SFTreeRef * nref, GSList * psam);static void uisf_preset_delete (SFItemID itemid);static void uisf_pzone_delete (SFItemID itemid);static void uisf_inst_delete (SFItemID itemid);static void uisf_izone_delete (SFItemID itemid);static void uisf_sample_delete (SFItemID itemid);static void uisf_vbank_map_delete (SFItemID itemid);static void uisf_piano_follow_update (gboolean temp_audible, gint bank, gint prenum);static void uisf_set_selected_preset (SFPreset * preset, UISFont * uisf);static void uisf_set_selected_inst (SFInst * inst, UISFont * uisf);static void uisf_set_selected_sample (SFSample * sam, UISFont * uisf);static void uisf_set_selected_pzone (SFZone * zone, SFPreset * preset, UISFont * uisf);static void uisf_set_selected_izone (SFZone *zone, SFInst *inst, UISFont *uisf);static void uisf_set_selected_vbnk_map (VBnkItem *item, UIVBank *uivb);/***--- Sound Font FILE level routines ---***/voiduisf_init (void){ uisf_new_sfont ();}/* add sfont to user interface */UISFont *uisf_add_sfont (SFData * sf){ UISFont *uisf; uisf = g_malloc (sizeof (UISFont)); uisf->sf = sf; uisf_sfonts = g_list_append (uisf_sfonts, uisf); sftree_add_sfont (uisf); /* add sfont to tree */ return (uisf);}/* add virtual sfont bank to user interface */UIVBank *uisf_add_vbank (VBnkData *vbnk){ UIVBank *uivb; uivb = g_malloc (sizeof (UIVBank)); uivb->vbnk = vbnk; uisf_vbanks = g_list_append (uisf_vbanks, uivb); sftree_add_vbank (uivb); return (uivb);}/* remove sound font from user interface */voiduisf_remove_sfont (UISFont * uisf){ /* if removing the selected sound font then deactivate selection */ if (uisf_selected_uisfont == uisf) uisf_deactivate_selection (); sftree_remove_sfont (uisf); /* remove from tree */ sfont_close (uisf->sf); /* close the sfont */ uisf_sfonts = g_list_remove (uisf_sfonts, uisf); /* remove from list */ g_free (uisf);}/* remove virtual bank from user interface */voiduisf_remove_vbank (UIVBank *uivb){ sftree_remove_vbank (uivb); /* remove from sftree */ vbank_close (uivb->vbnk); /* free the virtual bank */ uisf_vbanks = g_list_remove (uisf_vbanks, uivb); /* remove from vbank list */ g_free (uivb);}/* create a new sound font */voiduisf_new_sfont (void){ untitlecount++; uisf_add_sfont (sfont_new (untitlecount));}/* create a new virtual bank */voiduisf_new_vbank (void){ untitlecount++; uisf_add_vbank (vbank_new (untitlecount));}/* finds a loaded sound font by its file name, excluding excl */UISFont *uisf_find_sfont_by_fname (gchar * fname, SFData * excl){ GList *p; UISFont *uisf; p = uisf_sfonts; while (p) { uisf = (UISFont *) (p->data); if (uisf->sf != excl && strcmp (fname, uisf->sf->fname) == 0) return (uisf); p = g_list_next (p); } return (NULL);}/* finds a loaded virtual bank by its file name, excluding excl */UIVBank *uisf_find_vbank_by_fname (gchar * fname, VBnkData * excl){ GList *p; UIVBank *uivb; p = uisf_vbanks; while (p) { uivb = (UIVBank *) (p->data); if (uivb->vbnk != excl && strcmp (fname, uivb->vbnk->fname) == 0) return (uivb); p = g_list_next (p); } return (NULL);}SFItemIDuisf_load_sfont (gchar * fname){ SFData *sf; VBnkData *vbnk; SFItemID retid; /* if its a virtual bank file (*.bnk) then load as such */ if (vbank_is_virtual_bank (fname)) { if (!(vbnk = vbank_load (fname))) return (SFITEMID_NONE); uisf_add_vbank (vbnk); retid = vbnk->itemid; } else { if (!(sf = sfload_file (fname))) return (SFITEMID_NONE); uisf_add_sfont (sf); retid = sf->itemid; } return (retid);}voiduisf_open_sfont (void){ GTokenValue *val; GtkWidget *filewin; if (util_activate_unique_dialog ("opensf", 0)) return; filewin = gtk_file_selection_new (_("Open Sound Font")); util_register_unique_dialog (filewin, "opensf", 0); /* if load path isn't set, use default sfont path from smurf.cfg */ if (!uisf_sfont_load_path) { val = smurfcfg_get_val (SMURFCFG_DEF_SFONT_PATH); uisf_sfont_load_path = g_strdup (val->v_string); } if (strlen (uisf_sfont_load_path)) gtk_file_selection_set_filename (GTK_FILE_SELECTION (filewin), uisf_sfont_load_path); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filewin)-> ok_button), "clicked", (GtkSignalFunc) uisf_cb_open_sfont_okay, GTK_OBJECT (filewin)); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filewin)-> cancel_button), "clicked", (GtkSignalFunc) gtk_widget_destroy, GTK_OBJECT (filewin)); gtk_widget_show (filewin);}static voiduisf_cb_open_sfont_okay (GtkWidget * filewin){ gchar *fname; gchar *s; fname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filewin)); if (uisf_find_sfont_by_fname (fname, NULL)) { util_quick_popup (_("That sound font is already loaded and being used"), NULL); return; } if (!uisf_load_sfont (fname)) /* load sfont */ return; g_free (uisf_sfont_load_path); /* free old load path */ s = g_dirname (fname); /* new load path */ uisf_sfont_load_path = g_strconcat (s, "/", NULL); g_free (s); gtk_widget_destroy (filewin); /* destroy file sel dialog on success */}voiduisf_dump_sfont (void){ SFItemID itemid; GtkCTreeNode *node; UISFont *uisf; FILE *dumpfd; if (!(itemid = sftree_get_selection_single ())) return; if (!(node = SFTREE_LOOKUP_ITEMID (itemid))) return; uisf = SFTREE_UPFIND_UISF (node); if (!(dumpfd = fopen ("/tmp/smurf_dump.txt", "w"))) { logit (LogFubar | LogErrno, _("Failed to open /tmp/smurf_dump.txt for writing")); return; } sfont_dump (uisf->sf, dumpfd); fclose (dumpfd);}voiduisf_close_sfont (void){ SFItemID itemid; GtkCTreeNode *node; UISFont *uisf; UIVBank *uivb; GtkWidget *popdog; gchar *s; /* get active single item (NULL if multiple active items) */ if (!(itemid = sftree_get_selection_single ())) return; if (!(node = SFTREE_LOOKUP_ITEMID (itemid))) return; uisf = SFTREE_UPFIND_UISF (node); if (!uisf) uivb = SFTREE_UPFIND_UIVB (node); else uivb = NULL; if (uisf && uisf->sf->up2date) uisf_remove_sfont (uisf); else if (uivb && uivb->vbnk->up2date) uisf_remove_vbank (uivb); else { s = g_strdup_printf (_("Save changes before closing \"%s\"?"), (uisf != NULL) ? uisf->sf->fname : uivb->vbnk->fname); popdog = util_quick_popup (s, _("Yes"), uisf_close_sfont_save_yes, NULL, _("No"), uisf_close_sfont_save_no, NULL, _("Cancel"), NULL, NULL, NULL); g_free (s); gtk_object_set_data (GTK_OBJECT (popdog), "itemid", GINT_TO_POINTER (itemid)); }}static voiduisf_close_sfont_save_yes (gpointer data, GtkWidget *popdog){ SFItemID itemid; GtkCTreeNode *node; UISFont *uisf; UIVBank *uivb; GtkWidget *savewin; itemid = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (popdog), "itemid")); if (!(node = SFTREE_LOOKUP_ITEMID (itemid))) { gtk_widget_destroy (popdog); return; } uisf = SFTREE_UPFIND_UISF (node); if (!uisf) uivb = SFTREE_UPFIND_UIVB (node); else uivb = NULL; sftree_set_selection_single (itemid); savewin = uisf_save_sfont (FALSE); sftree_unset_selection (); if (uisf && uisf->sf->up2date) { /* sound font is now up to date? */ uisf_remove_sfont (uisf); gtk_widget_destroy (popdog); } else if (uivb && uivb->vbnk->up2date) { /* vbank now up to date? */ uisf_remove_vbank (uivb); gtk_widget_destroy (popdog); } else { /* not saved, hook savewin destroy signal */ if (savewin) gtk_signal_connect (GTK_OBJECT (savewin), "destroy", (GtkSignalFunc) uisf_cb_close_sfont_savewin_destroy, popdog); }}/* triggered by death of save file select widget from within close sfont */static voiduisf_cb_close_sfont_savewin_destroy (GtkWidget * savewin, GtkWidget * popdog){ SFItemID itemid; GtkCTreeNode *node; UISFont *uisf; UIVBank *uivb; itemid = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (popdog), "itemid")); if (!(node = SFTREE_LOOKUP_ITEMID (itemid))) { gtk_widget_destroy (popdog); return; } uisf = SFTREE_UPFIND_UISF (node); if (!uisf) uivb = SFTREE_UPFIND_UIVB (node); else uivb = NULL; if (uisf && uisf->sf->up2date) { /* did sound font get saved? */ uisf_remove_sfont (uisf); gtk_widget_destroy (popdog); } /* ?: no, then leave "Save before close" dialog un-molested */ else if (uivb && uivb->vbnk->up2date) { uisf_remove_vbank (uivb); gtk_widget_destroy (popdog); }}static voiduisf_close_sfont_save_no (gpointer data, GtkWidget *popdog){ SFItemID itemid; GtkCTreeNode *node; UISFont *uisf; UIVBank *uivb; itemid = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (popdog), "itemid")); if (!(node = SFTREE_LOOKUP_ITEMID (itemid))) { gtk_widget_destroy (popdog); return; } uisf = SFTREE_UPFIND_UISF (node); if (!uisf) /* ?: is it a virtual bank? */ { /* ?: Yes */ uivb = SFTREE_UPFIND_UIVB (node); uisf_remove_vbank (uivb); } else uisf_remove_sfont (uisf); /* ?: No */ gtk_widget_destroy (popdog);}/*---- uisf_save_sfont ----------- saves a sound font with 2 different modes save_as = TRUE or sound font never been saved: pops a file selection dialog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -