<commit_before>/* Note.cc: Types for a Musical Note
 *
 * Copyright 2018 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#include <map>

#include "Note.h"

// This might be useful later
#define ROOT12_OF_2 1.0594630943592951988208028
#define CONCERT_A 440.0

std::map<PitchClass, double> PitchMap
{
	{PitchClass::C_Flat,  246.94},
	{PitchClass::C,       261.63},
	{PitchClass::C_Sharp, 277.18},
	{PitchClass::D_Flat,  277.18},
	{PitchClass::D,       293.66},
	{PitchClass::D_Sharp, 311.13},
	{PitchClass::E_Flat,  311.13},
	{PitchClass::E,       329.63},
	{PitchClass::E_Sharp, 349.23},
	{PitchClass::F_Flat,  329.63},
	{PitchClass::F,       349.23},
	{PitchClass::F_Sharp, 369.99},
	{PitchClass::G_Flat,  369.99},
	{PitchClass::G,       392.00},
	{PitchClass::G_Sharp, 415.30},
	{PitchClass::A_Flat,  415.30},
	{PitchClass::A,       440.00},
	{PitchClass::A_Sharp, 466.16},
	{PitchClass::B_Flat,  466.16},
	{PitchClass::B,       493.88},
	{PitchClass::B_Sharp, 523.25},
};

PitchClass MakePitchClass(char Letter, char Accidental)
{
	if (Letter >= 'a' && Letter <= 'g')
		Letter -= 'a' - 'A';

	if (Letter < 'A' || Letter > 'G')
		return PitchClass::None;

	int Adjustment = 2;
	switch (Accidental)
	{
		case '-':
		case 'b':
			Adjustment = 1;
			break;
		case '+':
		case '#':
			Adjustment = 3;
			break;
		default:
			break;
	}
	return static_cast<PitchClass>((Letter - 'A')*3 + Adjustment);
}

class Pitch::Pimpl
{
public:
	inline Pimpl(PitchClass newClass, int newOctave)
	: PitchClass(newClass), Octave(newOctave)
	{
	}

	PitchClass PitchClass;
	int Octave;
};

Pitch::Pitch(PitchClass newClass, int newOctave)
	: p(new Pimpl(newClass, newOctave))
{
}

Pitch::Pitch(const Pitch& src)
	: p(new Pimpl(src.p->PitchClass, src.p->Octave))
{

}

Pitch::~Pitch()
{
	//delete p;
}

PitchClass Pitch::Class() const
{
	return p->PitchClass;
}

int Pitch::Octave() const
{
	return p->Octave;
}

double  Pitch::Frequency() const
{
	return PitchMap[p->PitchClass] * (1<<(p->Octave-4));
}

class Note::Pimpl
{
public:
	inline Pimpl(class Pitch newPitch,
		int newDurationNumerator, int newDurationDenominator)
	: Pitch(newPitch), DurationNumerator(newDurationNumerator),
		DurationDenominator(newDurationDenominator)
	{
	}

	class Pitch Pitch;
	int DurationNumerator;
	int DurationDenominator;
};

Note::Note(class Pitch newPitch, int  newDurationNumerator,
		int newDurationDenominator)
	: p(new Pimpl(newPitch, newDurationNumerator,<commit_msg>Fix bug with octaves lower than 4<commit_after>/* Note.cc: Types for a Musical Note
 *
 * Copyright 2018 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#include <cmath>
#include <map>

#include "Note.h"

// This might be useful later
#define ROOT12_OF_2 1.0594630943592951988208028
#define CONCERT_A 440.0

std::map<PitchClass, double> PitchMap
{
	{PitchClass::C_Flat,  246.94},
	{PitchClass::C,       261.63},
	{PitchClass::C_Sharp, 277.18},
	{PitchClass::D_Flat,  277.18},
	{PitchClass::D,       293.66},
	{PitchClass::D_Sharp, 311.13},
	{PitchClass::E_Flat,  311.13},
	{PitchClass::E,       329.63},
	{PitchClass::E_Sharp, 349.23},
	{PitchClass::F_Flat,  329.63},
	{PitchClass::F,       349.23},
	{PitchClass::F_Sharp, 369.99},
	{PitchClass::G_Flat,  369.99},
	{PitchClass::G,       392.00},
	{PitchClass::G_Sharp, 415.30},
	{PitchClass::A_Flat,  415.30},
	{PitchClass::A,       440.00},
	{PitchClass::A_Sharp, 466.16},
	{PitchClass::B_Flat,  466.16},
	{PitchClass::B,       493.88},
	{PitchClass::B_Sharp, 523.25},
};

PitchClass MakePitchClass(char Letter, char Accidental)
{
	if (Letter >= 'a' && Letter <= 'g')
		Letter -= 'a' - 'A';

	if (Letter < 'A' || Letter > 'G')
		return PitchClass::None;

	int Adjustment = 2;
	switch (Accidental)
	{
		case '-':
		case 'b':
			Adjustment = 1;
			break;
		case '+':
		case '#':
			Adjustment = 3;
			break;
		default:
			break;
	}
	return static_cast<PitchClass>((Letter - 'A')*3 + Adjustment);
}

class Pitch::Pimpl
{
public:
	inline Pimpl(PitchClass newClass, int newOctave)
	: PitchClass(newClass), Octave(newOctave)
	{
	}

	PitchClass PitchClass;
	int Octave;
};

Pitch::Pitch(PitchClass newClass, int newOctave)
	: p(new Pimpl(newClass, newOctave))
{
}

Pitch::Pitch(const Pitch& src)
	: p(new Pimpl(src.p->PitchClass, src.p->Octave))
{

}

Pitch::~Pitch()
{
	//delete p;
}

PitchClass Pitch::Class() const
{
	return p->PitchClass;
}

int Pitch::Octave() const
{
	return p->Octave;
}

double  Pitch::Frequency() const
{
	return PitchMap[p->PitchClass] * std::pow(2.0, p->Octave - 4);
}

class Note::Pimpl
{
public:
	inline Pimpl(class Pitch newPitch,
		int newDurationNumerator, int newDurationDenominator)
	: Pitch(newPitch), DurationNumerator(newDurationNumerator),
		DurationDenominator(newDurationDenominator)
	{
	}

	class Pitch Pitch;
	int DurationNumerator;
	int DurationDenominator;
};

Note::Note(class Pitch newPitch, int  newDurationNumerator,
		int newDurationDenominator)
	: p(new Pimpl(newPitch, newDurationNumerator,
{'fraction_non_alphanumeric': 0.14491539621377114, 'fraction_numerical': 0.051264868487183785, 'mean_word_length': 4.287865367581931, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5950073', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2280, 'n_words': 543}