mirror of
https://github.com/thestk/stk
synced 2026-01-20 07:51:53 +00:00
Release 4.1.1 tarball
This commit is contained in:
committed by
Stephen Sinclair
parent
b39c0bb101
commit
ffce5357c6
137
doc/html/polyvoices.html
Normal file
137
doc/html/polyvoices.html
Normal file
@@ -0,0 +1,137 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>The Synthesis ToolKit in C++ (STK)</TITLE>
|
||||
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF">
|
||||
<CENTER>
|
||||
<img src="princeton.gif"> <img src="ccrma.gif"><P>
|
||||
<a class="qindex" href="index.html">Home</a> <a class="qindex" href="information.html">Information</a> <a class="qindex" href="classes.html">Classes</a> <a class="qindex" href="download.html">Download</a> <a class="qindex" href="usage.html">Usage</a> <a class="qindex" href="maillist.html">Mail List</a> <a class="qindex" href="system.html">Requirements</a> <a class="qindex" href="links.html">Links</a> <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
|
||||
<HR>
|
||||
<!-- Generated by Doxygen 1.2.8.1 -->
|
||||
<a name="polyvoices"><h2>Voice Management</h2></a>
|
||||
The previous tutorial chapters were concerned only with monophonic ToolKit instrument playback and control. At this point, it should be relatively clear that one can instantiate multiple instruments and perhaps sum together their sounds or even direct their sounds to separate output channels. It is less clear how one might go about controlling a group of instruments. The <a class="el" href="classVoicer.html">Voicer</a> class is designed to serve just this purpose.
|
||||
<p>
|
||||
The STK <a class="el" href="classVoicer.html">Voicer</a> class is a relatively simple voice manager. The user can dynamically add and delete instruments from its "control", with the option of controlling specific instruments via unique note tags and/or grouping sets of instruments via a "channel" number. All sounding instrument outputs are summed and returned via the <code>tick()</code> function. The <a class="el" href="classVoicer.html">Voicer</a> class responds to noteOn, noteOff, setFrequency, pitchBend, and controlChange messages, automatically assigning incoming messages to the voices in its control. When all voices are sounding and a new noteOn is encountered, the <a class="el" href="classVoicer.html">Voicer</a> interrupts the oldest sounding voice. The user is responsible for creating and deleting all instrument instances.
|
||||
<p>
|
||||
In the following example, we modify the <code>controlbee.cpp</code> program to make use of three <a class="el" href="classBeeThree.html">BeeThree</a> instruments, all controlled using a <a class="el" href="classVoicer.html">Voicer</a>.
|
||||
<p>
|
||||
<div class="fragment"><pre><font class="comment">// threebees.cpp</font>
|
||||
|
||||
<font class="preprocessor">#include "BeeThree.h"</font>
|
||||
<font class="preprocessor">#include "RtWvOut.h"</font>
|
||||
<font class="preprocessor">#include "Messager.h"</font>
|
||||
<font class="preprocessor">#include "Voicer.h"</font>
|
||||
<font class="preprocessor">#include "SKINI.msg"</font>
|
||||
|
||||
<font class="keywordtype">int</font> main()<font class="keyword"></font>
|
||||
<font class="keyword"></font>{
|
||||
<font class="comment">// Set the global sample rate before creating class instances.</font>
|
||||
<a class="code" href="classStk.html#d1">Stk::setSampleRate</a>( 44100.0 );
|
||||
|
||||
<font class="keywordtype">int</font> i;
|
||||
<a class="code" href="classRtWvOut.html">RtWvOut</a> *output = 0;
|
||||
<a class="code" href="classMessager.html">Messager</a> *messager = 0;
|
||||
<a class="code" href="classVoicer.html">Voicer</a> *voicer = 0;
|
||||
<font class="keywordtype">bool</font> done = FALSE;
|
||||
<a class="code" href="classInstrmnt.html">Instrmnt</a> *instrument[3];
|
||||
<font class="keywordflow">for</font> ( i=0; i<3; i++ ) instrument[i] = 0;
|
||||
|
||||
<font class="keywordflow">try</font> {
|
||||
<font class="comment">// Define and load the BeeThree instruments</font>
|
||||
<font class="keywordflow">for</font> ( i=0; i<3; i++ )
|
||||
instrument[i] = <font class="keyword">new</font> BeeThree();
|
||||
|
||||
<font class="comment">// Define and open the default realtime output device for one-channel playback</font>
|
||||
output = <font class="keyword">new</font> RtWvOut(1);
|
||||
}
|
||||
<font class="keywordflow">catch</font> (<a class="code" href="classStkError.html">StkError</a> &) {
|
||||
<font class="keywordflow">goto</font> cleanup;
|
||||
}
|
||||
|
||||
<font class="keywordflow">try</font> {
|
||||
<font class="comment">// Create a Messager instance to read from a redirected SKINI scorefile.</font>
|
||||
messager = <font class="keyword">new</font> Messager();
|
||||
}
|
||||
<font class="keywordflow">catch</font> (<a class="code" href="classStkError.html">StkError</a> &) {
|
||||
<font class="keywordflow">goto</font> cleanup;
|
||||
}
|
||||
|
||||
<font class="comment">// Instantiate the voicer for a maximum of three voices.</font>
|
||||
voicer = <font class="keyword">new</font> Voicer( 3 );
|
||||
<font class="keywordflow">for</font> ( i=0; i<3; i++ )
|
||||
voicer-><a class="code" href="classVoicer.html#a2">addInstrument</a>( instrument[i] );
|
||||
|
||||
<font class="comment">// Play the instrument until the end of the scorefile.</font>
|
||||
<font class="keywordtype">int</font> nTicks, type;
|
||||
MY_FLOAT byte2, byte3;
|
||||
<font class="keywordflow">while</font> (!done) {
|
||||
|
||||
<font class="comment">// Look for new messages and return a delta time (in samples).</font>
|
||||
type = messager-><a class="code" href="classMessager.html#a2">nextMessage</a>();
|
||||
<font class="keywordflow">if</font> (type < 0)
|
||||
done = TRUE;
|
||||
|
||||
nTicks = messager-><a class="code" href="classMessager.html#a4">getDelta</a>();
|
||||
<font class="keywordflow">try</font> {
|
||||
<font class="keywordflow">for</font> ( i=0; i<nTicks; i++ )
|
||||
output-><a class="code" href="classRtWvOut.html#a6">tick</a>( voicer-><a class="code" href="classVoicer.html#a14">tick</a>() );
|
||||
}
|
||||
<font class="keywordflow">catch</font> (<a class="code" href="classStkError.html">StkError</a> &) {
|
||||
<font class="keywordflow">goto</font> cleanup;
|
||||
}
|
||||
|
||||
<font class="keywordflow">if</font> ( type > 0 ) {
|
||||
<font class="comment">// Process the new control message.</font>
|
||||
byte2 = messager-><a class="code" href="classMessager.html#a6">getByteTwo</a>();
|
||||
byte3 = messager-><a class="code" href="classMessager.html#a7">getByteThree</a>();
|
||||
|
||||
<font class="keywordflow">switch</font>(type) {
|
||||
|
||||
<font class="keywordflow">case</font> __SK_NoteOn_:
|
||||
voicer-><a class="code" href="classVoicer.html#a4">noteOn</a>( byte2, byte3 );
|
||||
<font class="keywordflow">break</font>;
|
||||
|
||||
<font class="keywordflow">case</font> __SK_NoteOff_:
|
||||
voicer-><a class="code" href="classVoicer.html#a5">noteOff</a>( byte2, byte3 );
|
||||
<font class="keywordflow">break</font>;
|
||||
|
||||
<font class="keywordflow">case</font> __SK_ControlChange_:
|
||||
voicer-><a class="code" href="classVoicer.html#a11">controlChange</a>( (<font class="keywordtype">int</font>) byte2, byte3 );
|
||||
<font class="keywordflow">break</font>;
|
||||
|
||||
<font class="keywordflow">case</font> __SK_AfterTouch_:
|
||||
voicer-><a class="code" href="classVoicer.html#a11">controlChange</a>( 128, byte2 );
|
||||
<font class="keywordflow">break</font>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
<font class="keywordflow">for</font> ( i=0; i<3; i++ ) <font class="keyword">delete</font> instrument[i];
|
||||
<font class="keyword">delete</font> output;
|
||||
<font class="keyword">delete</font> messager;
|
||||
<font class="keyword">delete</font> voicer;
|
||||
|
||||
<font class="keywordflow">return</font> 0;
|
||||
}</pre></div>
|
||||
<p>
|
||||
Assuming the program is compiled as <code>threebees</code>, the three-voice <a class="el" href="classSKINI.html">SKINI</a> scorefile <a href="tutorial/bachfugue.ski"><code>bachfugue.ski</code></a> could be redirected to the program as:
|
||||
<p>
|
||||
<div class="fragment"><pre>threebees < bachfugue.ski</pre></div>
|
||||
<p>
|
||||
For more fun, surf to <a href="http://kern.humdrum.net/">Kern Scores</a> for a huge assortment of other scorefiles which can be downloaded in the <a class="el" href="classSKINI.html">SKINI</a> format.
|
||||
<p>
|
||||
Another easy extension would be to use the <code>STK_MIDI</code> constructor argument to the <a class="el" href="classMessager.html">Messager</a> class and then play the instruments via a MIDI keyboard.
|
||||
<p>
|
||||
[<a href="tutorial.html">Main tutorial page</a>]
|
||||
<p>
|
||||
<HR>
|
||||
|
||||
<table>
|
||||
<tr><td><A HREF="http://www-ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
|
||||
<tr><td>©1995-2002 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
||||
</table>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user