#include "KSInstrument.h" #include //Constructor KSInstrument :: KSInstrument(int numberOfStringsIn, int numberOfVoicesIn, double lowNoteFreqIn, double feedbackGainIn, double fsIn) { fs = fsIn; lowNoteFreq = lowNoteFreqIn; feedbackGain = feedbackGainIn; numberOfStrings = numberOfStringsIn; numberOfVoices = numberOfVoicesIn; //Initialize strings ksStringsCollection = new KSString*[numberOfStrings]; for (unsigned int i=0; i < numberOfStrings; i++) { ksStringsCollection[i] = new KSString(lowNoteFreq*pow(2,i/12.0), lowNoteFreq*pow(2,i/12.0), fs, feedbackGain); } } //Destructor KSInstrument :: ~KSInstrument() { for (unsigned int i=0; ipluck(velocity); activeStrings.push_front(stringNum); } } //Marks the given string as no longer active (no longer being played) void KSInstrument :: markInactive(int stringNum) { activeStrings.remove(stringNum); } //Gets the sum of the next output samples from all active strings and increments time one sample for those strings SAMPLE KSInstrument :: tick() { SAMPLE outputSum = 0.0; for(iter=activeStrings.begin(); iter != activeStrings.end(); ++iter) outputSum += ksStringsCollection[*iter]->tick(); return outputSum; } void KSInstrument :: setFeedbackGain(double feedbackGainIn) { feedbackGain = feedbackGainIn; for( unsigned int i=0; isetFeedbackGain(feedbackGain); } void KSInstrument :: clear() { for(iter=activeStrings.begin(); iter != activeStrings.end(); ++iter) ksStringsCollection[*iter]->clear(); }