Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 2eb128636afdc4a8c8207ec3ec09861d > files > 46

fluidsynth-devel-1.1.3-1.fc14.i686.rpm

<!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">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>libfluidsynth: fluidsynth_simple.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.1 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1>fluidsynth_simple.c</h1>  </div>
</div>
<div class="contents">
<p>A basic example of using fluidsynth to play a single note</p>
<div class="fragment"><pre class="fragment"><span class="comment">/* FluidSynth Simple - An example of using fluidsynth</span>
<span class="comment"> *</span>
<span class="comment"> * This code is in the public domain.</span>
<span class="comment"> *</span>
<span class="comment"> * To compile:</span>
<span class="comment"> *   gcc -g -O -o fluidsynth_simple fluidsynth_simple.c -lfluidsynth</span>
<span class="comment"> *</span>
<span class="comment"> * To run</span>
<span class="comment"> *   fluidsynth_simple soundfont</span>
<span class="comment"> *</span>
<span class="comment"> * [Peter Hanappe]</span>
<span class="comment"> */</span>


<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="fluidsynth_8h.html" title="FluidSynth is a real-time synthesizer designed for SoundFont(R) files.">fluidsynth.h</a>&gt;</span>

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv) 
{
        <a class="code" href="types_8h.html#aa363402d3c77333b0f070ba531d034ba" title="Configuration settings instance.">fluid_settings_t</a>* settings;
        <a class="code" href="types_8h.html#ae265f10ae174a13afe010de50d87e1a4" title="Synthesizer instance.">fluid_synth_t</a>* synth = NULL;
        <a class="code" href="types_8h.html#ac3706330ce49cac5b7dd079e90d376d8" title="Audio driver instance.">fluid_audio_driver_t</a>* adriver = NULL;
        <span class="keywordtype">int</span> err = 0;

        <span class="keywordflow">if</span> (argc != 2) {
                fprintf(stderr, <span class="stringliteral">&quot;Usage: fluidsynth_simple [soundfont]\n&quot;</span>);
                <span class="keywordflow">return</span> 1;
        }

        <span class="comment">/* Create the settings object. This example uses the default</span>
<span class="comment">         * values for the settings. */</span>
        settings = <a name="a0"></a><a class="code" href="settings_8h.html#ad7ab9269a28c2b5852d512ffe3546949" title="Create a new settings object.">new_fluid_settings</a>();
        <span class="keywordflow">if</span> (settings == NULL) {
                fprintf(stderr, <span class="stringliteral">&quot;Failed to create the settings\n&quot;</span>);
                err = 2;
                <span class="keywordflow">goto</span> cleanup;
        }
  
        <span class="comment">/* Create the synthesizer */</span>
        synth = <a name="a1"></a><a class="code" href="synth_8h.html#a344f7369c0f57d30f72702d0c88e6178" title="Create new FluidSynth instance.">new_fluid_synth</a>(settings);
        <span class="keywordflow">if</span> (synth == NULL) {
                fprintf(stderr, <span class="stringliteral">&quot;Failed to create the synthesizer\n&quot;</span>);
                err = 3;
                <span class="keywordflow">goto</span> cleanup;
        }

        <span class="comment">/* Load the soundfont */</span>
        <span class="keywordflow">if</span> (<a name="a2"></a><a class="code" href="synth_8h.html#aaf9376cf7189f9c64da5ffdeed85c9c4" title="Load a SoundFont file (filename is interpreted by SoundFont loaders).">fluid_synth_sfload</a>(synth, argv[1], 1) == -1) {
                fprintf(stderr, <span class="stringliteral">&quot;Failed to load the SoundFont\n&quot;</span>);
                err = 4;
                <span class="keywordflow">goto</span> cleanup;
        }

        <span class="comment">/* Create the audio driver. As soon as the audio driver is</span>
<span class="comment">         * created, the synthesizer can be played. */</span>
        adriver = <a name="a3"></a><a class="code" href="audio_8h.html#a4ad51317b10b89bfe94ade5db345864b" title="Create a new audio driver.">new_fluid_audio_driver</a>(settings, synth);
        <span class="keywordflow">if</span> (adriver == NULL) {
                fprintf(stderr, <span class="stringliteral">&quot;Failed to create the audio driver\n&quot;</span>);
                err = 5;
                <span class="keywordflow">goto</span> cleanup;
        }

        <span class="comment">/* Play a note */</span>
        <a name="a4"></a><a class="code" href="synth_8h.html#a4a98222fe1c36bfd598dc4cd89f4b75c" title="Send a note-on event to a FluidSynth object.">fluid_synth_noteon</a>(synth, 0, 60, 100);

        printf(<span class="stringliteral">&quot;Press \&quot;Enter\&quot; to stop: &quot;</span>);
        fgetc(stdin);
        printf(<span class="stringliteral">&quot;done\n&quot;</span>);

        
 cleanup:
        
        <span class="keywordflow">if</span> (adriver) {
                <a name="a5"></a><a class="code" href="audio_8h.html#a05678e633d37da0f93000045393e9442" title="Deletes an audio driver instance.">delete_fluid_audio_driver</a>(adriver);
        }
        <span class="keywordflow">if</span> (synth) {
                <a name="a6"></a><a class="code" href="synth_8h.html#a585a63f3a25b9df17b82ae87f2d38cfc" title="Delete a FluidSynth instance.">delete_fluid_synth</a>(synth);
        }
        <span class="keywordflow">if</span> (settings) {
                <a name="a7"></a><a class="code" href="settings_8h.html#a550270f09e4f3c645cbe9e6d3c514ca4" title="Delete the provided settings object.">delete_fluid_settings</a>(settings);
        }
        
        <span class="keywordflow">return</span> err;
}
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Tue Oct 12 2010 for libfluidsynth by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>