<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>libkmid: gusout.cc Source File (libkmid)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../.."><img id="nav_header_logo" alt="Home" align="left" src="../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <div id="nav_header_title" align="left">KDE API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_right" style="text-align: left;"> / <a href="../..">API Reference</a> / <a href=".">libkmid</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <a name="content"></a> <!-- Generated by Doxygen 1.7.4 --> <div class="header"> <div class="headertitle"> <div class="title">gusout.cc</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/**************************************************************************</span> <a name="l00002"></a>00002 <span class="comment"></span> <a name="l00003"></a>00003 <span class="comment"> gusout.cc - class GUSOut which implements support for Gravis</span> <a name="l00004"></a>00004 <span class="comment"> Ultrasound cards through a /dev/sequencer device</span> <a name="l00005"></a>00005 <span class="comment"> This file is part of LibKMid 0.9.5</span> <a name="l00006"></a>00006 <span class="comment"> Copyright (C) 1998,99,2000 Antonio Larrosa Jimenez</span> <a name="l00007"></a>00007 <span class="comment"> LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00010"></a>00010 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00011"></a>00011 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00012"></a>00012 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00017"></a>00017 <span class="comment"> Library General Public License for more details.</span> <a name="l00018"></a>00018 <span class="comment"></span> <a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU Library General Public License</span> <a name="l00020"></a>00020 <span class="comment"> along with this library; see the file COPYING.LIB. If not, write to</span> <a name="l00021"></a>00021 <span class="comment"> the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,</span> <a name="l00022"></a>00022 <span class="comment"> Boston, MA 02110-1301, USA.</span> <a name="l00023"></a>00023 <span class="comment"></span> <a name="l00024"></a>00024 <span class="comment"> Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org></span> <a name="l00025"></a>00025 <span class="comment"></span> <a name="l00026"></a>00026 <span class="comment">***************************************************************************/</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "gusout.h"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "sndcard.h"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "midispec.h"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "gusvoices.h"</span> <a name="l00031"></a>00031 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <unistd.h></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <fcntl.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <stdio.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <sys/ioctl.h></span> <a name="l00036"></a>00036 <span class="preprocessor">#include <errno.h></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <string.h></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <sys/param.h></span> <a name="l00039"></a>00039 <span class="preprocessor">#include <stdlib.h></span> <a name="l00040"></a>00040 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00041"></a>00041 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#endif</span> <a name="l00043"></a>00043 <span class="preprocessor"></span> <a name="l00044"></a>00044 SEQ_USE_EXTBUF(); <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#ifdef HAVE_OSS_SUPPORT</span> <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="keyword">struct </span>pat_header <a name="l00048"></a>00048 { <a name="l00049"></a>00049 <span class="keywordtype">char</span> magic[12]; <a name="l00050"></a>00050 <span class="keywordtype">char</span> <a class="codeRef" doxygen="kdecore.tag:../../kdecore/html/" href="../../kdecore/html/namespaceKDE.html#aa7220767389d3c119ac8cf38bf333c55">version</a>[10]; <a name="l00051"></a>00051 <span class="keywordtype">char</span> <a class="codeRef" doxygen="kdecore.tag:../../kdecore/html/" href="../../kdecore/html/namespaceKStdAccel.html#a35d2086a231403eb59f82ea75da4cb4c">description</a>[60]; <a name="l00052"></a>00052 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> instruments; <a name="l00053"></a>00053 <span class="keywordtype">char</span> voices; <a name="l00054"></a>00054 <span class="keywordtype">char</span> channels; <a name="l00055"></a>00055 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> nr_waveforms; <a name="l00056"></a>00056 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> master_volume; <a name="l00057"></a>00057 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> data_size; <a name="l00058"></a>00058 }; <a name="l00059"></a>00059 <span class="keyword">struct </span>sample_header <a name="l00060"></a>00060 { <a name="l00061"></a>00061 <span class="keywordtype">char</span> <a class="codeRef" doxygen="kdecore.tag:../../kdecore/html/" href="../../kdecore/html/namespaceKStdAccel.html#a737bc2466b1f000625fe8ebddffbb09d">name</a>[7]; <a name="l00062"></a>00062 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> fractions; <a name="l00063"></a>00063 <span class="keywordtype">long</span> len; <a name="l00064"></a>00064 <span class="keywordtype">long</span> loop_start; <a name="l00065"></a>00065 <span class="keywordtype">long</span> loop_end; <a name="l00066"></a>00066 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> base_freq; <a name="l00067"></a>00067 <span class="keywordtype">long</span> low_note; <a name="l00068"></a>00068 <span class="keywordtype">long</span> high_note; <a name="l00069"></a>00069 <span class="keywordtype">long</span> base_note; <a name="l00070"></a>00070 <span class="keywordtype">short</span> detune; <a name="l00071"></a>00071 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> panning; <a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> envelope_rate[6]; <a name="l00074"></a>00074 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> envelope_offset[6]; <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tremolo_sweep; <a name="l00077"></a>00077 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tremolo_rate; <a name="l00078"></a>00078 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tremolo_depth; <a name="l00079"></a>00079 <a name="l00080"></a>00080 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> vibrato_sweep; <a name="l00081"></a>00081 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> vibrato_rate; <a name="l00082"></a>00082 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> vibrato_depth; <a name="l00083"></a>00083 <a name="l00084"></a>00084 <span class="keywordtype">char</span> modes; <a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="keywordtype">short</span> scale_frequency; <a name="l00087"></a>00087 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> scale_factor; <a name="l00088"></a>00088 }; <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="keywordtype">int</span> get_dint(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *p) <a name="l00091"></a>00091 { <a name="l00092"></a>00092 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> v=0; <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i<4;i++) <a name="l00095"></a>00095 { <a name="l00096"></a>00096 v |= (p[i] << (i*8)); <a name="l00097"></a>00097 } <a name="l00098"></a>00098 <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)v; <a name="l00099"></a>00099 } <a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> get_word(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *p) <a name="l00102"></a>00102 { <a name="l00103"></a>00103 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> v=0; <a name="l00104"></a>00104 <a name="l00105"></a>00105 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i<2;i++) <a name="l00106"></a>00106 v |= (*p++ << (i*8)); <a name="l00107"></a>00107 <span class="keywordflow">return</span> (<span class="keywordtype">short</span>)v; <a name="l00108"></a>00108 } <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="preprocessor">#endif</span> <a name="l00111"></a>00111 <span class="preprocessor"></span> <a name="l00112"></a><a class="code" href="classGUSOut.html#adcd5eadb028f11bed62fdbd268738776">00112</a> <a class="code" href="classGUSOut.html#adcd5eadb028f11bed62fdbd268738776" title="Constructor.">GUSOut::GUSOut</a>(<span class="keywordtype">int</span> d,<span class="keywordtype">int</span> total) <a name="l00113"></a>00113 { <a name="l00114"></a>00114 seqfd = -1; <a name="l00115"></a>00115 devicetype=KMID_GUS; <a name="l00116"></a>00116 device= d; <a name="l00117"></a>00117 _ok=1; <a name="l00118"></a>00118 <a name="l00119"></a>00119 use8bit=0; <a name="l00120"></a>00120 nvoices=total; <a name="l00121"></a>00121 vm=<span class="keyword">new</span> VoiceManager(nvoices); <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a><a class="code" href="classGUSOut.html#a811d3051ffb01c2085f60feba44f49d3">00124</a> <a class="code" href="classGUSOut.html#a811d3051ffb01c2085f60feba44f49d3" title="Destructor.">GUSOut::~GUSOut</a>() <a name="l00125"></a>00125 { <a name="l00126"></a>00126 <a class="code" href="classGUSOut.html#ac27415d9031d37869f4e6641abf6848f" title="See MidiOut::closeDev()">closeDev</a>(); <a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="keyword">delete</span> vm; <a name="l00129"></a>00129 <span class="keywordflow">if</span> (delete_GUS_patches_directory) <a name="l00130"></a>00130 { <a name="l00131"></a>00131 free((<span class="keywordtype">char</span> *)GUS_patches_directory); <a name="l00132"></a>00132 delete_GUS_patches_directory = 0; <a name="l00133"></a>00133 GUS_patches_directory=<span class="stringliteral">"/etc"</span>; <a name="l00134"></a>00134 } <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00137"></a><a class="code" href="classGUSOut.html#a00ced18d9a643ceffb16faa4b622e55a">00137</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a00ced18d9a643ceffb16faa4b622e55a" title="See MidiOut::openDev()">GUSOut::openDev</a> (<span class="keywordtype">int</span> sqfd) <a name="l00138"></a>00138 { <a name="l00139"></a>00139 _ok=1; <a name="l00140"></a>00140 seqfd = sqfd; <a name="l00141"></a>00141 <span class="comment">//vm->clearLists();</span> <a name="l00142"></a>00142 <span class="keywordflow">if</span> (seqfd==-1) <a name="l00143"></a>00143 { <a name="l00144"></a>00144 printfdebug(<span class="stringliteral">"ERROR: Could not open /dev/sequencer\n"</span>); <a name="l00145"></a>00145 <span class="keywordflow">return</span>; <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00148"></a>00148 <span class="preprocessor">#ifdef HAVE_OSS_SUPPORT</span> <a name="l00149"></a>00149 <span class="preprocessor"></span> <a name="l00150"></a>00150 <span class="comment">//seqbuf_clean();</span> <a name="l00151"></a>00151 <span class="comment">//ioctl(seqfd,SNDCTL_SEQ_RESET);</span> <a name="l00152"></a>00152 <span class="comment">//ioctl(seqfd,SNDCTL_SEQ_PANIC);</span> <a name="l00153"></a>00153 <a name="l00154"></a>00154 <span class="keywordflow">if</span> (ioctl(seqfd, SNDCTL_SEQ_RESETSAMPLES, &device)==-1) <a name="l00155"></a>00155 { <a name="l00156"></a>00156 printfdebug(<span class="stringliteral">"Error reseting gus samples. Please report\n"</span>); <a name="l00157"></a>00157 }; <a name="l00158"></a>00158 use8bit=0; <a name="l00159"></a>00159 totalmemory = device; <a name="l00160"></a>00160 ioctl(seqfd, SNDCTL_SYNTH_MEMAVL, &totalmemory); <a name="l00161"></a>00161 freememory = device; <a name="l00162"></a>00162 ioctl(seqfd, SNDCTL_SYNTH_MEMAVL, &freememory); <a name="l00163"></a>00163 <a name="l00164"></a>00164 <span class="preprocessor">#endif</span> <a name="l00165"></a>00165 <span class="preprocessor"></span> <a name="l00166"></a>00166 <a name="l00167"></a>00167 } <a name="l00168"></a>00168 <a name="l00169"></a><a class="code" href="classGUSOut.html#ac27415d9031d37869f4e6641abf6848f">00169</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#ac27415d9031d37869f4e6641abf6848f" title="See MidiOut::closeDev()">GUSOut::closeDev</a> (<span class="keywordtype">void</span>) <a name="l00170"></a>00170 { <a name="l00171"></a>00171 <span class="keywordflow">if</span> (!<a class="code" href="classMidiOut.html#adb7701cf6f4fea7bfdf4b110f3fd2fd2" title="Returns true if everything's ok and false if there has been any problem.">ok</a>()) <span class="keywordflow">return</span>; <a name="l00172"></a>00172 vm->clearLists(); <a name="l00173"></a>00173 <span class="comment">//if (seqfd>=0)</span> <a name="l00174"></a>00174 <span class="comment">// close(seqfd);</span> <a name="l00175"></a>00175 seqfd=-1; <a name="l00176"></a>00176 } <a name="l00177"></a>00177 <a name="l00178"></a><a class="code" href="classGUSOut.html#aa02cb206225bec46285f11584a9eb6f7">00178</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#aa02cb206225bec46285f11584a9eb6f7" title="See MidiOut::initDev()">GUSOut::initDev</a> (<span class="keywordtype">void</span>) <a name="l00179"></a>00179 { <a name="l00180"></a>00180 <span class="preprocessor">#ifdef HAVE_OSS_SUPPORT</span> <a name="l00181"></a>00181 <span class="preprocessor"></span> <span class="keywordtype">int</span> chn; <a name="l00182"></a>00182 <span class="keywordflow">if</span> (!<a class="code" href="classMidiOut.html#adb7701cf6f4fea7bfdf4b110f3fd2fd2" title="Returns true if everything's ok and false if there has been any problem.">ok</a>()) <span class="keywordflow">return</span>; <a name="l00183"></a>00183 uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7}; <a name="l00184"></a>00184 <a class="code" href="classGUSOut.html#aff190956fe307114e1330201f06ae5b8" title="It's an empty function, as GUS synths don't support System Exclusive messages.">sysex</a>(gm_reset, <span class="keyword">sizeof</span>(gm_reset)); <a name="l00185"></a>00185 <span class="keywordflow">for</span> (chn=0;chn<16;chn++) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 chnmute[chn]=0; <a name="l00188"></a>00188 <a class="code" href="classGUSOut.html#acf231cc3b64a9933b31d52171f056de3" title="See MidiOut::chnPatchChange()">chnPatchChange</a>(chn,0); <a name="l00189"></a>00189 <span class="comment">// chnPressure(chn,127);</span> <a name="l00190"></a>00190 <a class="code" href="classGUSOut.html#af87699d2bb0e317d02fdd3e525c54dfb" title="See MidiOut::chnPitchBender()">chnPitchBender</a>(chn, 0x00, 0x40); <a name="l00191"></a>00191 <a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716" title="See MidiOut::chnController()">chnController</a>(chn, CTL_MAIN_VOLUME,127); <a name="l00192"></a>00192 <a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716" title="See MidiOut::chnController()">chnController</a>(chn, CTL_EXT_EFF_DEPTH, 0); <a name="l00193"></a>00193 <a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716" title="See MidiOut::chnController()">chnController</a>(chn, CTL_CHORUS_DEPTH, 0); <a name="l00194"></a>00194 <a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716" title="See MidiOut::chnController()">chnController</a>(chn, 0x4a, 127); <a name="l00195"></a>00195 } <a name="l00196"></a>00196 <a name="l00197"></a>00197 <a name="l00198"></a>00198 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < nvoices; i++) <a name="l00199"></a>00199 { <a name="l00200"></a>00200 SEQ_CONTROL(device, i, SEQ_VOLMODE, VOL_METHOD_LINEAR); <a name="l00201"></a>00201 SEQ_STOP_NOTE(device, i, vm->note(i), 64); <a name="l00202"></a>00202 } <a name="l00203"></a>00203 <a name="l00204"></a>00204 <span class="preprocessor">#endif</span> <a name="l00205"></a>00205 <span class="preprocessor"></span>} <a name="l00206"></a>00206 <a name="l00207"></a>00207 <a name="l00208"></a><a class="code" href="classGUSOut.html#a650e3abbe8be4cfeeb48f99a8ed1521e">00208</a> <span class="keywordtype">int</span> <a class="code" href="classGUSOut.html#a650e3abbe8be4cfeeb48f99a8ed1521e" title="Returns p if the patch with number p has been correctly loaded.">GUSOut::patch</a>(<span class="keywordtype">int</span> p) <a name="l00209"></a>00209 { <a name="l00210"></a>00210 <span class="keywordflow">if</span> (patchloaded[p]==1) <span class="keywordflow">return</span> p; <a name="l00211"></a>00211 printfdebug(<span class="stringliteral">"Not loaded %d!\n"</span>,p); <a name="l00212"></a>00212 p=0; <a name="l00213"></a>00213 <span class="keywordflow">while</span> ((p<256)&&(patchloaded[p]==0)) p++; <a name="l00214"></a>00214 <span class="keywordflow">return</span> p; <a name="l00215"></a>00215 } <a name="l00216"></a>00216 <a name="l00217"></a><a class="code" href="classGUSOut.html#a22341d7226833443ae3e3a5ce3719965">00217</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a22341d7226833443ae3e3a5ce3719965" title="See MidiOut::noteOn()">GUSOut::noteOn</a> (uchar chn, uchar note, uchar vel) <a name="l00218"></a>00218 { <a name="l00219"></a>00219 <span class="keywordflow">if</span> (vel==0) <a name="l00220"></a>00220 { <a name="l00221"></a>00221 <a class="code" href="classGUSOut.html#a19b08017bd073198306bf623f036e3a1" title="See MidiOut::noteOff()">noteOff</a>(chn,note,vel); <a name="l00222"></a>00222 } <a name="l00223"></a>00223 <span class="keywordflow">else</span> <a name="l00224"></a>00224 { <a name="l00225"></a>00225 <span class="keywordflow">if</span> (chn==PERCUSSION_CHANNEL) <a name="l00226"></a>00226 { <a name="l00227"></a>00227 <span class="keywordflow">if</span> (patchloaded[note+128]==0) <span class="keywordflow">return</span>; <a name="l00228"></a>00228 <span class="keywordflow">else</span> <a name="l00229"></a>00229 <span class="keywordflow">if</span> (patchloaded[chnpatch[chn]]==0) <span class="keywordflow">return</span>; <a name="l00230"></a>00230 }; <a name="l00231"></a>00231 <span class="keywordtype">int</span> v=vm->allocateVoice(chn,note); <a name="l00232"></a>00232 <span class="keywordtype">int</span> p; <a name="l00233"></a>00233 <span class="keywordflow">if</span> (chn==PERCUSSION_CHANNEL) <a name="l00234"></a>00234 SEQ_SET_PATCH(device,v ,p=<a class="code" href="classGUSOut.html#a650e3abbe8be4cfeeb48f99a8ed1521e" title="Returns p if the patch with number p has been correctly loaded.">patch</a>(note+128)) <a name="l00235"></a>00235 <span class="keywordflow">else</span> <a name="l00236"></a>00236 SEQ_SET_PATCH(device,v ,p=map-><a class="code" href="classMidiMapper.html#a7f6e49b422e84e432bc9d6f762135e7a" title="Returns the patch which pgm used on channel chn should be mapped to.">patch</a>(chn,chnpatch[chn])); <a name="l00237"></a>00237 SEQ_BENDER(device, v, chnbender[chn]); <a name="l00238"></a>00238 <a name="l00239"></a>00239 SEQ_START_NOTE(device, v, note, vel); <a name="l00240"></a>00240 <span class="comment">// SEQ_CONTROL(device, v, CTL_MAIN_VOLUME, chncontroller[chn][CTL_MAIN_VOLUME]);</span> <a name="l00241"></a>00241 SEQ_CHN_PRESSURE(device, v , chnpressure[chn]); <a name="l00242"></a>00242 } <a name="l00243"></a>00243 <a name="l00244"></a>00244 printfdebug(<span class="stringliteral">"Note ON >\t chn : %d\tnote : %d\tvel: %d\n"</span>,chn,note,vel); <a name="l00245"></a>00245 } <a name="l00246"></a>00246 <a name="l00247"></a><a class="code" href="classGUSOut.html#a19b08017bd073198306bf623f036e3a1">00247</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a19b08017bd073198306bf623f036e3a1" title="See MidiOut::noteOff()">GUSOut::noteOff</a> (uchar chn, uchar note, uchar vel) <a name="l00248"></a>00248 { <a name="l00249"></a>00249 <span class="keywordtype">int</span> i; <a name="l00250"></a>00250 vm->initSearch(); <a name="l00251"></a>00251 <span class="keywordflow">while</span> ((i=vm->search(chn,note))!=-1) <a name="l00252"></a>00252 { <a name="l00253"></a>00253 SEQ_STOP_NOTE(device, i, note, vel); <a name="l00254"></a>00254 vm->deallocateVoice(i); <a name="l00255"></a>00255 } <a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00258"></a>00258 <span class="preprocessor"></span> printf(<span class="stringliteral">"Note OFF >\t chn : %d\tnote : %d\tvel: %d\n"</span>,chn,note,vel); <a name="l00259"></a>00259 <span class="preprocessor">#endif</span> <a name="l00260"></a>00260 <span class="preprocessor"></span>} <a name="l00261"></a>00261 <a name="l00262"></a><a class="code" href="classGUSOut.html#a4347f6364c371831ce301021ce766eee">00262</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a4347f6364c371831ce301021ce766eee" title="See MidiOut::keyPressure()">GUSOut::keyPressure</a> (uchar chn, uchar note, uchar vel) <a name="l00263"></a>00263 { <a name="l00264"></a>00264 <span class="keywordtype">int</span> i; <a name="l00265"></a>00265 vm->initSearch(); <a name="l00266"></a>00266 <span class="keywordflow">while</span> ((i=vm->search(chn,note))!=-1) <a name="l00267"></a>00267 SEQ_KEY_PRESSURE(device, i, note,vel); <a name="l00268"></a>00268 } <a name="l00269"></a>00269 <a name="l00270"></a><a class="code" href="classGUSOut.html#acf231cc3b64a9933b31d52171f056de3">00270</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#acf231cc3b64a9933b31d52171f056de3" title="See MidiOut::chnPatchChange()">GUSOut::chnPatchChange</a> (uchar chn, uchar patch) <a name="l00271"></a>00271 { <a name="l00272"></a>00272 <span class="keywordflow">if</span> (chn==PERCUSSION_CHANNEL) <span class="keywordflow">return</span>; <a name="l00273"></a>00273 <span class="keywordtype">int</span> i; <a name="l00274"></a>00274 vm->initSearch(); <a name="l00275"></a>00275 <span class="keywordflow">while</span> ((i=vm->search(chn))!=-1) <a name="l00276"></a>00276 SEQ_SET_PATCH(device,i,map-><a class="code" href="classMidiMapper.html#a7f6e49b422e84e432bc9d6f762135e7a" title="Returns the patch which pgm used on channel chn should be mapped to.">patch</a>(chn,patch)); <a name="l00277"></a>00277 chnpatch[chn]=<a class="code" href="classGUSOut.html#a650e3abbe8be4cfeeb48f99a8ed1521e" title="Returns p if the patch with number p has been correctly loaded.">patch</a>; <a name="l00278"></a>00278 <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a><a class="code" href="classGUSOut.html#a9c9c76df32f088d2b8ed842f122a3827">00281</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a9c9c76df32f088d2b8ed842f122a3827" title="See MidiOut::chnPressure()">GUSOut::chnPressure</a> (uchar <span class="comment">/*chn*/</span>, uchar <span class="comment">/*vel*/</span>) <a name="l00282"></a>00282 { <a name="l00283"></a>00283 <span class="comment">/* int i;</span> <a name="l00284"></a>00284 <span class="comment"> vm->initSearch();</span> <a name="l00285"></a>00285 <span class="comment"> while ((i=vm->search(chn))!=-1)</span> <a name="l00286"></a>00286 <span class="comment"> SEQ_CHN_PRESSURE(device, i , vel);</span> <a name="l00287"></a>00287 <span class="comment"> chnpressure[chn]=vel;</span> <a name="l00288"></a>00288 <span class="comment"> */</span> <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a><a class="code" href="classGUSOut.html#af87699d2bb0e317d02fdd3e525c54dfb">00291</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#af87699d2bb0e317d02fdd3e525c54dfb" title="See MidiOut::chnPitchBender()">GUSOut::chnPitchBender</a>(uchar chn,uchar lsb, uchar msb) <a name="l00292"></a>00292 { <a name="l00293"></a>00293 chnbender[chn]=((int)msb<<7) | (lsb & 0x7F); <a name="l00294"></a>00294 <a name="l00295"></a>00295 <span class="keywordtype">int</span> i; <a name="l00296"></a>00296 vm->initSearch(); <a name="l00297"></a>00297 <span class="keywordflow">while</span> ((i=vm->search(chn))!=-1) <a name="l00298"></a>00298 SEQ_BENDER(device, i, chnbender[chn]); <a name="l00299"></a>00299 } <a name="l00300"></a>00300 <a name="l00301"></a><a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716">00301</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a24ef8810d86d67a25970eb1c86974716" title="See MidiOut::chnController()">GUSOut::chnController</a> (uchar chn, uchar ctl, uchar v) <a name="l00302"></a>00302 { <a name="l00303"></a>00303 <span class="keywordflow">if</span> ((ctl==11)||(ctl==7)) <a name="l00304"></a>00304 { <a name="l00305"></a>00305 v=(v*volumepercentage)/100; <a name="l00306"></a>00306 <span class="keywordflow">if</span> (v>127) v=127; <a name="l00307"></a>00307 }; <a name="l00308"></a>00308 <a name="l00309"></a>00309 <span class="keywordtype">int</span> i; <a name="l00310"></a>00310 vm->initSearch(); <a name="l00311"></a>00311 <span class="keywordflow">while</span> ((i=vm->search(chn))!=-1) <a name="l00312"></a>00312 SEQ_CONTROL(device, i, ctl, v); <a name="l00313"></a>00313 <a name="l00314"></a>00314 chncontroller[chn][ctl]=v; <a name="l00315"></a>00315 } <a name="l00316"></a>00316 <a name="l00317"></a><a class="code" href="classGUSOut.html#aff190956fe307114e1330201f06ae5b8">00317</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#aff190956fe307114e1330201f06ae5b8" title="It's an empty function, as GUS synths don't support System Exclusive messages.">GUSOut::sysex</a>(uchar *, ulong ) <a name="l00318"></a>00318 { <a name="l00319"></a>00319 <a name="l00320"></a>00320 } <a name="l00321"></a>00321 <a name="l00322"></a><a class="code" href="classGUSOut.html#a1d33214c4a154ec818b68341e582a58f">00322</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#a1d33214c4a154ec818b68341e582a58f" title="Sets the directory where the GUS patches are stored, that is, where the acpiano.pat, ...">GUSOut::setGUSPatchesDirectory</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *dir) <a name="l00323"></a>00323 { <a name="l00324"></a>00324 <span class="keywordflow">if</span> ((dir==NULL)||(dir[0]==0)) <span class="keywordflow">return</span>; <a name="l00325"></a>00325 <span class="keywordflow">if</span> (delete_GUS_patches_directory) <a name="l00326"></a>00326 free((<span class="keywordtype">char</span> *)GUS_patches_directory); <a name="l00327"></a>00327 <a name="l00328"></a>00328 GUS_patches_directory = strdup(dir); <a name="l00329"></a>00329 delete_GUS_patches_directory=1; <a name="l00330"></a>00330 } <a name="l00331"></a>00331 <a name="l00332"></a>00332 <span class="keyword">const</span> <span class="keywordtype">char</span> *GUSOut::patchName(<span class="keywordtype">int</span> pgm) <a name="l00333"></a>00333 { <a name="l00334"></a>00334 <span class="keywordflow">return</span> GUS_voice_names[pgm]; <a name="l00335"></a>00335 } <a name="l00336"></a>00336 <a name="l00337"></a>00337 <a name="l00338"></a><a class="code" href="classGUSOut.html#a791b7cd77daa1f4bfac78a2e922e87e5">00338</a> <span class="keywordtype">int</span> <a class="code" href="classGUSOut.html#a791b7cd77daa1f4bfac78a2e922e87e5" title="Loads a single patch on the synthesizer memory.">GUSOut::loadPatch</a>(<span class="keywordtype">int</span> pgm) <a name="l00339"></a>00339 { <a name="l00340"></a>00340 <span class="preprocessor">#ifdef HAVE_OSS_SUPPORT</span> <a name="l00341"></a>00341 <span class="preprocessor"></span> <span class="keyword">struct </span>pat_header header; <a name="l00342"></a>00342 <span class="keyword">struct </span>sample_header sample; <a name="l00343"></a>00343 <span class="keywordflow">if</span> (patchloaded[pgm]==1) <a name="l00344"></a>00344 { <a name="l00345"></a>00345 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00346"></a>00346 <span class="preprocessor"></span> printf(<span class="stringliteral">"Trying to reload a patch. This should never happen, please report.\n"</span>); <a name="l00347"></a>00347 <span class="preprocessor">#endif</span> <a name="l00348"></a>00348 <span class="preprocessor"></span> <span class="keywordflow">return</span> 0; <a name="l00349"></a>00349 } <a name="l00350"></a>00350 <span class="keywordflow">if</span> ((patchName(pgm)==NULL)||((patchName(pgm))[0]==0)) <a name="l00351"></a>00351 { <a name="l00352"></a>00352 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00353"></a>00353 <span class="preprocessor"></span> printf(<span class="stringliteral">"Couldn't guess patch name for patch number %d\n"</span>,pgm); <a name="l00354"></a>00354 <span class="preprocessor">#endif</span> <a name="l00355"></a>00355 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00356"></a>00356 } <a name="l00357"></a>00357 <span class="keywordtype">char</span> *s=<span class="keyword">new</span> <span class="keywordtype">char</span>[strlen(GUS_patches_directory)+strlen(patchName(pgm))+10]; <a name="l00358"></a>00358 <span class="keywordflow">if</span> (s==NULL) <span class="keywordflow">return</span> -1; <a name="l00359"></a>00359 sprintf(s,<span class="stringliteral">"%s/%s.pat"</span>,GUS_patches_directory,patchName(pgm)); <a name="l00360"></a>00360 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00361"></a>00361 <span class="preprocessor"></span> printf(<span class="stringliteral">"Loading patch : %s\n"</span>,s); <a name="l00362"></a>00362 <span class="preprocessor">#endif</span> <a name="l00363"></a>00363 <span class="preprocessor"></span> <span class="keyword">struct </span>patch_info *<a class="code" href="classGUSOut.html#a650e3abbe8be4cfeeb48f99a8ed1521e" title="Returns p if the patch with number p has been correctly loaded.">patch</a>=NULL; <a name="l00364"></a>00364 <span class="keyword">struct </span>stat info; <a name="l00365"></a>00365 <span class="keywordflow">if</span> (stat(s, &info)==-1) <a name="l00366"></a>00366 { <a name="l00367"></a>00367 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00368"></a>00368 <span class="preprocessor"></span> printf(<span class="stringliteral">"File %s doesn't exist\n"</span>,s); <a name="l00369"></a>00369 <span class="preprocessor">#endif</span> <a name="l00370"></a>00370 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00371"></a>00371 } <a name="l00372"></a>00372 <a name="l00373"></a>00373 FILE *fh=fopen(s,<span class="stringliteral">"rb"</span>); <a name="l00374"></a>00374 <span class="keywordflow">if</span> (fh==NULL) <a name="l00375"></a>00375 { <a name="l00376"></a>00376 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00377"></a>00377 <span class="preprocessor"></span> printf(<span class="stringliteral">"Couldn't open patch %s\n"</span>,s); <a name="l00378"></a>00378 <span class="preprocessor">#endif</span> <a name="l00379"></a>00379 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00380"></a>00380 } <a name="l00381"></a>00381 <a name="l00382"></a>00382 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tmp[256]; <a name="l00383"></a>00383 <span class="keywordflow">if</span> (fread(tmp,1,0xef,fh)!=0xef) <a name="l00384"></a>00384 { <a name="l00385"></a>00385 fclose(fh); <a name="l00386"></a>00386 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00387"></a>00387 <span class="preprocessor"></span> printf(<span class="stringliteral">"Short file ! \n"</span>); <a name="l00388"></a>00388 <span class="preprocessor">#endif</span> <a name="l00389"></a>00389 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00390"></a>00390 } <a name="l00391"></a>00391 memcpy ((<span class="keywordtype">char</span> *) &header, tmp, <span class="keyword">sizeof</span> (header)); <a name="l00392"></a>00392 <a name="l00393"></a>00393 <span class="keywordflow">if</span> (strncmp(header.magic,<span class="stringliteral">"GF1PATCH110"</span>,12)!=0) <a name="l00394"></a>00394 { <a name="l00395"></a>00395 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00396"></a>00396 <span class="preprocessor"></span> printf(<span class="stringliteral">"File %s is corrupted or it isn't a patch file\n"</span>,s); <a name="l00397"></a>00397 <span class="preprocessor">#endif</span> <a name="l00398"></a>00398 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00399"></a>00399 } <a name="l00400"></a>00400 <span class="keywordflow">if</span> (strncmp(header.version,<span class="stringliteral">"ID#000002"</span>,10)!=0) <a name="l00401"></a>00401 { <a name="l00402"></a>00402 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00403"></a>00403 <span class="preprocessor"></span> printf(<span class="stringliteral">"File %s's version is not supported\n"</span>,s); <a name="l00404"></a>00404 <span class="preprocessor">#endif</span> <a name="l00405"></a>00405 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00406"></a>00406 } <a name="l00407"></a>00407 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> nWaves= *(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> *)&tmp[85]; <a name="l00408"></a>00408 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00409"></a>00409 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> masterVolume= *(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> *)&tmp[87]; <a name="l00410"></a>00410 printf(<span class="stringliteral">"nWaves: %d\n"</span>,nWaves); <a name="l00411"></a>00411 printf(<span class="stringliteral">"masterVolume : %d\n"</span>,masterVolume); <a name="l00412"></a>00412 <span class="preprocessor">#endif</span> <a name="l00413"></a>00413 <span class="preprocessor"></span> <a name="l00414"></a>00414 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> i; <a name="l00415"></a>00415 <span class="keywordtype">int</span> offset=0xef; <a name="l00416"></a>00416 <span class="keywordflow">for</span> (i=0;i<nWaves;i++) <a name="l00417"></a>00417 { <a name="l00418"></a>00418 fseek(fh,offset,SEEK_SET); <a name="l00419"></a>00419 <a name="l00420"></a>00420 <span class="keywordflow">if</span> (fread(tmp,1,<span class="keyword">sizeof</span>(sample),fh) != <span class="keyword">sizeof</span>(sample)) <a name="l00421"></a>00421 { <a name="l00422"></a>00422 fclose(fh); <a name="l00423"></a>00423 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00424"></a>00424 <span class="preprocessor"></span> printf(<span class="stringliteral">"Short file\n"</span>); <a name="l00425"></a>00425 <span class="preprocessor">#endif</span> <a name="l00426"></a>00426 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00427"></a>00427 } <a name="l00428"></a>00428 memcpy ((<span class="keywordtype">char</span> *) &sample, tmp, <span class="keyword">sizeof</span> (sample)); <a name="l00429"></a>00429 sample.fractions = (char)tmp[7]; <a name="l00430"></a>00430 sample.len = get_dint(&tmp[8]); <a name="l00431"></a>00431 sample.loop_start = get_dint(&tmp[12]); <a name="l00432"></a>00432 sample.loop_end = get_dint(&tmp[16]); <a name="l00433"></a>00433 sample.base_freq = get_word(&tmp[20]); <a name="l00434"></a>00434 sample.low_note = get_dint(&tmp[22]); <a name="l00435"></a>00435 sample.high_note = get_dint(&tmp[26]); <a name="l00436"></a>00436 sample.base_note = get_dint(&tmp[30]); <a name="l00437"></a>00437 sample.detune = (short)get_word(&tmp[34]); <a name="l00438"></a>00438 sample.panning = (<span class="keywordtype">unsigned</span> char) tmp[36]; <a name="l00439"></a>00439 <a name="l00440"></a>00440 memcpy (sample.envelope_rate, &tmp[37], 6); <a name="l00441"></a>00441 memcpy (sample.envelope_offset, &tmp[43], 6); <a name="l00442"></a>00442 <a name="l00443"></a>00443 sample.tremolo_sweep = (<span class="keywordtype">unsigned</span> char) tmp[49]; <a name="l00444"></a>00444 sample.tremolo_rate = (<span class="keywordtype">unsigned</span> char) tmp[50]; <a name="l00445"></a>00445 sample.tremolo_depth = (<span class="keywordtype">unsigned</span> char) tmp[51]; <a name="l00446"></a>00446 <a name="l00447"></a>00447 sample.vibrato_sweep = (<span class="keywordtype">unsigned</span> char) tmp[52]; <a name="l00448"></a>00448 sample.vibrato_rate = (<span class="keywordtype">unsigned</span> char) tmp[53]; <a name="l00449"></a>00449 sample.vibrato_depth = (<span class="keywordtype">unsigned</span> char) tmp[54]; <a name="l00450"></a>00450 sample.modes = (<span class="keywordtype">unsigned</span> char) tmp[55]; <a name="l00451"></a>00451 sample.scale_frequency = (short)get_word(&tmp[56]); <a name="l00452"></a>00452 sample.scale_factor = get_word(&tmp[58]); <a name="l00453"></a>00453 <a name="l00454"></a>00454 offset = offset + 96; <a name="l00455"></a>00455 <a name="l00456"></a>00456 patch = (<span class="keyword">struct </span>patch_info *) malloc(<span class="keyword">sizeof</span> (*patch) + sample.len); <a name="l00457"></a>00457 <span class="keywordflow">if</span> (patch == NULL) <a name="l00458"></a>00458 { <a name="l00459"></a>00459 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00460"></a>00460 <span class="preprocessor"></span> printf(<span class="stringliteral">"Not enough memory\n"</span>); <a name="l00461"></a>00461 <span class="preprocessor">#endif</span> <a name="l00462"></a>00462 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00463"></a>00463 } <a name="l00464"></a>00464 patch->key = GUS_PATCH; <a name="l00465"></a>00465 patch->device_no = device; <a name="l00466"></a>00466 patch->instr_no = pgm; <a name="l00467"></a>00467 patch->mode = sample.modes | WAVE_TREMOLO | WAVE_VIBRATO | WAVE_SCALE; <a name="l00468"></a>00468 patch->len = sample.len; <a name="l00469"></a>00469 patch->loop_start = sample.loop_start; <a name="l00470"></a>00470 patch->loop_end = sample.loop_end; <a name="l00471"></a>00471 patch->base_note = sample.base_note; <a name="l00472"></a>00472 patch->high_note = sample.high_note; <a name="l00473"></a>00473 patch->low_note = sample.low_note; <a name="l00474"></a>00474 patch->base_freq = sample.base_freq; <a name="l00475"></a>00475 patch->detuning = sample.detune; <a name="l00476"></a>00476 patch->panning = (sample.panning - 7) * 16; <a name="l00477"></a>00477 <a name="l00478"></a>00478 memcpy (patch->env_rate, sample.envelope_rate, 6); <a name="l00479"></a>00479 memcpy (patch->env_offset, sample.envelope_offset, 6); <a name="l00480"></a>00480 <a name="l00481"></a>00481 patch->tremolo_sweep = sample.tremolo_sweep; <a name="l00482"></a>00482 patch->tremolo_rate = sample.tremolo_rate; <a name="l00483"></a>00483 patch->tremolo_depth = sample.tremolo_depth; <a name="l00484"></a>00484 <a name="l00485"></a>00485 patch->vibrato_sweep = sample.vibrato_sweep; <a name="l00486"></a>00486 patch->vibrato_rate = sample.vibrato_rate; <a name="l00487"></a>00487 patch->vibrato_depth = sample.vibrato_depth; <a name="l00488"></a>00488 <a name="l00489"></a>00489 patch->scale_frequency = sample.scale_frequency; <a name="l00490"></a>00490 patch->scale_factor = sample.scale_factor; <a name="l00491"></a>00491 <a name="l00492"></a>00492 patch->volume = header.master_volume; <a name="l00493"></a>00493 <a name="l00494"></a>00494 <span class="keywordflow">if</span> (fseek (fh, offset, 0) == -1) <a name="l00495"></a>00495 { <a name="l00496"></a>00496 fclose(fh); <a name="l00497"></a>00497 <span class="keywordflow">return</span> -1; <a name="l00498"></a>00498 } <a name="l00499"></a>00499 <a name="l00500"></a>00500 <span class="keywordflow">if</span> ((<span class="keywordtype">long</span>)fread (patch->data, 1,sample.len,fh) != sample.len) <a name="l00501"></a>00501 { <a name="l00502"></a>00502 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00503"></a>00503 <span class="preprocessor"></span> printf (<span class="stringliteral">"Short file\n"</span>); <a name="l00504"></a>00504 <span class="preprocessor">#endif</span> <a name="l00505"></a>00505 <span class="preprocessor"></span> <span class="keywordflow">return</span> -1; <a name="l00506"></a>00506 } <a name="l00507"></a>00507 <a name="l00508"></a>00508 SEQ_WRPATCH (patch, <span class="keyword">sizeof</span> (*patch) + sample.len); <a name="l00509"></a>00509 <a name="l00510"></a>00510 offset = offset + sample.len; <a name="l00511"></a>00511 <a name="l00512"></a>00512 } <a name="l00513"></a>00513 patchloaded[pgm]=1; <a name="l00514"></a>00514 <a name="l00515"></a>00515 fclose(fh); <a name="l00516"></a>00516 free(patch); <span class="comment">// Shouldn't this 'free' be within the 'for' loop ?</span> <a name="l00517"></a>00517 <span class="keyword">delete</span> s; <a name="l00518"></a>00518 freememory = device; <a name="l00519"></a>00519 ioctl(seqfd, SNDCTL_SYNTH_MEMAVL, &freememory); <a name="l00520"></a>00520 <span class="preprocessor">#endif</span> <a name="l00521"></a>00521 <span class="preprocessor"></span> <span class="keywordflow">return</span> 0; <a name="l00522"></a>00522 } <a name="l00523"></a>00523 <a name="l00524"></a>00524 <a name="l00525"></a><a class="code" href="classGUSOut.html#abab52f7f2cab4643479b1ff3953755ee">00525</a> <span class="keywordtype">void</span> <a class="code" href="classGUSOut.html#abab52f7f2cab4643479b1ff3953755ee" title="See DeviceManager::setPatchesToUse() .">GUSOut::setPatchesToUse</a>(<span class="keywordtype">int</span> *patchesused) <a name="l00526"></a>00526 { <a name="l00527"></a>00527 <span class="preprocessor">#ifdef HAVE_OSS_SUPPORT</span> <a name="l00528"></a>00528 <span class="preprocessor"></span> <span class="keywordtype">int</span> k; <a name="l00529"></a>00529 <span class="keywordflow">for</span> (k=0;k<256;k++) patchloaded[k]=0; <a name="l00530"></a>00530 <a name="l00531"></a>00531 <span class="keywordtype">int</span> patchesordered[256]; <span class="comment">//This holds the pgm used ordered by a method which</span> <a name="l00532"></a>00532 <span class="comment">// put first the patches more oftenly used, and then the least</span> <a name="l00533"></a>00533 <span class="comment">// In example, if a song only uses a piano and a splash cymbal,</span> <a name="l00534"></a>00534 <span class="comment">// This is set to : 0,188,-1,-1,-1,-1 ...</span> <a name="l00535"></a>00535 patchesLoadingOrder(patchesused,patchesordered); <a name="l00536"></a>00536 <a name="l00537"></a>00537 <span class="comment">// If above line doesn't work, perhaps you could try this ? :</span> <a name="l00538"></a>00538 <span class="comment">// for (int j=0;j<256;j++) patchesordered[j]=patchesused[j];</span> <a name="l00539"></a>00539 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00540"></a>00540 <span class="preprocessor"></span> printf(<span class="stringliteral">"Patches used : \n"</span>); <a name="l00541"></a>00541 <span class="keywordflow">for</span> (k=0;k<256;k++) <a name="l00542"></a>00542 { <a name="l00543"></a>00543 <span class="keywordflow">if</span> (patchesused[k]!=-1) printf(<span class="stringliteral">"%d,"</span>,patchesused[k]); <a name="l00544"></a>00544 } <a name="l00545"></a>00545 printf(<span class="stringliteral">"\n Patches used, sorted :\n"</span>); <a name="l00546"></a>00546 <span class="keywordflow">for</span> (k=0;k<256;k++) <a name="l00547"></a>00547 { <a name="l00548"></a>00548 <span class="keywordflow">if</span> (patchesordered[k]!=-1) printf(<span class="stringliteral">"%d,"</span>,patchesordered[k]); <a name="l00549"></a>00549 } <a name="l00550"></a>00550 <span class="preprocessor">#endif</span> <a name="l00551"></a>00551 <span class="preprocessor"></span> <a name="l00552"></a>00552 <span class="keywordtype">int</span> i=0; <a name="l00553"></a>00553 <span class="keywordflow">while</span> (patchesordered[i]!=-1) <a name="l00554"></a>00554 { <a name="l00555"></a>00555 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00556"></a>00556 <span class="preprocessor"></span> printf(<span class="stringliteral">"Load Patch : %d\n"</span>,patchesordered[i]); <a name="l00557"></a>00557 <span class="preprocessor">#endif</span> <a name="l00558"></a>00558 <span class="preprocessor"></span> <a class="code" href="classGUSOut.html#a791b7cd77daa1f4bfac78a2e922e87e5" title="Loads a single patch on the synthesizer memory.">loadPatch</a>(patchesordered[i]); <a name="l00559"></a>00559 i++; <a name="l00560"></a>00560 } <a name="l00561"></a>00561 <span class="preprocessor">#endif</span> <a name="l00562"></a>00562 <span class="preprocessor"></span>} <a name="l00563"></a>00563 <a name="l00564"></a>00564 <span class="keywordtype">int</span> compare_decreasing(<span class="keyword">const</span> <span class="keywordtype">void</span> *a,<span class="keyword">const</span> <span class="keywordtype">void</span> *b) <a name="l00565"></a>00565 { <a name="l00566"></a>00566 <span class="keyword">struct </span>instr_gm <a name="l00567"></a>00567 { <a name="l00568"></a>00568 <span class="keywordtype">int</span> used; <a name="l00569"></a>00569 <span class="keywordtype">int</span> pgm; <a name="l00570"></a>00570 }; <a name="l00571"></a>00571 instr_gm *ai=(instr_gm *)a; <a name="l00572"></a>00572 instr_gm *bi=(instr_gm *)b; <a name="l00573"></a>00573 <span class="keywordflow">return</span> ai->used<bi->used; <a name="l00574"></a>00574 } <a name="l00575"></a>00575 <a name="l00576"></a>00576 <a name="l00577"></a>00577 <span class="keywordtype">void</span> GUSOut::patchesLoadingOrder(<span class="keywordtype">int</span> *patchesused,<span class="keywordtype">int</span> *patchesordered) <a name="l00578"></a>00578 { <a name="l00579"></a>00579 <span class="keyword">struct </span>instr_gm <a name="l00580"></a>00580 { <a name="l00581"></a>00581 <span class="keywordtype">int</span> used; <a name="l00582"></a>00582 <span class="keywordtype">int</span> pgm; <a name="l00583"></a>00583 }; <a name="l00584"></a>00584 <a name="l00585"></a>00585 instr_gm tempmelody[128]; <a name="l00586"></a>00586 instr_gm tempdrums[128]; <a name="l00587"></a>00587 <span class="keywordtype">int</span> i,j; <a name="l00588"></a>00588 <span class="keywordflow">for</span> (i=0,j=128;i<128;i++,j++) <a name="l00589"></a>00589 { <a name="l00590"></a>00590 tempmelody[i].used=patchesused[i]; <a name="l00591"></a>00591 tempmelody[i].pgm=i; <a name="l00592"></a>00592 tempdrums[i].used=patchesused[j]; <a name="l00593"></a>00593 tempdrums[i].pgm=j; <a name="l00594"></a>00594 } <a name="l00595"></a>00595 <span class="comment">/* SORT */</span> <span class="comment">// Decreasing order (first most used patch, then less used patch)</span> <a name="l00596"></a>00596 qsort(&tempmelody[0],128,<span class="keyword">sizeof</span>(instr_gm),compare_decreasing); <a name="l00597"></a>00597 qsort(&tempdrums[0],128,<span class="keyword">sizeof</span>(instr_gm),compare_decreasing); <a name="l00598"></a>00598 <a name="l00599"></a>00599 <span class="comment">/* Once they are sorted, the result is put on patchesordered in the following</span> <a name="l00600"></a>00600 <span class="comment"> * way : If tempmelody is : M0 M1 M2 M3 ... M127 and tempdrums is :</span> <a name="l00601"></a>00601 <span class="comment"> * D0 D1 D2 D3 ... D127, the result is :</span> <a name="l00602"></a>00602 <span class="comment"> * M0 D0 M1 M2 D1 M3 M4 D2 M5 M6 D3 ...</span> <a name="l00603"></a>00603 <span class="comment"> * P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 ...</span> <a name="l00604"></a>00604 <span class="comment"> */</span> <a name="l00605"></a>00605 <a name="l00606"></a>00606 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00607"></a>00607 <span class="preprocessor"></span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k=0;k<128;k++) <a name="l00608"></a>00608 { <a name="l00609"></a>00609 printf(<span class="stringliteral">"%d - %d\n"</span>,tempmelody[k].used,tempmelody[k].pgm); <a name="l00610"></a>00610 } <a name="l00611"></a>00611 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k=0;k<128;k++) <a name="l00612"></a>00612 { <a name="l00613"></a>00613 printf(<span class="stringliteral">"%d : %d\n"</span>,tempdrums[k].used,tempdrums[k].pgm); <a name="l00614"></a>00614 } <a name="l00615"></a>00615 <span class="preprocessor">#endif</span> <a name="l00616"></a>00616 <span class="preprocessor"></span> <a name="l00617"></a>00617 i=0; <a name="l00618"></a>00618 <span class="keywordtype">int</span> totalmelody=0; <a name="l00619"></a>00619 <span class="keywordflow">while</span> ((i<128)&&(tempmelody[i].used!=0)) <a name="l00620"></a>00620 { <a name="l00621"></a>00621 totalmelody++; <a name="l00622"></a>00622 i++; <a name="l00623"></a>00623 } <a name="l00624"></a>00624 i=0; <a name="l00625"></a>00625 <span class="keywordtype">int</span> totaldrums=0; <a name="l00626"></a>00626 <span class="keywordflow">while</span> ((i<128)&&(tempdrums[i].used!=0)) <a name="l00627"></a>00627 { <a name="l00628"></a>00628 totaldrums++; <a name="l00629"></a>00629 i++; <a name="l00630"></a>00630 } <a name="l00631"></a>00631 <span class="preprocessor">#ifdef GUSOUTDEBUG</span> <a name="l00632"></a>00632 <span class="preprocessor"></span> printf(<span class="stringliteral">"Totalmelody : %d,totaldrums : %d\n"</span>,totalmelody,totaldrums); <a name="l00633"></a>00633 <span class="preprocessor">#endif</span> <a name="l00634"></a>00634 <span class="preprocessor"></span> <span class="keywordtype">int</span> tgt=0; <a name="l00635"></a>00635 <a name="l00636"></a>00636 <span class="keywordtype">int</span> tm=totalmelody; <a name="l00637"></a>00637 <span class="keywordtype">int</span> td=totaldrums; <a name="l00638"></a>00638 <span class="keywordtype">int</span> cm,cd; <a name="l00639"></a>00639 cm=cd=0; <a name="l00640"></a>00640 <span class="keywordflow">if</span> ((tm!=0)&&(td!=0)) <a name="l00641"></a>00641 { <a name="l00642"></a>00642 patchesordered[0]=tempmelody[0].pgm; <a name="l00643"></a>00643 patchesordered[1]=tempdrums[0].pgm; <a name="l00644"></a>00644 tm--;td--; <a name="l00645"></a>00645 cm++;cd++; <a name="l00646"></a>00646 tgt+=2; <a name="l00647"></a>00647 <span class="keywordflow">while</span> ((tm>0)&&(td>0)) <a name="l00648"></a>00648 { <a name="l00649"></a>00649 <span class="keywordflow">if</span> (((tgt-1)%3)==0) <a name="l00650"></a>00650 { <a name="l00651"></a>00651 patchesordered[tgt]=tempdrums[cd].pgm; <a name="l00652"></a>00652 cd++; <a name="l00653"></a>00653 td--; <a name="l00654"></a>00654 } <a name="l00655"></a>00655 <span class="keywordflow">else</span> <a name="l00656"></a>00656 { <a name="l00657"></a>00657 patchesordered[tgt]=tempmelody[cm].pgm; <a name="l00658"></a>00658 cm++; <a name="l00659"></a>00659 tm--; <a name="l00660"></a>00660 } <a name="l00661"></a>00661 tgt++; <a name="l00662"></a>00662 } <a name="l00663"></a>00663 } <a name="l00664"></a>00664 <span class="keywordflow">while</span> (tm>0) <a name="l00665"></a>00665 { <a name="l00666"></a>00666 patchesordered[tgt]=tempmelody[cm].pgm; <a name="l00667"></a>00667 tgt++; <a name="l00668"></a>00668 cm++; <a name="l00669"></a>00669 tm--; <a name="l00670"></a>00670 } <a name="l00671"></a>00671 <span class="keywordflow">while</span> (td>0) <a name="l00672"></a>00672 { <a name="l00673"></a>00673 patchesordered[tgt]=tempdrums[cd].pgm; <a name="l00674"></a>00674 tgt++; <a name="l00675"></a>00675 cd++; <a name="l00676"></a>00676 td--; <a name="l00677"></a>00677 } <a name="l00678"></a>00678 <a name="l00679"></a>00679 <span class="comment">// Now we put as not used (-1) the rest of the array</span> <a name="l00680"></a>00680 <span class="keywordflow">while</span> (tgt<256) <a name="l00681"></a>00681 { <a name="l00682"></a>00682 patchesordered[tgt]=-1; <a name="l00683"></a>00683 tgt++; <a name="l00684"></a>00684 } <a name="l00685"></a>00685 } <a name="l00686"></a>00686 <a name="l00687"></a>00687 <span class="comment">//char *GUSOut::GUS_patches_directory="/mnt/dosc/gravis/patches";</span> <a name="l00688"></a>00688 <span class="keyword">const</span> <span class="keywordtype">char</span> *GUSOut::GUS_patches_directory=<span class="stringliteral">"/usr/share/ultrasnd"</span>; <a name="l00689"></a>00689 <a name="l00690"></a>00690 <span class="keywordtype">int</span> GUSOut::delete_GUS_patches_directory = 0; <a name="l00691"></a>00691 <span class="comment">/* No, this doesn't delete any file :-) it's just for internal use */</span> </pre></div></div> </div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>libkmid</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classAlsaOut.html">alsaout</option>, <option value="classDeviceManager.html">devicemanager</option>, <option value="classFMOut.html">fmout</option>, <option value="classGUSOut.html">gusout</option>, <option value="classMidiMapper.html">midimapper</option>, <option value="classMidiOut.html">midiout</option>, <option value="classMidiPlayer.html">midiplayer</option>, <option value="classMidiStatus.html">midistatus</option>, <option value="classMidiTrack.html">miditrack</option>, <option value="classNoteArray.html">notearray</option>, <option value="classSynthOut.html">synthout</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../arts/html/index.html">arts</a></li><li><a href="../../dcop/html/index.html">dcop</a></li><li><a href="../../dnssd/html/index.html">dnssd</a></li><li><a href="../../interfaces/html/index.html">interfaces</a></li><li> <a href="../../interfaces/kimproxy/interface/html/index.html">interface</a></li><li> <a href="../../interfaces/kimproxy/library/html/index.html">library</a></li><li> <a href="../../interfaces/kspeech/html/index.html">kspeech</a></li><li> <a href="../../interfaces/ktexteditor/html/index.html">ktexteditor</a></li><li><a href="../../kabc/html/index.html">kabc</a></li><li><a href="../../kate/html/index.html">kate</a></li><li><a href="../../kcmshell/html/index.html">kcmshell</a></li><li><a href="../../kdecore/html/index.html">kdecore</a></li><li><a href="../../kded/html/index.html">kded</a></li><li><a href="../../kdefx/html/index.html">kdefx</a></li><li><a href="../../kdeprint/html/index.html">kdeprint</a></li><li><a href="../../kdesu/html/index.html">kdesu</a></li><li><a href="../../kdeui/html/index.html">kdeui</a></li><li><a href="../../kdoctools/html/index.html">kdoctools</a></li><li><a href="../../khtml/html/index.html">khtml</a></li><li><a href="../../kimgio/html/index.html">kimgio</a></li><li><a href="../../kinit/html/index.html">kinit</a></li><li><a href="../../kio/html/index.html">kio</a></li><li> <a href="../../kio/bookmarks/html/index.html">bookmarks</a></li><li> <a href="../../kio/httpfilter/html/index.html">httpfilter</a></li><li> <a href="../../kio/kfile/html/index.html">kfile</a></li><li> <a href="../../kio/kio/html/index.html">kio</a></li><li> <a href="../../kio/kioexec/html/index.html">kioexec</a></li><li> <a href="../../kio/kpasswdserver/html/index.html">kpasswdserver</a></li><li> <a href="../../kio/kssl/html/index.html">kssl</a></li><li><a href="../../kioslave/html/index.html">kioslave</a></li><li> <a href="../../kioslave/http/html/index.html">http</a></li><li><a href="../../kjs/html/index.html">kjs</a></li><li><a href="../../kmdi/html/index.html">kmdi</a></li><li> <a href="../../kmdi/kmdi/html/index.html">kmdi</a></li><li><a href="../../knewstuff/html/index.html">knewstuff</a></li><li><a href="../../kparts/html/index.html">kparts</a></li><li><a href="../../kresources/html/index.html">kresources</a></li><li><a href="../../kspell2/html/index.html">kspell2</a></li><li><a href="../../kunittest/html/index.html">kunittest</a></li><li><a href="../../kutils/html/index.html">kutils</a></li><li><a href="../../kwallet/html/index.html">kwallet</a></li><li><a href="../../libkmid/html/index.html">libkmid</a></li><li><a href="../../libkscreensaver/html/index.html">libkscreensaver</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>