📄 hacking
字号:
****** WARNING *******A lot of this stuff will be out dated, while Smurf undergoes majorchanges. Most of the low level sound font functions will be moved to anexternal libsoundfont library, and many changes relating to sound fontitem access, etc. Josh Green April 13, 2001****** WARNING *******So you want to try to add something.. Fix something.. Figure out somethingwith the Smurf source code ehh?? Perhaps this document will help you. Iwelcome any questions or suggestions relating to the Smurf Sound FontEditor, so don't hesitate to send me an email.Other helpful documentation:----------------GTK TutorialGTK Reference ManualGLib Reference ManualThese documents can be found at http://www.gtk.orgGLib is heavily used in the Smurf Sound Font Editor and GTK itself usesit. GLib defines many simple data types like linked lists, hashes,dynamic arrays and strings etc.; and has routines for effecient memorymanagement, portability functions and many other nice things. Inshort.. It kicks ass. Generally speaking any data type starting with a 'G'that isn't 'Gtk' is probably from GLib. Don't confuse glib (nice utilitylibrary) to glibc (essential libraries, the heart of Linux programs).Source file descriptions----------------Lets start off by listing all the source files and what they contain. Allpermanent source or header files contain a description (at the beginning of the file) of what should be found inside it.src/----------------glade_callbacks.c Currently empty, just to make Glade happyglade_interface.c Auto generated by glade, not to be changed directlymidi.c External MIDI inputsample.c Audio file and sample related routinessequencer.c Sequencer output routinessfdofunc.c Undo/Redo item specific functionssfdump.c Sound font dump to text file routines (for debugging)sfload.c Sound font file loadingsfont.c Sound font data manipulationsfsave.c Sound font file savingsfundo.c Undo/Redo systemsmurf.c main() which starts everythingsmurfcfg.c Configuration file routinessplash.c Intro splash image routinessplash_png.c Auto generated by tools/cdump of pixmaps/splash.pnguif_help.c Tips, about, and help (when it becomes available)uif_menutbar.c Menu and tool baruif_piano.c Virtual piano keyboarduif_pianospan.c Note/Velocity ranges below pianouif_pref.c Preferencesuif_sample.c Sample related user interface routinesuif_samview.c Sample viewer user interfaceuif_selections.c Operations on multiple sound font itemsuif_sfgen.c Sound font generator user interface (effects)uif_sfont.c User interface related sound font routinesuif_sftree.c Sound font treeuif_sfundo.c Undo/Redo user interfaceuif_treemenu.c Right click tree menusuif_wavegen.c Sample waveform generatoruiface.c main user interface routines (ties it all together)util.c error handling and other utility functionswavetable.c wavetable (patch loading) routinessrc/drivers----------------midi_alsaraw.c ALSA external raw MIDI thru drivermidi_alsaseq.c ALSA sequencer based MIDI thru drivermidi_oss.c OSS MIDI thruseq_alsa.c ALSA sequencer routinesseq_oss.c OSS sequencer routineswtbl_awe.c OSS AWE wavetable routineswtbl_awefx.c OSS AWE effects routineswtbl_awepatch.c OSS AWE patch loading routineswtbl_aweunits.c SF->AWE unit conversion routineswtbl_gus.c OSS GUS driver (yeah right, should just kill it)wtbl_guspatch.c Patch loading (stupid single sample loading)src/widgets----------------keyspan.c Note/velocity range widgetpiano.c Piano widgetpopdog.c Pop up dialog convenience widget (is it really?)ptrstrip.c Pointers on a strip widgetsamview.c Sample viewer widgetNOTE: If there is a file I didn't list there that you think should be,its probably new and I just forgot to add it to here.Definitions and terms----------------Here is a list of terms I will use throughout this document and adescription of what each means. I'm only going to list terms that areunique to Smurf or my own terminology.. etc. I'm not going to describesound fonts, this info can be found in other documents. I've writtenan un-official "Intro to sound fonts" which is on the Smurf web site(http://smurf.sourceforge.net). You can find more in-depth applicationlevel information in the SoundFont specification which can be found inPostScript or perhaps PDF format if you can find it. Trywww.soundfont.com or ftp.creaf.com for the official SoundFontspecification.sound font item A preset, instrument, sample, preset zone or instrument zonesound font tree The Smurf GUI sound font treeLower level sound font representation - sfont.[ch], uif_sfont.[ch]----------------You may want to try to understand how sound fonts are representedinternally in the Smurf Sound Font Editor. I'll attempt to describe thathere.uisf_sfonts (Linked list)||-[+] (UISFont *) untitled SF 1||-[-] (UISFont *) untitled SF 2| || |-- (SFTreeNodes *) nodes (pointers to nodes in the GUI tree)| || *-[-] (SFData *) sf| || |-- preset (linked list of SFPresets)| |-- inst (linked list of SFInsts)| *-- sample (linked list of SFSamples)|*-[+] (UISFont *) untitled SF 3SFPreset (SFInst is the same except for extra preset related info)|-- Name, prenum, bank, etc.*-- zone (linked list of SFZones)SFZone (structure)|-- instsamp (pointer to an instrument or sample)|-- gen (linked list of generators, effects)*-- mod (linked list of moderators, MIDI controls modulating effects)Most of the low level sound font manipulation occurs in sfont.c withuif_sfont.c being the user interface (GUI) routines.uisf_sfonts is a linked list of the currently open sound fonts. Eachpointer in this list points to a UISFont structure which essentiallycombines the non-GUI SFData structure with SFTreeNodes.SFTreeNodes is a structure with pointers to nodes in the GTK soundfont CTree widget of the top level branches for that soundfont. Fields: sfont (sfont root node), preset (preset root node),melodic (preset melodic branch) etc.Unique sound font item identifiers (not pointers!) - uif_sftree.[ch]----------------When dealing with user selections of sound font items and undo/redofunctionality, it becomes necessary to have a unique identifier for eachitem. This identifier should not be dependant on a memory location (apointer for instance).Why not pointers you ask? Example scenario when using pointers (skipif you're in a hurry :)<scenario>The user pops a preset rename dialog and gets distracted withsomething else. The dialog gets hidden by some other app and the userforgets all about it. Later when she comes back to editing the soundfont, she decides to destroy that particular preset. All is wellright? Well yes, until she finds that rename dialog again. Not reallythinking about it she just says okay. Smurf seg faults :( Passingaround non-static pointer references in a GUI environment is not agood idea. The rename dialog used a pointer to a preset that no longerexists.</scenario>Rather than making all dialogs "modal" (all other user interfacefunctions are frozen until dialog closes) a unique integer is used toidentify each item and a lookup is done to get the pointer to thedata. NULL is returned if a non-existing ID is looked up, allowingSmurf to handle the situation, instead of crash (most often the itemis just skipped silently).A GLib "keyed data list" is used to map a unique integer ID to apointer to the item data. Each item is assigned a unique ID when it isadded to the sound font tree. This key is removed when the item isdestroyed.The data type used for the unique integer ID is called a GQuark.Sound font tree - uif_sftree.[ch]----------------The pointer obtained from a GQuark lookup in the sound font item keyeddata list, is a pointer to a GtkCTreeNode in the sound font tree.A pointer can be stored in each GtkCTreeNode in a CTree./* each node in the tree points to one of these */typedef struct _SFTreeRef{ SFNodeType type; /* the type of node */ GQuark quarkid; /* sound font item keyed data list ID */ gpointer dptr; /* pointer to data associated with this type */}SFTreeRef;This structure contains a type enum which describes the item's type(NODE_SFONT, NODE_PRESET, etc), the node's quarkid (the same ID we startedwith, so we can get the GQuark id given a GtkCTreeNode *), pointer to dataassociated with this node.'dptr' in SFTreeRef points to different types of data, depending on the 'type'.Here is what it will point to for different types of nodes:type | dptr data type----------------------------------------NODE_SFONT | UISFont *dptr (UISFont struct associated with the sound font)NODE_PRESET | GList *dptr->data = SFPreset *NODE_INST | GList *dptr->data = SFInst *NODE_SAMPLE | GList *dptr->data = SFSample *NODE_PZONE | GList *dptr->data = SFZone *NODE_IZONE | GList *dptr->data = SFZone *others | NULLNotice that for most item types dptr points to a GList item. These are the sameGLists that are referenced by the SFData structure (described above).This system essentially binds the GUI related variables (GtkCTreeNode *) and thelower level SFData, SFPreset, SFInst, etc structures.Here is an example routine that expects a GQuark sfitem identifier andcloses the sound font that owns the sfitem. We'll use some of the macrosdefined in uif_sftree.h to help us.voidexample_close_function (GQuark sfquark){ UISFont *uisf; GtkCTreeNode *node; SFTreeRef *ref; /* look up the quark in the sftree_items keyed data list */ node = SFTREE_LOOKUP_QUARK (sfquark); /* node would equal NULL if item doesn't exist anymore */ if (!node) return; /* we now have the (GtkCTreeNode *) which references a node in the GUI sound font CTree */ /* find this node's root sound font node (type = NODE_SFONT) and fetch the UISFont structure from it */ uisf = SFTREE_UPFIND_UISF (node); /* close the sound font, sfont_close expects (SFData *) */ sfont_close (uisf->sf);}Smurf undo system----------------Smurf has a rather flexible undo system. The undo system is based on atree rather than queue or list. This means that, from the user pointof view, multiple changes can be easily tested. Performing an action,undoing it, then performing another action would cause the stateinformation for the first action to be destroyed when using atraditional undo LIST. But with a TREE, another branch is startedinstead.sfundo.c contains the undo system functions.sfdofunc.c contains the functions for saving/restoring the state of specificactions.The word "do" is used to signify things having to do with bothundo/redo stuff. The tree is based on the GNode glib data type, whichdefines a data type and functions for manipulating N-ary trees (a treewith arbitrary # of branches).SFDoTree sfdo_tree (structure)|-- GNode *root (dummy root node of tree, root->data = NULL)|-- GNode *curpos (current position in undo history)*-- GList *groups (list of currently active groups and sub groups)GNode *example_item (an example of an item in the sfdo_tree)|-- GNode *next, *prev (point to next and previous siblings, i.e. branches)|-- GNode *parent (parent of this node, NULL for root node)|-- GNode *children (first child or NULL if last node of this branch)*-- SFDoEntry *data (actually a gpointer which is equiv to a void *) |-- gchar *descr (description of this action) *-- GList *items (multiple do items "grouped" by this SFDoEntry) |-<list> |-[-] SFDoItem * | |-- guint16 type | *-- gpointer state *-[+] SFDoItem *A "do" tree consists of a tree of SFDoEntries which are linked listsof SFDoItems. The SFDoEntries are groups of SFDoItems essentially andmany operations act on them as a group. Each SFDoItem has anenumerated type (generator, sample, sampledata, preset, etc) and apointer to the associated "state" data which can be used to restorethe state of that type of object. Only a new entry (curpos) can beused for grouping. Groups can be nested. The same SFDoEntry is usedfor nested groups. A list of SFDoItems is kept in the tree, each is apointer to the last node of the previous group. This list is temporaryand exists only while the entry is opened as a group. Therefore subgroups are only available while they are open. Sub groups are usefulfor operations that call apon other functions that act on many itemsand group them. Should one of these functions fail, it would undo itsown group of changes, and return FAIL. The calling routine could thenundo all the other group data.Bye bye now------------------Okay, so that was some info about the Smurf Sound Font Editor source code.I'm sure there are a lot of other things that would be helpful to put in here,but I don't want to do it right now. If there is something that you can't figureout, let me know. Perhaps I'll add it to this document.Happy hacking.. Josh Green <jgreen@users.sourceforge.net>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -