;; -*- cscsd-current-processing : "csound to dac" -*-
<About> ===================================================================

This demo, to be used within Emacs in Surmulot, demonstrates the usage of
a CSD as a versatile interactive synthesizer for MIDI-like data.

Here the CSD has an empty score section. The score is dynamically built from
a [[info:surmulot.info:Musical%20phrase%20editor][Musical phrase editor]] widget maintaining a long musical phrase illustrating
the purvi Indian mode, built upon an observed 12-tone North-Indian scale.

Invoke one of the stored widgets via the "Widgets -> Stored widgets" submenu
... or click here:
 [[elisp:(surmulot-widget-restore "Indian mode purvi")]]
 [[elisp:(surmulot-widget-restore "Indian mode purvi with meends")]]

Now the widget button labelled "process as score" will play the musical phrase
via the CSD. Note that this does not change the current buffer, nor the initial
CSD file.


Moreover, since this CSD is a soundfont player, you can use the
"CSD -> Meta-settings -> Soundfont" menu to select the soundfont to be used.
(see [[info:Csound-x:CSD%20meta-controls][info:Csound-x:CSD meta-controls]] for details).

You do not have to save the buffer for this setting to take effect; hitting
the "process as score" button will play the curently selected soundfont.
If you like it, you can save the buffer so that it is kept as the default 
soundfont for the next session.


You can also start a new musical piece from scratch by opening a new phrase
editor. Any number of editors can be opened simulateously, and each one can
play its contents via the CSD.

You can save an editor music in three different ways:
 1) by storing the editor itself, just as the one we first restored.
 2) by storing its contents as a MPhrase area
 3) by converting its contents as a score and writing it in the CSD

1) and 2) allow any number of musical phrase to be saved, while 3) will only 
store one composition.

On the other hand, 3) will allow you to share the CSD with all csounders, 
since Surmulot is not required to play it. 1) and 2) use representations
only handled by Surmulot.

Now how to proceed:
 1) from the "Widgets" menu. See [[info:surmulot.info:Widgets]] for details.
 2) via the "emacs -> insert as <MPhrase> area" item in the editor contextual
 menu.
 3) via the "emacs -> insert as score" item in the editor contextual menu.


Any CSD can be operated in the way described in this example, provided that
Surmulot is able to map the MIDI-like data in a musical phrase into a correctly
formatted score.

This is made possible by the score format sections in the CSD: these are the
comments enclosed in /*| ... |*/

================================================================== </About>

<CsoundSynthesizer>
<CsOptions>
</CsOptions>

<CsInstruments>
sr = 44100
ksmps = 4410
nchnls = 1

	    gin  ftgen  1, 0, 128, 10, 1

instr 1
/*| 
((pitchField: 4)
 (pitchFormat: cps)
 (pitchInflexionField: 6)
 (ampField: 5)
 (ampMin:max: (0 1))
 (iTemplate: "i 1 0 0.5 440 0.5 0"))
|*/
            ;; p4   base pitch (cps)
            ;; p5   velocity
            ;; p6   pitch bend envelope over p3 (in cents)


  kpbend    =  0
if p6=0 goto noEnvelope
  kndx      line      0, p3, 1
  kpbend    table     kndx, p6, 1 
noEnvelope:

  kamp	    =  31129.60 * p5
  kfreq	    =  (kpbend > 0 ? p4*(2^(kpbend/1200)) : p4/(2^(abs(kpbend)/1200)))
  kpres	    =  3.0
  krat	    =  0.127236
  kvibf	    =  6.12723
  ifn	    =  gin

  ; Create an amplitude envelope for the vibrato.
  kv	    linseg    0, 0.02, 1, p3-0.04, 1, 0.02, 0
  kvamp	    =  kv * 0.01

  a1	    wgbow     kamp*kv, kfreq, kpres, krat, kvibf, kvamp, ifn
	    out	      a1
endin


</CsInstruments>
<CsScore>
; Table #1, a sine wave.
f 1 0 128 10 1

</CsScore>
</CsoundSynthesizer>

<WIDGET>Indian mode purvi with meends
Phrase Editor
'[encoded data, 29508 characters]'</WIDGET>

<WIDGET>Indian mode purvi
Phrase Editor
'[encoded data, 22924 characters]'</WIDGET>
