00001 #ifndef COUNTERPOINT_HPP
00002 #define COUNTERPOINT_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #include "Platform.hpp"
00053 #ifdef SWIG
00054 %module CsoundAC
00055 %{
00056 #include <string>
00057 #include <cstdarg>
00058 #include <stdio.h>
00059 #include <malloc.h>
00060 #include <boost/random.hpp>
00061 #include <boost/random/variate_generator.hpp>
00062 %}
00063 #else
00064 #include <string>
00065 #include <cstdarg>
00066 #include <stdio.h>
00067 #include <malloc.h>
00068 #include <boost/numeric/ublas/matrix.hpp>
00069 #include <boost/numeric/ublas/vector.hpp>
00070 #include <boost/random.hpp>
00071 #include <boost/random/variate_generator.hpp>
00072 #include "Random.hpp"
00073 using namespace boost::numeric;
00074 #endif
00075
00076 class Counterpoint
00077 {
00078 public:
00079 void (*messageCallback)(CSOUND *csound, int attribute, const char *format, va_list valist);
00080 void message(const char *format,...);
00081 void message(const char *format, va_list valist);
00082 int MostNotes;
00083 int MostVoices;
00084 enum
00085 {
00086 MostNotes_ = 128,
00087 MostVoices_ = 12
00088 };
00089 long randx;
00090 boost::numeric::ublas::matrix<int> Ctrpt;
00091 boost::numeric::ublas::matrix<int> Onset;
00092 boost::numeric::ublas::matrix<int> Dur;
00093 boost::numeric::ublas::vector<int> TotalNotes;
00094 boost::numeric::ublas::matrix<int> BestFit;
00095 boost::numeric::ublas::matrix<int> BestFit1;
00096 boost::numeric::ublas::matrix<int> BestFit2;
00097 boost::numeric::ublas::vector<int> vbs;
00098 boost::numeric::ublas::matrix<int> RhyPat;
00099 boost::numeric::ublas::vector<int> RhyNotes;
00100 int Fits[3];
00101 virtual void initialize(int mostnotes, int mostvoices);
00102 virtual void clear();
00103 Counterpoint();
00104 virtual ~Counterpoint();
00105 int ABS(int i);
00106 int MIN(int a, int b);
00107 int MAX(int a, int b);
00108 void ARRBLT(int *dest, int *source, int num);
00109 enum
00110 {
00111 Unison = 0,
00112 MinorSecond = 1,
00113 MajorSecond = 2,
00114 MinorThird = 3,
00115 MajorThird = 4,
00116 Fourth = 5,
00117 Tritone = 6,
00118 Fifth = 7,
00119 MinorSixth = 8,
00120 MajorSixth = 9,
00121 MinorSeventh = 10,
00122 MajorSeventh = 11,
00123 Octave = 12
00124 };
00125 #if !defined(SWIG)
00126 static int PerfectConsonance[13];
00127 static int ImperfectConsonance[13];
00128 static int Dissonance[13];
00129 #endif
00130 enum
00131 {
00132 Aeolian = 1,
00133 Dorian = 2,
00134 Phrygian = 3,
00135 Lydian = 4,
00136 Mixolydian = 5,
00137 Ionian = 6,
00138 Locrian = 7
00139 };
00140 #if !defined(SWIG)
00141 static int _Ionian[12];
00142 static int _Dorian[12];
00143 static int _Phrygian[12];
00144 static int _Lydian[12];
00145 static int _Mixolydian[12];
00146 static int _Aeolian[12];
00147 static int _Locrian[12];
00148 #endif
00149 int InMode(int Pitch, int Mode);
00150 #if !defined(SWIG)
00151 static int BadMelodyInterval[13];
00152 #endif
00153 int BadMelody(int Intv);
00154 int ASkip(int Interval);
00155 int AStep(int Interval);
00156 int AThird(int Interval);
00157 int ASeventh(int Interval);
00158 int AnOctave(int Interval);
00159 int ATenth(int Interval);
00160 enum
00161 {
00162 DirectMotion = 1,
00163 ContraryMotion = 2,
00164 ObliqueMotion = 3,
00165 NoMotion = 4
00166 };
00167 int MotionType(int Pitch1, int Pitch2, int Pitch3, int Pitch4);
00168 int DirectMotionToPerfectConsonance(int Pitch1, int Pitch2, int Pitch3, int Pitch4);
00169 int ConsecutiveSkipsInSameDirection(int Pitch1, int Pitch2, int Pitch3);
00170 int LowestSemitone;
00171 int HighestSemitone;
00172 int OutOfRange(int Pitch);
00173 int ExtremeRange(int Pitch);
00174 int BasePitch,Mode,TotalTime;
00175 int Us(int n, int v);
00176 int LastNote(int n, int v);
00177 int FirstNote(int n, int v);
00178 int NextToLastNote(int n, int v);
00179 void SetUs(int n, int p, int v);
00180 int TotalRange(int Cn, int Cp, int v);
00181 int Cantus(int n, int v);
00182 int VIndex(int Time, int VNum);
00183 int Other(int Cn, int v, int v1);
00184 int Bass(int Cn, int v);
00185 enum {
00186
00187 WholeNote = 8,
00188 HalfNote = 4,
00189 DottedHalfNote = 6,
00190 QuarterNote = 2,
00191 DottedQuarterNote = 3,
00192 EighthNote = 1
00193 };
00194 int Beat8(int n);
00195 int DownBeat(int n, int v);
00196 int UpBeat(int n, int v);
00197 int PitchRepeats(int Cn, int Cp, int v);
00198 enum {
00199 One = 0,
00200 Two = 2,
00201 Three = 3,
00202 Four = 4,
00203 Five = 5,
00204 Six = 6,
00205 Eight = 8
00206 };
00207 int Size(int MelInt);
00208 int TooMuchOfInterval(int Cn, int Cp, int v);
00209 int ADissonance(int Interval, int Cn, int Cp, int v, int Species);
00210 int Doubled(int Pitch, int Cn, int v);
00211 enum
00212 {
00213 infinity = 1000000,
00214 Bad = 100,
00215 RealBad = 200
00216 };
00217 int UnisonPenalty;
00218 int DirectToFifthPenalty;
00219 int DirectToOctavePenalty;
00220 int ParallelFifthPenalty;
00221 int ParallelUnisonPenalty;
00222 int EndOnPerfectPenalty;
00223 int NoLeadingTonePenalty;
00224 int DissonancePenalty;
00225 int OutOfRangePenalty;
00226 int OutOfModePenalty;
00227 int TwoSkipsPenalty;
00228 int DirectMotionPenalty;
00229 int PerfectConsonancePenalty;
00230 int CompoundPenalty;
00231 int TenthToOctavePenalty;
00232 int SkipTo8vePenalty;
00233 int SkipFromUnisonPenalty;
00234 int SkipPrecededBySameDirectionPenalty;
00235 int FifthPrecededBySameDirectionPenalty;
00236 int SixthPrecededBySameDirectionPenalty;
00237 int SkipFollowedBySameDirectionPenalty;
00238 int FifthFollowedBySameDirectionPenalty;
00239 int SixthFollowedBySameDirectionPenalty;
00240 int TwoSkipsNotInTriadPenalty;
00241 int BadMelodyPenalty;
00242 int ExtremeRangePenalty;
00243 int LydianCadentialTritonePenalty;
00244 int LowerNeighborPenalty;
00245 int UpperNeighborPenalty;
00246 int OverTwelfthPenalty;
00247 int OverOctavePenalty;
00248 int SixthLeapPenalty;
00249 int OctaveLeapPenalty;
00250 int BadCadencePenalty;
00251 int DirectPerfectOnDownbeatPenalty;
00252 int RepetitionOnUpbeatPenalty;
00253 int DissonanceNotFillingThirdPenalty;
00254 int UnisonDownbeatPenalty;
00255 int TwoRepeatedNotesPenalty;
00256 int ThreeRepeatedNotesPenalty;
00257 int FourRepeatedNotesPenalty;
00258 int LeapAtCadencePenalty;
00259 int NotaCambiataPenalty;
00260 int NotBestCadencePenalty;
00261 int UnisonOnBeat4Penalty;
00262 int NotaLigaturePenalty;
00263 int LesserLigaturePenalty;
00264 int UnresolvedLigaturePenalty;
00265 int NoTimeForaLigaturePenalty;
00266 int EighthJumpPenalty;
00267 int HalfUntiedPenalty;
00268 int UnisonUpbeatPenalty;
00269 int MelodicBoredomPenalty;
00270 int SkipToDownBeatPenalty;
00271 int ThreeSkipsPenalty;
00272 int DownBeatUnisonPenalty;
00273 int VerticalTritonePenalty;
00274 int MelodicTritonePenalty;
00275 int AscendingSixthPenalty;
00276 int RepeatedPitchPenalty;
00277 int NotContraryToOthersPenalty;
00278 int NotTriadPenalty;
00279 int InnerVoicesInDirectToPerfectPenalty;
00280 int InnerVoicesInDirectToTritonePenalty;
00281 int SixFiveChordPenalty;
00282 int UnpreparedSixFivePenalty;
00283 int UnresolvedSixFivePenalty;
00284 int AugmentedIntervalPenalty;
00285 int ThirdDoubledPenalty;
00286 int DoubledLeadingTonePenalty;
00287 int DoubledSixthPenalty;
00288 int DoubledFifthPenalty;
00289 int TripledBassPenalty;
00290 int UpperVoicesTooFarApartPenalty;
00291 int UnresolvedLeadingTonePenalty;
00292 int AllVoicesSkipPenalty;
00293 int DirectToTritonePenalty;
00294 int CrossBelowBassPenalty;
00295
00296 int CrossAboveCantusPenalty;
00297 int NoMotionAgainstOctavePenalty;
00298 int SpecialSpeciesCheck(int Cn, int Cp, int v, int Other0, int Other1, int Other2, int NumParts,
00299 int Species, int MelInt, int Interval, int ActInt, int LastIntClass, int Pitch, int LastMelInt, int CurLim);
00300 enum
00301 {
00302 INTERVALS_WITH_BASS_SIZE = 8
00303 };
00304 int IntervalsWithBass[INTERVALS_WITH_BASS_SIZE];
00305
00306 void AddInterval(int n);
00307 int OtherVoiceCheck(int Cn, int Cp, int v, int NumParts, int Species, int CurLim);
00308 int Check(int Cn, int Cp, int v, int NumParts, int Species, int CurLim);
00309 int BestFitPenalty,MaxPenalty,Branches,AllDone;
00310 float PenaltyRatio;
00311 enum
00312 {
00313 NumFields = 16,
00314 Field = (MostVoices_+1),
00315 EndF = (Field*NumFields)
00316 };
00317 int SaveIndx(int indx, int *Sp);
00318 void SaveResults(int CurrentPenalty, int Penalty, int v1, int Species);
00319 #if !defined(SWIG)
00320 static int Indx[17];
00321 #endif
00322 int Look(int CurPen, int CurVoice, int NumParts, int Species, int Lim, int *Pens, int *Is, int *CurNotes);
00323 void BestFitFirst(int CurTime, int CurrentPenalty, int NumParts, int Species, int BrLim);
00324 void FillRhyPat();
00325 float RANDOM(float amp);
00326 void UsedRhy(int n);
00327 int CurRhy(int n);
00328 void CleanRhy();
00329 int GoodRhy();
00330 void counterpoint(int OurMode, int *StartPitches, int CurV, int CantusFirmusLength, int Species, int *cantus);
00331 void AnySpecies(int OurMode, int *StartPitches, int CurV, int CantusFirmusLength, int Species);
00332 void fillCantus(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9, int c10, int c11, int c12, int c13, int c14);
00333 void toCsoundScore(std::string filename, double secondsPerPulse);
00334 void winners(int v1, int *data, int *best, int *best1, int *best2, int *durs);
00335 #if !defined(SWIG)
00336 static boost::mt19937 mersenneTwister;
00337 boost::variate_generator<boost::mt19937, boost::uniform_real<> > *uniform_real_generator;
00338 #endif
00339 };
00340
00341 #endif
00342