\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{audiocd}[2006/03/25 0.2]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass[a4paper,12pt]{article}
\RequirePackage[latin1]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{lmodern}
\RequirePackage[dvips,nohead,nofoot,left=0cm,right=0cm,top=2cm]{geometry}
\RequirePackage{array}

\pagestyle{empty}
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.1mm}
\setlength{\parindent}{0pt}

\ifx\pdfoutput\undefined
  \RequirePackage[dvips]{graphicx}
  \DeclareGraphicsExtensions{.eps}
  \RequirePackage[dvips]{color}
\else
  \RequirePackage[pdftex]{graphicx}
  \DeclareGraphicsExtensions{.png,.jpg,.pdf}
  \RequirePackage[pdftex]{color}
\fi

\def\audiocd@setcommand#1{\textsl{Set a #1 with \textbackslash{}#1}}

\def\audiocd@title   {\audiocd@setcommand{title}}
\let\audiocd@subtitle=\relax
\let\audiocd@supertitle=\relax
\let\audiocd@artist=\relax
\let\audiocd@cover=\relax
\let\audiocd@cover@head=\relax
\let\audiocd@date=\relax

\def\audiocd@sidetext{\textbf{\audiocd@title}}
\def\audio@cover@bg{white}

\newcommand\supertitle[1]{\gdef\audiocd@supertitle{#1}}
\renewcommand\title[1]{\gdef\audiocd@title{#1}}
\newcommand\subtitle[1]{\gdef\audiocd@subtitle{#1}}
\newcommand\sidetext[1]{\gdef\audiocd@sidetext{\textbf{#1}}}
\newcommand\artist[1]{\gdef\audiocd@artist{#1}}
\newcommand\coverhead[1]{\gdef\audiocd@cover@head{#1}}
\newcommand\cover[1]{\gdef\audiocd@cover{#1}}
\renewcommand\date[1]{\gdef\audiocd@date{#1}}
\newcommand\coverbackground[1]{\gdef\audio@cover@bg{#1}}

\newsavebox{\frameenvbox}
\newenvironment{frameenv}
{\begin{lrbox}{\frameenvbox}}
{\end{lrbox}\framebox{\usebox{\frameenvbox}}}

\newcommand{\coverbox}{\fcolorbox{black}{\audio@cover@bg}}

\newenvironment{block}[3]{%
\begin{minipage}{13.5cm}%
\begin{center}
\textbf{\ifx\relax#1\relax
\audiocd@title
\else
#1
\fi}
\vspace{.3em plus0em minus 0.2em}

\ifx\relax#2\relax
  \if\audiocd@artist\relax
  \else
{\small \audiocd@artist\ifx\relax#3\relax
                          \if\audiocd@date\relax
                          \else, \audiocd@date
                          \fi
                        \else, #3\fi}
\vspace{.5em}

  \fi
\else
{\small #2\ifx\relax#3\relax
                          \if\audiocd@date\relax
                          \else, \audiocd@date
                          \fi
                        \else, #3\fi}
\vspace{.5em}

\fi
\begin{minipage}{12.9cm}
\sffamily\scriptsize
}{%
\end{minipage}% 12.9cm
\end{center}%
\end{minipage}% 13.5cm
\vspace{1em plus1em minus1em}
}

\newenvironment{content}{
\begin{center}%
\textbf{\audiocd@title}
\vspace{.5em}

\if\audiocd@artist\relax\else
{\small \audiocd@artist\if\audiocd@date\relax\else, \audiocd@date\fi}
\vspace{.5em}

\fi
\begin{minipage}{12.9cm}
\sffamily\scriptsize

}{%
\end{minipage}%
\end{center}%
}

\AtBeginDocument{%
\begin{center}
\sffamily
\fbox{\parbox[c][11.95cm][c]{1.99cm}{\ }}\hspace{-\fboxrule}%
\fbox{\parbox[c][11.95cm][c]{2.39cm}{\ }}\hspace{-\fboxrule}%
\coverbox{\begin{minipage}[c][11.95cm][c]{12.15cm}%
\begin{center}
\if\audiocd@cover\relax
\if\audiocd@cover@head\relax\else
\vspace*{1cm}

\textit{\scriptsize \audiocd@cover@head}\fi
\vfill 

\if\audiocd@supertitle\relax\else
\textbf{\large \audiocd@supertitle}
\medskip

\fi
\textbf{\LARGE \audiocd@title}
\if\audiocd@subtitle\relax\else
\medskip

\textbf{\large \audiocd@subtitle}
\fi
\vfill 

\if\audiocd@artist\relax\else
\audiocd@artist
\vspace{5mm}

\fi
\else
\center\includegraphics[height=11.95cm,width=12.15cm,keepaspectratio]{\audiocd@cover}%
\fi
\end{center}
\end{minipage}}\hspace{-\fboxrule}%
\fbox{\parbox[c][11.95cm][c]{2.39cm}{\ }}\hspace{-\fboxrule}%
\fbox{\parbox[c][11.95cm][c]{1.99cm}{\ }}
\vspace{1cm}

\fbox{\begin{minipage}[c][11.8cm][c]{0.65cm}%
\hspace{1.50mm}\rotatebox{-90}{\audiocd@sidetext}%
\end{minipage}}\hspace{-\fboxrule}%
\begin{frameenv}%
\begin{minipage}[c][11.8cm][c]{13.7cm}%
}

\AtEndDocument{%
\end{minipage}
\end{frameenv}\hspace{-\fboxrule}%
\fbox{\begin{minipage}[c][11.8cm][c]{0.65cm}%
\hspace{1.50mm}\rotatebox{-90}{\audiocd@sidetext}%
\end{minipage}}
\end{center}
}
