X-Git-Url: http://git.johnwright.org/?p=fmit.git;a=blobdiff_plain;f=libs%2FMusic%2FScoreGenerator.h;fp=libs%2FMusic%2FScoreGenerator.h;h=3b8e8192109751ad2735269828840cd98588dd6d;hp=0000000000000000000000000000000000000000;hb=49947d1cd4506f5574b3be62ee90e9f00227d9fd;hpb=82c9faab9421b3d87a0faa84a73f55aaccbbb689 diff --git a/libs/Music/ScoreGenerator.h b/libs/Music/ScoreGenerator.h new file mode 100644 index 0000000..3b8e819 --- /dev/null +++ b/libs/Music/ScoreGenerator.h @@ -0,0 +1,238 @@ +// Copyright 2004 "Gilles Degottex" + +// This file is part of "Music" + +// "Music" is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// "Music" is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +#ifndef _ScoreGenerator_h_ +#define _ScoreGenerator_h_ + +#include +#include +#include +#include +#include +using namespace std; + +#include +#include +//#include + +#include "Music.h" +#include "Instrument.h" + +namespace Music +{ + +//! generate a randomly generated score with \ref Instrument +/*! + * \param buffer the outputed wave + * \param score the corresponding outputed score + * \param instrs the instruments + * \param lenght lenght of the score in seconds : R+* + * \param dataBySecond number of data by second : ~{11000, 22000, 44100} + * \param AFreq frequency of the A3 : ~440.0 + * \param minHT minimum halftone : Z // TODO <0 + * \param maxHT maximum halftone : Z + * \param nbNotes maximum number of notes in lenght : N* + * \param nbInstr maximum number of instruments played at the same time : N* +*/ +inline void GenerateScoreFromInstruments( + deque& buffer, + vector< vector >& score, + vector& instrs, + double lenght, + int dataBySecond, + double AFreq, + int minHT, + int maxHT, + int nbNotes, + int nbInstr) +{ + int size = int(lenght*dataBySecond); + int nbHT = maxHT-minHT+1; + int note_size = size / nbNotes; + // cout << "AFreq=" << AFreq << " dataBySecond=" << dataBySecond << endl; + // cout << "nbNotes=" << nbNotes << " lenght=" << lenght << " minHT=" << minHT << " maxHT=" << maxHT << endl; + // cout << "size=" << size << " nbHT=" << nbHT << endl; + + // TODO compute upHT so every harm are present in the range of minHT maxHT + // int maxNbHarm = 0; + // for(int i=0; igetFreqs()!=NULL) + // { + // int n = instrs[i]->getFreqs()->size(); + // maxNbHarm = std::max(maxNbHarm, n); + // } + // } + // int upHT = (int)f2h(AFreq*(maxNbHarm+1), AFreq); + // if(upHT>maxHT-minHT) throw string("not enough HT for covering all harmonics"); + // cout << upHT << endl; + + // cout << "make score ... " << instrs.size() << endl; + int t=0; + if(score.size()!=(size_t)(nbNotes*note_size)) + score.resize(nbNotes*note_size); + + assert((size_t)nbInstr<=instrs.size()); + + for(int i=0; i hs(instrs.size()); + vector< Math::polar > ps(instrs.size()); + vector play(instrs.size()); + for(size_t w=0; wgetFreqs()->size()), AFreq); +// int up = instrs[v]->getFreqs()->size(); + int up = 36; +// cout << "up=" << up << endl; +// assert(up(Random::s_random.nextDouble()/nbInstr, Random::s_random.nextDouble()*2*Math::Pi); +// ps[v] = Math::polar(1.0/nbInstr, g_random.nextDouble()*2*Math::Pi); +// cout << "halftone choosen " << hs[v] << endl; + } + +// cout << ps[v].mod << " "; + } +// cout << endl; + +// if(i==5)hs[0]=-12; +// else hs[0]=-48; + +// for(int v=0; v hs(nbVoice); + for(size_t v=0; v decals(nbVoice); + for(size_t v=0; v