%\documentclass[trans]{beamer}
\documentclass{beamer}
%\usecolortheme{seagull}
%usetheme{Frankfurt}
\usetheme{Singapore}
\setbeamercovered{transparent} 
%usepackage[generate,ps2eps]{abc}
\usepackage[latin1]{inputenc}
%\usepackage{myisolatin1}
\usepackage{graphicx}
%\usepackage{jnoxy}
\usepackage{attachfile}

%include polycode.fmt 

\def\displayPin#1{~~~~ #1}
\def\comp{\mathbin{\cdot}}

\newenvironment{slide}[1]{\begin{frame}\frametitle{#1}}{\end{frame}}
%----------------------------------------------------------------------------
\def\traco{\noindent\mbox{}\hrulefill\mbox{} \\*}
\newcounter{exercise}
\def\theexercise{\arabic{exercise}}
%
\newenvironment{exercise}%
{\refstepcounter{exercise}
	\traco\small\noindent {\bf Exercise~\theexercise:}
\addcontentsline{loe}{subsection}{\numberline{}{{\rm \hskip-6em Exercise \arabic{exercise}}}}}%
{~\\$\Box$
}
%----------------------------------------------------------------------------

\title{
	 Computing for Musicology (0809.F104N5)
\\
	1. Introduction to the Course
}
\author{J.N.\ Oliveira}
\institute{Dept.\ Inform{\'a}tica, \\Universidade do Minho\\Braga, Portugal}
\date{
\begin{tabular}{c}
Feb.\ 2009
\\
	Licenciatura em M{\'u}sica
\\
	Universidade do Minho 
\\
	Braga
%
\end{tabular}
}

\begin{document}

\frame[plain]{\titlepage}

\section{Introduction}

\begin{slide}{About this course}
Quoted from my machine's native dictionary:

\begin{description}
\item[Musicology]
(noun)
the study of music as an academic subject, as distinct from training in performance or composition; scholarly research into music.	
\item[Computing]
(noun)
the use or operation of computers : \emph{developments in mathematics and computing}
\end{description}

In this course you will learn how to program computers to help you in musical analysis.
\end{slide}

\begin{slide}{About this course}
What this course is \textbf{not} about:

\begin{itemize}
\item	music electronics
\item	computer music
\item	music typesetting
\end{itemize}

\end{slide}

\begin{slide}{The 3M rule}
Music used to be part of the \emph{Quadrivium}, a
medieval university curriculum involving the ``mathematical arts'' of
\begin{itemize}
\item	
arithmetic
\item
geometry
\item
astronomy
\item
music
\end{itemize}
	
The ``3M rule'' : people who like
\textbf Music also like
\textbf Maths and
\textbf Maps.

\vskip 2em
Why is this?

\vskip 2em
All three M's above have to do with \textbf{abstraction}.
In fact, \textbf{music} is perhaps the most abstract of all arts:
what does a piece of music (with no words) actually mean?
Hard to say.
\end{slide}

\begin{slide}{Music is about sound}
Music is one of the pilars of culture: every community, civilization etc has its own.

\vskip 2em

When/how did it start?
\begin{itemize}
\item	
One can imagine hominids marvelling at drumming and producing ``arbitrary'' sounds.
\item
Temptation to master the amazing world of sound must have taken place later;
it implied \textbf{selection} and \textbf{abstraction} skills.
\item
Abstraction led to \textbf{music notation}; thus the \textbf{history} of music was born.
\end{itemize}
\end{slide}

\begin{slide}{Glossary in one slide}
\begin{quote}
\begin{enumerate}
\item[Sound] vibrations that travel through the air or another medium and can be heard when they reach the ear.
\item[Period] the interval of time ($T$) between successive occurrences of the same state in an oscillatory or cyclic phenomenon.
\item[Frequency] the rate of vibrations producing sound ($f = 1/T$).
\item[Pitch] the quality of a sound governed by the rate of vibrations producing it
\item[Amplitude] the maximum extent of a vibration or oscillation, measured from the position of rest.
\item[Rhythm] the systematic arrangement of musical sounds, principally according to duration and periodic stress.
\end{enumerate}
\end{quote}
\end{slide}

\section{Proportions and rational numbers}

\begin{slide}{Mastering time}
Time division as rythmic perception of \emph{rational numbers} (vulg.\ fractions),
\begin{center}
\begin{_abc}[mp3,width=0.7\textwidth]
X: 1 
L: 1/1 
K: C 
C1|D/2D/2|
w: ~1 ~1/2 ~1/2
E/4E/4E/4E/4|
w: ~1/4 ~1/4 ~1/4 ~1/4
F/8F/8F/8F/8F/8F/8F/8F/8|
w: ~1/8 ~1/8 ~1/8 ~1/8 ~1/8 ~1/8 ~1/8 ~1/8
\end{_abc}
\end{center}
and so on and so forth:
\begin{center}
\begin{_abc}[mp3,width=0.7\textwidth]
X: 1 
L: 1/1 
K: C 
G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16G/16|
w: ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16 ~1/16
A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32A/32|
w: ~1/32 ~1/32 ~...
B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64B/64|
w: ~1/64 ~1/64 ~...
\end{_abc}
\end{center}
\end{slide}

\begin{slide}{Mastering time}
The other way round:
	\raisebox{-2.5ex}{
	\_abc[width=6cm]{
	X: 1 
	L: 1/1 
	K: C 
	C1|D2|E4
	w: ~1 ~2 ~4
}},
etc

\vskip 1em

Recall:
\begin{description}
\item[Natural numbers]	--- $1$, $2$, $3$, $4$, ....
\item[Rational numbers]	--- $1/2$, $2/3$, $1/3$, ..., $n/m$, ...  where $n$ and $m$ are natural numbers
\item[Rational number arithmetics] ---
eg.\ $\frac 1 2 + \frac 1 4 + \frac 1 8 = \frac 7 8$, cf.
\begin{center}
	\raisebox{-1ex}{
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	D1/2-D1/4-D1/8|
	}
	}
=
	\raisebox{-1ex}{
	\_abc[width=3cm]{
	X: 1
	K: C
	L: 1/1
	D1/8-D1/8-D1/8-D1/8-D1/8-D1/8-D1/8-D1/8
	}
	}
=
	\raisebox{-1ex}{
	\_abc[width=1.5cm]{
	X: 1
	K: C
	L: 1/2
	D>>
	}
	}
\end{center}
\end{description}
Therefore:
\begin{quote}
Need for a computer language able to calculate with \emph{rational numbers}
\end{quote}
We shall use the \textbf{Haskell} language for this.
\end{slide}

\begin{slide}{First exercise in Haskell}
The following exercise shows how GHC (the ``Glasgow Haskell Calculator'') helps in calculating with rational numbers.

\begin{exercise}
Run \texttt{ghci Ipm}, where \texttt{Ipm} stands for
\emph{Informática para a Musicologia}:
\begin{quote}
ghci Ipm
\end{quote}
Then type |1%2+1%4+1%8| (this is the way rational numbers are written in the language).
You should obtain |7%8| as result.

Perform other calculations such as
|2%3+3%2|, |4*(3%2)| etc.

You can also calculate inverses. Try eg. |1/(3%2) = 2%3|, etc.
\end{exercise}

\end{slide}

\begin{slide}{Mastering pitch}
\begin{center}
	\includegraphics[width=0.8\textwidth]{sinewaves.jpg}
\end{center}
\end{slide}

\begin{slide}{Mastering pitch}
\begin{itemize}
\item	
Pythagoras instrument
\item	
Overtones
\end{itemize}
\end{slide}

\begin{slide}{The sextine}
16c theoreticians explained tunings in terms of the \textbf{sextine}, as follows:
\begin{center}
\begin{_abc}[mp3,width=0.7\textwidth]
X:3 
M: C
T:
C:
L: 1/1
K:C
V:RH clef=treble staves=2 brace=2
V:LH clef=bass
%%staves [RH LH]
[V:RH]  x   x  D G B d | [DGBd]  |
w: ~3 ~4 ~5 ~6
[V:LH]  G,, G, x x x x | [G,,G,] |
w: ~1 ~2 
\end{_abc}
\end{center}
leading to interval taxonomy as follows:
\begin{center}
\begin{tabular}{ccc}\\\hline
Interval & Ascending & Descending
\\
	octave & $\frac 1 2$ & $\frac 2 1$
\\
	fifth & $\frac 2 3$ & $\frac 3 2$
\\
	fourth & $\frac 3 4$ & $\frac 4 3$
\\
	major third & $\frac 4 5$ & $\frac 5 4$
\\
	minor third & $\frac 5 6$ & $\frac 6 5$
\end{tabular}
\end{center}
\end{slide}

\begin{slide}{}
\begin{center}
\includegraphics[width=0.4\textwidth]{inca.jpg}\displayPin{\attachfile[color=1 1 1]{3229269995132-01_05.mp3}}
\end{center}
\end{slide}

\begin{slide}{Diatonismo}
\small
Logo
\begin{eqnarray*}
	\rarrow{Nota}{intervalo}{Nota}
\end{eqnarray*}
por exemplo, $8asc(f) = 2f$, $3Mdesc(f) = \frac 4 5 f$, etc
\end{slide}

\begin{slide}{Composição de intervalos}
Dados dois intervalos $i$ e $j$, a sua composição corresponde à sua multiplicação,
\begin{eqnarray*}
	(i· j)(f) = i(j(f))
\end{eqnarray*}
por exemplo
\begin{eqnarray*}
	2Masc &=& 4desc· 5asc
\end{eqnarray*}
isto é
\begin{eqnarray*}
2Masc(f) = (\frac 3 4× \frac 3 2)(f) = \frac 9 8 f
\end{eqnarray*}
Exemplo:
\begin{center}
\begin{_abc}[mp3,width=0.7\textwidth]
X:3 
M: C
T:
C:
L: 1/1
K:C
G "@-40,-20 3/4"D "@-40,-20 3/2"A | G "@-40,-20 9/8"A |
\end{_abc}
\end{center}
\end{slide}

\begin{slide}{Pentatonic scale}
Usando apenas quintas e oitavas:

\begin{_abc}[mp3,width=0.7\textwidth]
X:4 
M: C
L: 1/1
K:C
%%staves [RH]
V:RH clef=treble
[V:RH]  GdAeB
\end{_abc}

isto \'e, ordenando:

\begin{_abc}[mp3,width=0.7\textwidth]
X:5 
M: C
L: 1/1
K:C
%%staves [RH]
V:RH clef=treble
[V:RH]  GABde
\end{_abc}

De facto,
$\frac 3 4 \times \frac 3 2 = \frac 9 8$, isto \'e,
$+V ; -IV = II$

Contudo, uma teceira maior n\~ao \'e \emph{exactamente} uma terceira maior:
$\frac 9 8 \times \frac 9 8 = \frac{81}{64}$, devendo ser
$\frac{80}{64}=\frac 5 4$... 
O erro \'e de $\frac 1 64$,

x=81/64	II ; II
x=5/4	sextina
$x=(2^(1/12))^4 = 2^(1/3)$	temperada

\end{slide}

\begin{slide}{Carnaval serrano}
\begin{center}
\begin{_abc}[mp3,width=0.8\textwidth]
X:3
M: 2/2
T: Carnaval serrano
T: (Bolívia e Peru)
L: 1/1
K:C
V:P1 clef=treble
V:P2 clef=alto
%%staves [P1 P2]
[V:P1]
B3/8A1/8|G1/2G1/4A1/4|B1/4B1/4B1/4A1/4|G1/2G1/4A1/4|B1/4B1/8d1/8B1/4A1/4|G1/2G1/4A1/4|G1/4G1/4A1/4G1/4|E3/4B1/4|
E3/4B1/4|E1/2B3/8A1/8|G1/2G1/4A1/4|B1/4B1/4B1/4A1/4|G1/2G1/4A1/4|B1/4B1/8d1/8B1/4A1/4|G1/2G1/4A1/4|G1/4G1/4A1/4G1/4|E3/4B1/4|E3/4B1/4E1/2
[V:P2]
E3/8D1/8C1/2C1/4D1/4E1/4E1/4E1/4D1/4C1/2C1/4D1/4E1/4E1/8G1/8E1/4D1/4C1/2C1/4D1/4C1/4C1/4D1/4C1/4A,3/4E1/4A,3/4E1/4A,1/2E3/8D1/8C1/2C1/4D1/4E1/4E1/4E1/4D1/4C1/2C1/4D1/4E1/4E1/8G1/8E1/4D1/4C1/2C1/4D1/4C1/4C1/4D1/4C1/4A,3/4E1/4A,3/4E1/4A,1/2
\end{_abc}
\end{center}
nrep in action:
\begin{center}
\begin{_abc}[mp3,width=0.8\textwidth]
X:3
M: 2/2
L: 1/1
K:C
%%staves [P0]
[V:P0]
B3/8A1/8G3/4A1/4B3/4A1/4G3/4A1/4B3/8d1/8B1/4A1/4G3/4A1/4G1/2A1/4G1/4E3/4B1/4E3/4B1/4E1/2
\end{_abc}
\end{center}
rythm out
\begin{center}
\begin{_abc}[mp3,width=0.8\textwidth]
X:3
M: 2/2
L: 1/4
K:C
%%staves [P0]
[V:P0]
B0A0G0A0B0A0G0A0B0d0B0A0G0A0G0A0G0E0B0E0B0E0
\end{_abc}
\end{center}
\end{slide}

\begin{slide}{Ugarit (Syria), 3400 years ago}
Believed to be the oldest ``score'' known, in cuneiform notation:
\begin{center}
\includegraphics[width=0.7\textwidth]{kilmer.pdf}
\end{center}
\begin{center}
\begin{_abc}[mp3,width=0.7\textwidth]
X:1
K:C
L:1/8
M:C
%%staves (1 2)
[V:1]  G G A B B A A B B2 "..."
[V:2]  E E F G G F F D D2
"last line"
[V:1]  A B B A A A A B F B B2 |: G G G G G2 :|
[V:2]  F G G C C C C D C G G2 |: E E E E E2 :|
\end{_abc}
\end{center}
\small
See:
Kilmer, A.D. (1971) \emph{The Discovery of an Ancient Mesopotamian Theory of Music}.
Proceedings of the American Philosophical Society 115, 131-149.
\end{slide}

\begin{slide}{Rythmic genealogy}
\begin{eqnarray*}
\xymatrix@@C=2ex{
&
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	G1/2 G1/2|
	}
		\ar[dl]_{dot}
		\ar[dr]^{patata}
\\
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	G3/4 G1/4|
	}
&
&
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	G1/2 G1/4G1/4|
	}
		\ar[dl]_{a}
		\ar[dr]_{b}
\\
&
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	G1/4G1/4G1/4G1/4|
	}
		\ar[dl]_{}
&
&
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	z1/2 G3/8G1/8|
	}
\\
	\_abc[width=2cm]{
	X: 1
	K: C
	L: 1/1
	G1/4G1/8G1/8G1/4G1/4|
	}
}
\end{eqnarray*}

\end{slide}

\begin{slide}{Haskell - numbers}
Equations:
\begin{eqnarray}
	a*0 &= &0
\\
	a*1 &= &1
\\
	a*(b+c) &= &(a*b)+(a*c)
\end{eqnarray}
Code
\begin{code}
	a .* 0 = 0
	a .* 1 = a
	a .* (c+1) = (a .* c) + (a .* 1)
\end{code}
Simpler version --- replace |(a .* 1)| by |a| and delete second clause.
\end{slide}

\begin{slide}{Haskell -- words}
Equations:
\begin{eqnarray}
	|""++a = a|
\\
	|"a"++b = a:b|
\\
	|(a ++ b) ++ c = a ++ (b ++ c)|
\end{eqnarray}
Code
\begin{code}
	"" .++ a = a
	(a:b) .++ c = a:(b .++ c)
\end{code}
\end{slide}

\end{document}

