Skip to content

Commit

Permalink
Get and set CSD from MusicModel (#35).
Browse files Browse the repository at this point in the history
  • Loading branch information
gogins committed Jan 13, 2025
1 parent 53b1232 commit 57820ed
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CsoundAC/MusicModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ std::string MusicModel::getCsoundOrchestra() const
return cppSound->getOrchestra();
}

void MusicModel::setCsd(std::string csd)
{
cppSound->setCSD(csd);
}

std::string MusicModel::getCsd() const
{
return cppSound->getCSD();
}

void MusicModel::setCsoundScoreHeader(std::string header)
{
csoundScoreHeader = header;
Expand Down
10 changes: 10 additions & 0 deletions CsoundAC/MusicModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class SILENCE_PUBLIC MusicModel :
* Clear all contents of this.
*/
virtual void clear();
/**
* Set the Csound csd file
* (convenience wrapper for CppSound::setCSD()).
*/
virtual void setCsd(std::string csd);
/**
* Get the Csound csd file
* (convenience wrapper for CppSound::getCSD()).
*/
virtual std::string getCsd() const;
/**
* Set the Csound orchestra
* (convenience wrapper for CppSound::setOrchestra()).
Expand Down
2 changes: 1 addition & 1 deletion user-guide/csound-ac-user-guide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ \section{Running CsoundAC}

CsoundAC can be run as part of an ordinary Python program that imports CsoundAC, or embedded in Csound using the \texttt{bin} attribute, e.g. \lstinline|<CsScore bin="python3.12">|, or embedded in a DAW using its Python scripting facility.

Here, the same simple example is run in each of these environments. All three examples use the same Csound orchestra, which is defined in the Python code as a Python string literal (\lstinline|(r"some string with perhaps many lines and escape characters"|). All three examples use a simple loop to generate an ascending chromatic scale of notes. The only differences between the examples are in how they are run and how they interface with Csound.
Here, the same simple example is run in each of these environments. All three examples use the same Csound orchestra, \lstinline|simple.csd|, which is defined in the Python code as a Python string literal (\lstinline|(r"some string with perhaps many lines and escape characters"|). All three examples use a simple loop to generate an ascending chromatic scale of notes. The only differences between the examples are in how they are run and how they interface with Csound.

\subsection{Running in Python}

Expand Down
19 changes: 16 additions & 3 deletions user-guide/simple-python.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
orc = r'''
csd = r'''
<CsoundSynthesizer>
<CsLicense>
This piece tests combinations of instr definitions.
</CsLicense>
<CsOptions>
--m-amps=1 --m-range=1 --m-dB=1 --m-benchmarks=1 --m-warnings=0 -+msg_color=0 -d -odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 128
nchnls = 2
Expand Down Expand Up @@ -859,6 +868,11 @@
endif
prints "%-24s i %9.4f t %9.4f d %9.4f k %9.4f v %9.4f p %9.4f #%3d\n", nstrstr(p1), p1, p2, p3, p4, p5, p7, active(p1)
endin
</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>
'''

import CsoundAC
Expand All @@ -874,6 +888,5 @@
score_node.getScore().add(p2, p3, 144, p1, p4, p5)
print("Generated score:")
print(score_node.getScore().getCsoundScore())
music_model.setCsoundOrchestra(orc)
music_model.setCsoundCommand("-m163 --midi-key=4 --midi-velocity=5 -odac")
music_model.setCsd(csd)
music_model.render()

0 comments on commit 57820ed

Please sign in to comment.