From: <pst...@us...> - 2013-04-07 06:00:01
|
Revision: 1005 http://sourceforge.net/p/jazzplusplus/code/1005 Author: pstieber Date: 2013-04-07 05:59:57 +0000 (Sun, 07 Apr 2013) Log Message: ----------- 1. Simplified array code. 2. Added more code to the rhythm generator. 3. Used ostringstream instead of char buf[]. Modified Paths: -------------- trunk/jazz/src/DynamicArray.cpp trunk/jazz/src/DynamicArray.h trunk/jazz/src/Random.cpp trunk/jazz/src/Random.h trunk/jazz/src/Resources.h trunk/jazz/src/Rhythm.cpp trunk/jazz/src/Rhythm.h trunk/jazz/src/SampleDialog.cpp trunk/jazz/src/Track.cpp trunk/jazz/src/Track.h trunk/jazz/src/mswin/WindowsMidiInterface.cpp trunk/jazz/src/mswin/WindowsMidiInterface.h trunk/jazz/src/mswin/WindowsPlayer.cpp trunk/jazz/src/mswin/WindowsPlayer.h Modified: trunk/jazz/src/DynamicArray.cpp =================================================================== --- trunk/jazz/src/DynamicArray.cpp 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/DynamicArray.cpp 2013-04-07 05:59:57 UTC (rev 1005) @@ -21,37 +21,3 @@ //***************************************************************************** #include "DynamicArray.h" - -DEFINE_ARRAY(JZIntArray, int) - -JZUniqIds::JZUniqIds() - : mArray(0) -{ - mArray[0] = 1; // 0 is an invalid id -} - -int JZUniqIds::Get() -{ - int i = 0; - while (mArray[i]) - { - ++i; - } - mArray[i] = 1; - return i; -} - -void JZUniqIds::Get(int id) -{ - ++mArray[id]; -} - -int JZUniqIds::Put(int id) -{ - int i = --mArray[id]; - assert(i >= 0); - return i; -} - - -DEFINE_ARRAY(JZVoidPtrArray, void *) Modified: trunk/jazz/src/DynamicArray.h =================================================================== --- trunk/jazz/src/DynamicArray.h 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/DynamicArray.h 2013-04-07 05:59:57 UTC (rev 1005) @@ -22,7 +22,8 @@ #pragma once -#include <assert.h> +#include <cassert> +#include <vector> #define DECLARE_ARRAY(CLASS, TYPE) \ \ @@ -162,27 +163,6 @@ } -DECLARE_ARRAY(JZIntArray, int) - - - -class JZUniqIds -{ - public: - - JZUniqIds(); - int Get(); - void Get(int id); - - // Returns the no of pending references to id. - int Put(int id); - - private: - - JZIntArray mArray; -}; - - class JZBitset { public: @@ -201,18 +181,10 @@ mArray[index(i)] &= ~mask(i); } } - void operator += (int i) - { - mArray[index(i)] |= mask(i); - } - void operator -= (int i) - { - mArray[index(i)] &= ~mask(i); - } private: - JZIntArray mArray; + std::vector<int> mArray; // this works for sizeof(int) >= 4 int index(int i) @@ -224,5 +196,3 @@ return 1 << (i & 31); } }; - -DECLARE_ARRAY(JZVoidPtrArray, void *) Modified: trunk/jazz/src/Random.cpp =================================================================== --- trunk/jazz/src/Random.cpp 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/Random.cpp 2013-04-07 05:59:57 UTC (rev 1005) @@ -30,9 +30,12 @@ #include <cassert> #include <cstdlib> +#include <sstream> using namespace std; +//***************************************************************************** +//***************************************************************************** double JZRandomGenerator::asDouble() { return double(rand()) / double(RAND_MAX); @@ -40,307 +43,350 @@ JZRandomGenerator rnd; -// Array of probabilities - -JZRndArray::JZRndArray(int nn, int mmin, int mmax) +//***************************************************************************** +// Description: +// Array of probabilities +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZRndArray::JZRndArray(int Size, int Min, int Max) + : mArray(Size), + mNull(0), + mMin(Min), + mMax(Max) { - int i; - n = nn; - for (i = 0; i < n; i++) + for (size_t i = 0; i < mArray.size(); ++i) { - mArray[i] = mmin; + mArray[i] = Min; } - min = mmin; - max = mmax; - nul = min > 0 ? min : 0; + mNull = mMin > 0 ? mMin : 0; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRndArray::JZRndArray(const JZRndArray& Other) : mArray(Other.mArray), - n(Other.n), - nul(Other.nul), - min(Other.min), - max(Other.max) + mNull(Other.mNull), + mMin(Other.mMin), + mMax(Other.mMax) { } -void JZRndArray::SetMinMax(int mi, int ma) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZRndArray::~JZRndArray() { - min = mi; - max = ma; - nul = min > 0 ? min : 0; - for (int i = 0; i < mArray.GetSize(); i++) +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRndArray::SetMinMax(int Min, int Max) +{ + mMin = Min; + mMax = Max; + mNull = mMin > 0 ? mMin : 0; + for (size_t i = 0; i < mArray.size(); ++i) { - if (mArray[i] < min) + if (mArray[i] < mMin) { - mArray[i] = min; + mArray[i] = mMin; } - else if (mArray[i] > max) + else if (mArray[i] > mMax) { - mArray[i] = max; + mArray[i] = mMax; } } } -JZRndArray::~JZRndArray() -{ -} - -/* PAT - The following ifdef was removed due to the changes implemented in gcc - 3.x. The new gcc is more compatible with Windows. */ -/*#ifdef FOR_MSW*/ +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- double JZRndArray::operator[](double f) - /*#else -double JZRndArray::operator[](double f) const -#endif*/ { int i = (int)f; if (i < 0) + { i = 0; - else if (i >= n - 2) - i = n - 2; - JZMapper Map(i, i+1, mArray[i], mArray[i+1]); + } + else if (i >= mArray.size() - 2) + { + i = mArray.size() - 2; + } + JZMapper Map(i, i + 1, mArray[i], mArray[i+1]); return Map.XToY(f); } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRndArray& JZRndArray::operator = (const JZRndArray& Rhs) { if (this != &Rhs) { mArray = Rhs.mArray; - n = Rhs.n; - min = Rhs.min; - max = Rhs.max; - nul = Rhs.nul; + mMin = Rhs.mMin; + mMax = Rhs.mMax; + mNull = Rhs.mNull; } return *this; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRndArray::Random() { return Random(rnd.asDouble()); } -int JZRndArray::Random(double rndval) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZRndArray::Random(double RandonValue) { - double sum, dec; - int i; + assert(!mArray.empty()); - assert(n > 0); - - sum = 0.0; - for (i = 0; i < n; i++) + double Sum = 0.0; + for (size_t i = 0; i < mArray.size(); ++i) { assert(mArray[i] >= 0); - sum += mArray[i]; + Sum += mArray[i]; } - if (sum <= 0) + if (Sum <= 0) + { return 0; + } - dec = sum * rndval * 0.99999; - assert(dec < sum); + double dec = Sum * RandonValue * 0.99999; + assert(dec < Sum); - i = 0; + int i = 0; while (dec >= 0.0) { - dec -= mArray[i]; - i++; + dec -= mArray[i++]; } i--; - assert(i >= 0 && i < n); + assert(i >= 0 && i < mArray.size()); return i; } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRndArray::Interval(int seed) { - if (seed < 0) // initial ? - seed = int(rnd.asDouble() * n); + // Test to see if this is the initial call. + if (seed < 0) + { + seed = int(rnd.asDouble() * mArray.size()); + } int delta = Random(); if (rnd.asDouble() < 0.5) + { delta = -delta; - seed = (seed + n + delta) % n; + } + seed = (seed + mArray.size() + delta) % mArray.size(); return seed; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRndArray::Random(int i) { - return rnd.asDouble() * (max - min) < mArray[i]; + return rnd.asDouble() * (mMax - mMin) < mArray[i]; } - -void JZRndArray::SetUnion(JZRndArray &o, int fuzz) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRndArray::SetUnion(JZRndArray& Other, int fuzz) { - for (int i = 0; i < n; i++) + for (size_t i = 0; i < mArray.size(); ++i) { - int val = mArray[i]; - if (o.mArray[i] > val) + int Value = mArray[i]; + if (Other.mArray[i] > Value) { - val = o.mArray[i]; + Value = Other.mArray[i]; } - mArray[i] = Fuzz(fuzz, mArray[i], val); + mArray[i] = Fuzz(fuzz, mArray[i], Value); } } - -void JZRndArray::SetIntersection(JZRndArray &o, int fuzz) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRndArray::SetIntersection(JZRndArray& Other, int fuzz) { - for (int i = 0; i < n; i++) + for (size_t i = 0; i < mArray.size(); ++i) { - int val = mArray[i]; - if (o.mArray[i] < val) + int Value = mArray[i]; + if (Other.mArray[i] < Value) { - val = o.mArray[i]; + Value = Other.mArray[i]; } - mArray[i] = Fuzz(fuzz, mArray[i], val); + mArray[i] = Fuzz(fuzz, mArray[i], Value); } } - -void JZRndArray::SetDifference(JZRndArray &o, int fuzz) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRndArray::SetDifference(JZRndArray& Other, int fuzz) { - JZRndArray tmp(o); + JZRndArray tmp(Other); tmp.SetInverse(tmp.Max()); SetIntersection(tmp, fuzz); } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRndArray::SetInverse(int fuzz) { - for (int i = 0; i < n; i++) + for (size_t i = 0; i < mArray.size(); ++i) { - mArray[i] = Fuzz(fuzz, mArray[i], min + max - mArray[i]); + mArray[i] = Fuzz(fuzz, mArray[i], mMin + mMax - mArray[i]); } } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRndArray::Fuzz(int fuz, int v1, int v2) const { // interpolate between v1 and v2 - return (fuz - min) * v2 / (max - min) + (max - fuz) * v1 / (max - min); + return (fuz - mMin) * v2 / (mMax - mMin) + (mMax - fuz) * v1 / (mMax - mMin); } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRndArray::Clear() { - for (int i = 0; i < n; i++) + for (size_t i = 0; i < mArray.size(); ++i) { - mArray[i] = min; + mArray[i] = mMin; } } - -ostream & operator << (ostream &os, JZRndArray const &a) +//***************************************************************************** +//***************************************************************************** +ostream& operator << (ostream& Os, const JZRndArray& RndArray) { - int i; - - os << a.n << ' ' << a.min << ' ' << a.max << endl; - for (i = 0; i < a.n; i++) + Os + << RndArray.mArray.size() + << ' ' << RndArray.mMin + << ' ' << RndArray.mMax + << '\n'; + for (size_t i = 0; i < RndArray.mArray.size(); ++i) { - os << a.mArray[i] << ' '; + Os << RndArray.mArray[i] << ' '; } - os << endl; - return os; + Os << endl; + return Os; } - -istream & operator >> (istream &is, JZRndArray &a) +//***************************************************************************** +//***************************************************************************** +istream & operator >> (istream& Is, JZRndArray& RndArray) { - int i; - is >> a.n >> a.min >> a.max; - for (i = 0; i < a.n; i++) - is >> a.mArray[i]; - return is; + unsigned Size; + Is >> Size >> RndArray.mMin >> RndArray.mMax; + RndArray.mArray.resize(Size); + for (size_t i = 0; i < RndArray.mArray.size(); ++i) + { + Is >> RndArray.mArray[i]; + } + return Is; } - -// --------------------------------- JZArrayEdit ------------------------------------- - +//***************************************************************************** // length of tickmark line +//***************************************************************************** #define TICK_LINE 0 +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +BEGIN_EVENT_TABLE(JZArrayEdit, wxScrolledWindow) + EVT_SIZE(JZArrayEdit::OnSize) + EVT_MOUSE_EVENTS(JZArrayEdit::OnMouseEvent) +END_EVENT_TABLE() + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZArrayEdit::JZArrayEdit( - wxFrame *frame, - JZRndArray &ar, + wxFrame* pFrame, + JZRndArray& Array, const wxPoint& Position, const wxSize& Size, int StyleBits) - : wxScrolledWindow(frame, wxID_ANY, Position, Size), - mArray(ar), - n(ar.n), - min(ar.min), - max(ar.max), - nul(ar.nul) + : wxScrolledWindow(pFrame, wxID_ANY, Position, Size), + mArray(Array), + mMin(Array.mMin), + mMax(Array.mMax), + mNull(Array.mNull), + mLabel(), + mpDrawBars(0), + mX(0), + mY(0), + mWidth(Size.GetWidth()), + mHeight(Size.GetHeight()), + mYNull(0), + mDragging(false), + mIndex(-1), + mXMin(0), + mXMax(mArray.Size()), + mEnabled(true), + mStyleBits(StyleBits) { - draw_bars = 0; - enabled = 1; - dragging = 0; - index = -1; - mStyleBits = StyleBits; + int TextWidth, TextHeight; - xmin = 0; - xmax = n; - - x = 0; // draw to topleft corner of canvas - y = 0; - w = Size.GetWidth(); - h = Size.GetHeight(); - - int tw, th; - wxClientDC Dc(this); Dc.SetFont(*wxSMALL_FONT); - Dc.GetTextExtent("123", &tw, &th); + Dc.GetTextExtent("123", &TextWidth, &TextHeight); if (mStyleBits & ARED_XTICKS) { - // leave space for bottomline - h -= (int)th; + // Leave space for the bottom line. + mHeight -= TextHeight; } if (mStyleBits & (ARED_MINMAX | ARED_YTICKS)) { - // leave space to display min / max - x = (int)(tw + TICK_LINE); - w -= (int)(tw + TICK_LINE); + // Leave space to display the minimum and maximum + mX = (int)(TextWidth + TICK_LINE); + mWidth -= (int)(TextWidth + TICK_LINE); } - ynul = y + h - h * (nul - min) / (max - min); + mYNull = mY + mHeight - mHeight * (mNull - mMin) / (mMax - mMin); } -BEGIN_EVENT_TABLE(JZArrayEdit, wxScrolledWindow) - EVT_SIZE(JZArrayEdit::OnSize) - EVT_MOUSE_EVENTS(JZArrayEdit::OnMouseEvent) -END_EVENT_TABLE() - - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::OnSize(wxSizeEvent& Event) { - w = Event.GetSize().GetWidth(); - h = Event.GetSize().GetHeight(); + mWidth = Event.GetSize().GetWidth(); + mHeight = Event.GetSize().GetHeight(); Event.Skip(); - int tw, th; + int TextWidth, TextHeight; wxClientDC Dc(this); - Dc.GetTextExtent("123", &tw, &th); + Dc.GetTextExtent("123", &TextWidth, &TextHeight); if (mStyleBits & ARED_XTICKS) - h -= (int)th; + { + mHeight -= TextHeight; + } if (mStyleBits & (ARED_MINMAX | ARED_YTICKS)) { - x = (int)(tw + TICK_LINE); - w -= (int)(tw + TICK_LINE); + mX = (int)(TextWidth + TICK_LINE); + mWidth -= (int)(TextWidth + TICK_LINE); } - ynul = y + h - h * (nul - min) / (max - min); + mYNull = mY + mHeight - mHeight * (mNull - mMin) / (mMax - mMin); } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZArrayEdit::~JZArrayEdit() { } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::DrawBar(wxDC& Dc, int i, int black) { if (mStyleBits & ARED_LINES) @@ -350,8 +396,8 @@ Dc.SetPen(*wxWHITE_PEN); } - JZMapper XMap(0, n, 0, w); - JZMapper YMap(min, max, h, 0); + JZMapper XMap(0, mArray.Size(), 0, mWidth); + JZMapper YMap(mMin, mMax, mHeight, 0); int x1 = (int)XMap.XToY(i + 0.5); int y1 = (int)YMap.XToY(mArray[i]); @@ -362,11 +408,11 @@ int y0 = (int)YMap.XToY(mArray[i-1]); Dc.DrawLine(x0, y0, x1, y1); } - if (i < n-1) + if (i < mArray.Size() - 1) { // draw line to next position int x2 = (int)XMap.XToY(i + 1.5); - int y2 = (int)YMap.XToY(mArray[i+1]); + int y2 = (int)YMap.XToY(mArray[i + 1]); Dc.DrawLine(x1, y1, x2, y2); } @@ -380,37 +426,39 @@ int gap = 0; if (mStyleBits & ARED_GAP) { - gap = w / n / 6; - if (!gap && w / n > 3) + gap = mWidth / mArray.Size() / 6; + if (!gap && mWidth / mArray.Size() > 3) + { gap = 1; + } } int xbar, ybar, wbar, hbar; - wbar = w / n - 2 * gap; - xbar = x + i * w / n + gap; - hbar = h * (mArray[i] - nul) / (max - min); + wbar = mWidth / mArray.Size() - 2 * gap; + xbar = mX + i * mWidth / mArray.Size() + gap; + hbar = mHeight * (mArray[i] - mNull) / (mMax - mMin); if (mStyleBits & ARED_BLOCKS) { /* - ybar = ynul - hbar; + ybar = mYNull - hbar; if (hbar < 0) hbar = -hbar; hbar = (hbar < 2) ? hbar : 2; */ int hblk = 12; - ybar = ynul - hbar - hblk/2; + ybar = mYNull - hbar - hblk/2; hbar = hblk; - if (ybar < y) + if (ybar < mY) { - int d = y - ybar; + int d = mY - ybar; ybar += d; hbar -= d; } - if (ybar + hbar > y + h) + if (ybar + hbar > mY + mHeight) { - int d = (ybar + hbar) - (y + h); + int d = (ybar + hbar) - (mY + mHeight); hbar -= d; } if (hbar < 2) @@ -420,14 +468,16 @@ if (hbar < 0) { - ybar = ynul; + ybar = mYNull; hbar = -hbar; } else - ybar = ynul - hbar; + ybar = mYNull - hbar; - if (ybar == y) + if (ybar == mY) + { ++ybar, --hbar; + } if (!black) { @@ -445,23 +495,29 @@ } } -const char *JZArrayEdit::GetXText(int xval) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +string JZArrayEdit::GetXText(int XValue) { - static char buf[8]; - sprintf(buf, "%d", xval); - return buf; + ostringstream Oss; + Oss << XValue; + return Oss.str(); } -const char *JZArrayEdit::GetYText(int yval) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +string JZArrayEdit::GetYText(int YValue) { - static char buf[8]; - sprintf(buf, "%d", yval); - return buf; + ostringstream Oss; + Oss << YValue; + return Oss.str(); } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::DrawXTicks(wxDC& Dc) { - int tw, th; + int TextWidth, TextHeight; if (!(mStyleBits & ARED_XTICKS)) { @@ -471,31 +527,38 @@ Dc.SetFont(*wxSMALL_FONT); // compute tickmark x-distance - Dc.GetTextExtent("-123", &tw, &th); - int max_labels = (int)(w / (tw + tw/2)); - if (max_labels > 0) + Dc.GetTextExtent("-123", &TextWidth, &TextHeight); + int MaxLabels = (int)(mWidth / (TextWidth + TextWidth/2)); + if (MaxLabels > 0) { - int step = (xmax - xmin + 1) / max_labels; - if (step <= 0) - step = 1; - for (int val = xmin; val <= xmax; val += step) + int Step = (mXMax - mXMin + 1) / MaxLabels; + if (Step <= 0) { - const char *buf = GetXText(val); - //sprintf(buf, "%d", val); - Dc.GetTextExtent((char *)buf, &tw, &th); - float yy = y + h; - float xx = x + w * (val - xmin) / (xmax - xmin + 1); - xx -= tw/2; // center text - xx += 0.5 * w / n; // middle of bar - Dc.DrawText(buf, (int)xx, (int)yy); - //Dc.DrawLine(x - TICK_LINE, yy, x, yy); + Step = 1; } + for (int Value = mXMin; Value <= mXMax; Value += Step) + { + string String = GetXText(Value); + Dc.GetTextExtent(String, &TextWidth, &TextHeight); + int YPosition = mY + mHeight; + float XPosition = mX + mWidth * (Value - mXMin) / (mXMax - mXMin + 1); + + // Center text. + XPosition -= TextWidth / 2; + + // Middle of bar. + XPosition += 0.5 * mWidth / mArray.Size(); + + Dc.DrawText(String, (int)XPosition, YPosition); +// Dc.DrawLine(mX - TICK_LINE, YPosition, mX, YPosition); + } } Dc.SetFont(*wxNORMAL_FONT); } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::DrawYTicks(wxDC& Dc) { @@ -503,64 +566,70 @@ if (mStyleBits & ARED_YTICKS) { - // compute tickmark y-distance - int tw, th; - Dc.GetTextExtent("-123", &tw, &th); - int max_labels = (int)(h / (th + th/2)); - if (max_labels > 0) + // Compute tickmark y-distance. + int TextWidth, TextHeight; + Dc.GetTextExtent("-123", &TextWidth, &TextHeight); + int MaxLabels = (int)(mHeight / (TextHeight + TextHeight / 2)); + if (MaxLabels > 0) { - int step = (max - min) / max_labels; - if (step <= 0) - step = 1; - for (int val = min; val < max; val += step) + int Step = (mMax - mMin) / MaxLabels; + if (Step <= 0) { - const char *buf = GetYText(val); - //sprintf(buf, "%d", val); - Dc.GetTextExtent((char *)buf, &tw, &th); - float yy = y + h - h * (val - min) / (max - min) - th/2; - Dc.DrawText(buf, x - tw - TICK_LINE, (int)yy); - //Dc.DrawLine(x - TICK_LINE, yy, x, yy); + Step = 1; } + for (int Value = mMin; Value < mMax; Value += Step) + { + string String = GetYText(Value); + Dc.GetTextExtent(String, &TextWidth, &TextHeight); + int YPosition = + mY + mHeight - mHeight * (Value - mMin) / (mMax - mMin) - + TextHeight / 2; + Dc.DrawText(String, mX - TextWidth - TICK_LINE, YPosition); +// Dc.DrawLine(mX - TICK_LINE, YPosition, mX, YPosition); + } } } - else if (mStyleBits & ARED_MINMAX) { - // min/max - int tw, th; - char buf[20]; - sprintf(buf, "%d", max); - Dc.GetTextExtent(buf, &tw, &th); - Dc.DrawText(buf, x - tw, y); - sprintf(buf, "%d", min); - Dc.GetTextExtent(buf, &tw, &th); - Dc.DrawText(buf, x - tw, y + h - th); + // mMin/mMax + int TextWidth, TextHeight; + ostringstream Oss; + Oss << mMax; + Dc.GetTextExtent(Oss.str(), &TextWidth, &TextHeight); + Dc.DrawText(Oss.str(), mX - TextWidth, mY); + + Oss.str(""); + + Oss << mMin; + Dc.GetTextExtent(Oss.str(), &TextWidth, &TextHeight); + Dc.DrawText(Oss.str(), mX - TextWidth, mY + mHeight - TextHeight); } Dc.SetFont(*wxNORMAL_FONT); - } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::DrawLabel(wxDC& Dc) { Dc.SetFont(*wxSMALL_FONT); if (!mLabel.empty()) { - Dc.DrawText(mLabel.c_str(), x + 5, y + 2); + Dc.DrawText(mLabel, mX + 5, mY + 2); } Dc.SetFont(*wxNORMAL_FONT); } - - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::OnDraw(wxDC& Dc) { int i; // surrounding rectangle Dc.Clear(); - if (enabled) + if (mEnabled) { Dc.SetBrush(*wxWHITE_BRUSH); } @@ -570,14 +639,14 @@ } Dc.SetPen(*wxBLACK_PEN); - if (w && h) + if (mWidth && mHeight) { - Dc.DrawRectangle(x, y, w, h); + Dc.DrawRectangle(mX, mY, mWidth, mHeight); } // sliders Dc.SetBrush(*wxBLACK_BRUSH); - for (i = 0; i < n; ++i) + for (i = 0; i < mArray.Size(); ++i) { DrawBar(Dc, i, 1); } @@ -586,154 +655,158 @@ DrawLabel(Dc); DrawYTicks(Dc); DrawNull(Dc); - if (draw_bars) + if (mpDrawBars) { - draw_bars->DrawBars(Dc); + mpDrawBars->DrawBars(Dc); } } - - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::DrawNull(wxDC& Dc) { + Dc.SetPen(*wxCYAN_PEN); - Dc.SetPen(*wxCYAN_PEN); - // draw y-null line - if (min < nul && nul < max) - Dc.DrawLine(x, ynul, x+w, ynul); - // draw x-null line - if (xmin < 0 && 0 < xmax) + // Draw y-null line. + if (mMin < mNull && mNull < mMax) { - int x0 = w * (0 - xmin) / (xmax - xmin); - Dc.DrawLine(x0, y, x0, y + h); + Dc.DrawLine(mX, mYNull, mX + mWidth, mYNull); } + + // Draw x-null line. + if (mXMin < 0 && 0 < mXMax) + { + int x0 = mWidth * (0 - mXMin) / (mXMax - mXMin); + Dc.DrawLine(x0, mY, x0, mY + mHeight); + } + Dc.SetPen(*wxBLACK_PEN); } - - -void JZArrayEdit::SetXMinMax(int xmi, int xma) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZArrayEdit::SetXMinMax(int XMin, int XMax) { - xmin = xmi; - xmax = xma; + mXMin = XMin; + mXMax = XMax; } -int JZArrayEdit::Index(wxMouseEvent& MouseEvent) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int JZArrayEdit::GetIndex(wxMouseEvent& MouseEvent) { - int ex, ey; - MouseEvent.GetPosition(&ex, &ey); - int i = (int)( ((short)ex - x) * n / w); - i = i < 0 ? 0 : i; - i = i >= n ? n-1 : i; - return i; + int EventX, EventY; + MouseEvent.GetPosition(&EventX, &EventY); + int Index = (int)((EventX - mX) * mArray.Size() / mWidth); + if (Index < 0) + { + Index = 0; + } + if (Index >= mArray.Size()) + { + Index = mArray.Size() - 1; + } + return Index; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZArrayEdit::Dragging(wxMouseEvent& MouseEvent) { - if (!dragging) + if (!mDragging) { return 0; } - if (index < 0) + if (mIndex < 0) { - index = Index(MouseEvent); + mIndex = GetIndex(MouseEvent); } wxClientDC Dc(this); // PORTING this is evil and shoud go - int val = nul; + int Value = mNull; if (MouseEvent.LeftIsDown()) { - int ex, ey; - MouseEvent.GetPosition(&ex, &ey); + int EventX, EventY; + MouseEvent.GetPosition(&EventX, &EventY); -#if 0 - { - // in msw ex,ey are 65536 for negative values! - char buf[500]; - sprintf(buf, "x %4.0f, y %4.0f, sh %d", ex, ey, MouseEvent.ShiftDown()); - Dc.DrawText(buf, 50, 50); - } -#endif - - // $blk$ val = (int)( (y + h - (short)ey) * (max - min) / h + min); - val = (int)( (double)(y + h - ey) * (max - min) / h + min + 0.5); - val = val > max ? max : val; - val = val < min ? min : val; + Value = (int)((double)(mY + mHeight - EventY) * (mMax - mMin) / mHeight + + mMin + 0.5); + Value = Value > mMax ? mMax : Value; + Value = Value < mMin ? mMin : Value; } if (MouseEvent.ShiftDown()) { - int k; - for (k = 0; k < n; k++) + for (int k = 0; k < mArray.Size(); ++k) { - DrawBar(Dc, k, 0); - mArray[k] = val; + mArray[k] = Value; DrawBar(Dc, k, 1); - } } else if (MouseEvent.ControlDown()) { - DrawBar(Dc, index, 0); - mArray[index] = val; - DrawBar(Dc, index, 1); + DrawBar(Dc, mIndex, 0); + mArray[mIndex] = Value; + DrawBar(Dc, mIndex, 1); } else { - int i = Index(MouseEvent); + int i = GetIndex(MouseEvent); int k = i; - if (i < index) - for (; i <= index; i++) + if (i < mIndex) + for (; i <= mIndex; ++i) { DrawBar(Dc, i, 0); - mArray[i] = val; + mArray[i] = Value; DrawBar(Dc, i, 1); } else - for (; i >= index; i--) + for (; i >= mIndex; --i) { DrawBar(Dc, i, 0); - mArray[i] = val; + mArray[i] = Value; DrawBar(Dc, i, 1); } - index = k; + mIndex = k; } return 0; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZArrayEdit::ButtonDown(wxMouseEvent& MouseEvent) { #ifdef __WXMSW__ CaptureMouse(); #endif - dragging = 1; - index = Index(MouseEvent); + mDragging = true; + mIndex = GetIndex(MouseEvent); Dragging(MouseEvent); return 0; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZArrayEdit::ButtonUp(wxMouseEvent& MouseEvent) { #ifdef __WXMSW__ ReleaseMouse(); #endif - dragging = 0; - index = -1; -// wxClientDC Dc(this); // PORTING this is evil and shoud go -// DrawLabel(Dc); -// DrawNull(Dc); + mDragging = false; + mIndex = -1; Refresh(); return 0; } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZArrayEdit::OnMouseEvent(wxMouseEvent& MouseEvent) { - if (!enabled) + if (!mEnabled) { return; } @@ -751,58 +824,66 @@ } } -void JZArrayEdit::Enable(int e) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZArrayEdit::SetEnabled(bool Enabled) { - enabled = e; + mEnabled = Enabled; } -void JZArrayEdit::SetLabel(char const* pLabel) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZArrayEdit::SetLabel(const string& Label) { - mLabel = pLabel; + mLabel = Label; } -void JZArrayEdit::SetYMinMax(int mi, int ma) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZArrayEdit::SetYMinMax(int YMin, int YMax) { - mArray.SetMinMax(mi, ma); - ynul = y + h - h * (nul - min) / (max - min); + mArray.SetMinMax(YMin, YMax); + mYNull = mY + mHeight - mHeight * (mNull - mMin) / (mMax - mMin); } -void JZArrayEdit::DrawBarLine(wxDC& Dc, int xx) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZArrayEdit::DrawBarLine(wxDC& Dc, int XPosition) { -// cerr << "x: " << x << " xx: " << xx << endl; - if (xx > x && xx + 1 < x + w) + if (XPosition > mX && XPosition + 1 < mX + mWidth) { Dc.SetPen(*wxLIGHT_GREY_PEN); - Dc.DrawLine(xx, y + 1, xx, y + h - 2); + Dc.DrawLine(XPosition, mY + 1, XPosition, mY + mHeight - 2); Dc.SetPen(*wxBLACK_PEN); } } - - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRhyArrayEdit::JZRhyArrayEdit( - wxFrame *parent, + wxFrame* pParent, JZRndArray& Array, const wxPoint& Position, const wxSize& Size, int StyleBits) - : JZArrayEdit(parent, Array, Position, Size, StyleBits) + : JZArrayEdit(pParent, Array, Position, Size, StyleBits), + mStepsPerCount(4), + mCountPerBar(4) { - steps_per_count = 4; - count_per_bar = 4; - n_bars = 4; } -void JZRhyArrayEdit::SetMeter(int s, int c, int b) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhyArrayEdit::SetMeter(int StepsPerCount, int CountPerBar, int BarCount) { - steps_per_count = s; - count_per_bar = c; - n_bars = b; - mArray.Resize(s * c * b); - SetXMinMax(1, s * c * b); + mStepsPerCount = StepsPerCount; + mCountPerBar = CountPerBar; + mArray.Resize(StepsPerCount * CountPerBar * BarCount); + SetXMinMax(1, StepsPerCount * CountPerBar * BarCount); } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhyArrayEdit::DrawXTicks(wxDC& Dc) { if (!(mStyleBits & ARED_RHYTHM)) @@ -811,23 +892,22 @@ return; } - char buf[20]; - int tw, th; + assert(mStepsPerCount && mCountPerBar); Dc.SetFont(*wxSMALL_FONT); // tick marks - assert(steps_per_count && count_per_bar && n_bars); - int i; - for (i = 0; i < n; i += steps_per_count) + int TextWidth, TextHeight; + for (int i = 0; i < mArray.Size(); i += mStepsPerCount) { - int mark = (i / steps_per_count) % count_per_bar + 1; - sprintf(buf, "%d", mark); - int yy = y + h; - int xx = (int)(x + (i + 0.5) * w / n); - Dc.GetTextExtent(buf, &tw, &th); - xx -= (int)(tw/2.0); - Dc.DrawText(buf, xx, yy); + int mark = (i / mStepsPerCount) % mCountPerBar + 1; + ostringstream Oss; + Oss << mark; + int YPosition = mY + mHeight; + int XPosition = (int)(mX + (i + 0.5) * mWidth / mArray.Size()); + Dc.GetTextExtent(Oss.str(), &TextWidth, &TextHeight); + XPosition -= (int)(TextWidth / 2.0); + Dc.DrawText(Oss.str(), XPosition, YPosition); } Dc.SetFont(*wxNORMAL_FONT); } Modified: trunk/jazz/src/Random.h =================================================================== --- trunk/jazz/src/Random.h 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/Random.h 2013-04-07 05:59:57 UTC (rev 1005) @@ -25,10 +25,12 @@ #include <wx/scrolwin.h> #include <iostream> +#include <vector> #include "DynamicArray.h" - +//***************************************************************************** +//***************************************************************************** class JZRandomGenerator { public: @@ -38,37 +40,31 @@ extern JZRandomGenerator rnd; -#undef min -#undef max - - -// array of probabilities - +//***************************************************************************** +// Description: +// Array of probabilities. +//***************************************************************************** class JZRndArray { friend class JZArrayEdit; - protected: + public: - JZIntArray mArray; - int n; // number of elements in array - int nul, min, max; + JZRndArray(int Size, int Min, int Max); + JZRndArray & operator = (const JZRndArray &); + JZRndArray(JZRndArray const &); - public: + virtual ~JZRndArray(); - int Null() + int GetNull() { - return nul; + return mNull; } - void SetNull(int n) + void SetNull(int Null) { - nul = n; + mNull = Null; } - JZRndArray(int n, int min, int max); - JZRndArray & operator = (const JZRndArray &); - JZRndArray(JZRndArray const &); - virtual ~JZRndArray(); int &operator[] (int i) { return mArray[i]; @@ -77,44 +73,41 @@ { return mArray[i]; } - /* PAT - The following ifdef was removed due to changes in gcc 3.x. If it - needs to be put back for compatibility purposes, it will need to return - in an alternate form. */ - /*#ifdef FOR_MSW*/ double operator[](double f); float operator[](float f) { - /*#else - double operator[](double f) const; - float operator[](float f) const - { - #endif*/ return (float)operator[]((double)f); } int Size() const { - return n; + return mArray.size(); } int Min() const { - return min; + return mMin; } int Max() const { - return max; + return mMax; } - void SetMinMax(int min, int max); + void SetMinMax(int Min, int Max); void Resize(int nn) { - n = nn; + mArray.resize(nn); } friend std::ostream & operator << (std::ostream &, JZRndArray const &); friend std::istream & operator >> (std::istream &, JZRndArray &); - int Random(); // returns index 0..n-1 (arrayvalues -> empiric distribution) - int Random(double rndval); // returns index 0..n-1 (arrayvalues -> empiric distribution) - int Random(int i); // return 0/1 + // Returns index 0..n-1 (arrayvalues -> empiric distribution) + int Random(); + + // returns index 0..n-1 (arrayvalues -> empiric distribution) + int Random(double rndval); + + // return 0/1 + int Random(int i); + int Interval(int seed); void SetUnion(JZRndArray &o, int fuzz); @@ -123,9 +116,15 @@ void SetInverse(int fuzz); int Fuzz(int fuzz, int v1, int v2) const; void Clear(); + + protected: + + std::vector<int> mArray; + int mNull, mMin, mMax; }; - +//***************************************************************************** +//***************************************************************************** #define ARED_GAP 1 #define ARED_XTICKS 2 #define ARED_YTICKS 4 @@ -134,7 +133,8 @@ #define ARED_BLOCKS 32 #define ARED_LINES 64 - +//***************************************************************************** +//***************************************************************************** class JZArrayEditDrawBars { public: @@ -146,38 +146,10 @@ virtual void DrawBars(wxDC& Dc) = 0; }; - +//***************************************************************************** +//***************************************************************************** class JZArrayEdit : public wxScrolledWindow { - protected: - - // paint position - int x, y, w, h, ynul; - void DrawBar(wxDC& Dc, int i, int black); - - int dragging; // Dragging-Event valid - int index; // ctrl down: drag this one - - JZRndArray& mArray; - int &n, &min, &max, &nul; // shorthand for mArray.n, mArray.min, ... - wxString mLabel; - JZArrayEditDrawBars *draw_bars; - - // array size is mapped to this range for x-tick marks - int xmin, xmax; - - virtual void DrawXTicks(wxDC& Dc); - virtual void DrawYTicks(wxDC& Dc); - virtual void DrawLabel(wxDC& Dc); - virtual void DrawNull(wxDC& Dc); - int Index(wxMouseEvent& MouseEvent); - - int enabled; - int mStyleBits; - - virtual const char *GetXText(int xval); // Text for x-tickmarks - virtual const char *GetYText(int yval); // Text for y-tickmarks - public: JZArrayEdit( @@ -196,42 +168,88 @@ virtual int ButtonDown(wxMouseEvent& MouseEvent); virtual int ButtonUp(wxMouseEvent& MouseEvent); - virtual void SetLabel(char const *llabel); - void Enable(int enable = 1); + virtual void SetLabel(const std::string& Label); + + void SetEnabled(bool Enabled = true); + void SetStyle(int StyleBits) { mStyleBits = StyleBits; } - // min and max value in array (both values inclusive) - void SetYMinMax(int min, int max); - // for display x-axis only, does not resize the array (both values inclusive) - void SetXMinMax(int xmin, int xmax); - void DrawBarLine (wxDC& Dc, int xx); - void SetDrawBars(JZArrayEditDrawBars *x) + + // Minimum and maximum value in array (both values inclusive) + void SetYMinMax(int Min, int Max); + + // For display x-axis only, does not resize the array (both values inclusive) + void SetXMinMax(int XMin, int XMax); + + void DrawBarLine(wxDC& Dc, int xx); + void SetDrawBars(JZArrayEditDrawBars* pDrawBars) { - draw_bars = x; + mpDrawBars = pDrawBars; } + void Init() { } + protected: + + void DrawBar(wxDC& Dc, int i, int black); + + virtual void DrawXTicks(wxDC& Dc); + virtual void DrawYTicks(wxDC& Dc); + virtual void DrawLabel(wxDC& Dc); + virtual void DrawNull(wxDC& Dc); + int GetIndex(wxMouseEvent& MouseEvent); + + virtual std::string GetXText(int XValue); // Text for x-tickmarks + virtual std::string GetYText(int YValue); // Text for y-tickmarks + + protected: + + JZRndArray& mArray; + + // Shorthand for mArray.mMin, mArray.mMax, ... + int& mMin; + int& mMax; + int& mNull; + + std::string mLabel; + JZArrayEditDrawBars* mpDrawBars; + + // paint position + int mX, mY, mWidth, mHeight, mYNull; + + // Dragging flag. + bool mDragging; + + // If ctrl is pushed: drag this one. + int mIndex; + + // Array size is mapped to this range for x-tick marks. + int mXMin, mXMax; + + bool mEnabled; + int mStyleBits; + DECLARE_EVENT_TABLE() }; - - +//***************************************************************************** +//***************************************************************************** class JZRhyArrayEdit : public JZArrayEdit { public: JZRhyArrayEdit( - wxFrame *parent, + wxFrame* pParent, JZRndArray& Array, const wxPoint& Position, const wxSize& Size, - int StyleBits = (ARED_GAP | ARED_XTICKS | ARED_RHYTHM)); + int StyleBits = ARED_GAP | ARED_XTICKS | ARED_RHYTHM); - void SetMeter(int steps_per_count, int count_per_bar, int n_bars); + void SetMeter(int StepsPerCount, int CountPerBar, int BarCount); protected: @@ -239,7 +257,6 @@ private: - int steps_per_count; - int count_per_bar; - int n_bars; + int mStepsPerCount; + int mCountPerBar; }; Modified: trunk/jazz/src/Resources.h =================================================================== --- trunk/jazz/src/Resources.h 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/Resources.h 2013-04-07 05:59:57 UTC (rev 1005) @@ -149,3 +149,12 @@ // JZSamplesDialog resource IDs. #define IDC_BN_SD_FILE_SELECT_BROWSE (wxID_HIGHEST + 1240) + +// Rhythm window resource IDs. +#define IDC_SL_RHYTHM_STEPS_PER_COUNT (wxID_HIGHEST + 1250) +#define IDC_SL_RHYTHM_COUNTS_PER_BAR (wxID_HIGHEST + 1251) +#define IDC_SL_RHYTHM_BAR_COUNT (wxID_HIGHEST + 1252) +#define IDC_LB_RHYTHM_INSTRUMENTS (wxID_HIGHEST + 1253) +#define IDC_SL_RHYTHM_GROUP_CONTRIB (wxID_HIGHEST + 1254) +#define IDC_SL_RHYTHM_GROUP_LISTEN (wxID_HIGHEST + 1255) +#define IDC_CB_RHYTHM_RANDOMIZE (wxID_HIGHEST + 1258) Modified: trunk/jazz/src/Rhythm.cpp =================================================================== --- trunk/jazz/src/Rhythm.cpp 2013-04-06 17:42:24 UTC (rev 1004) +++ trunk/jazz/src/Rhythm.cpp 2013-04-07 05:59:57 UTC (rev 1005) @@ -45,9 +45,11 @@ #include <wx/menu.h> #include <wx/msgdlg.h> #include <wx/slider.h> +#include <wx/stattext.h> #include <wx/toolbar.h> #include <fstream> +#include <iostream> #include <sstream> using namespace std; @@ -61,247 +63,286 @@ #include "Bitmaps/rrggen.xpm" #include "Bitmaps/help.xpm" -void tRhyGroup::write(ostream& Os) const +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZRhythmGroup::JZRhythmGroup() + : mListen(0), + mContrib(0) { - Os << listen << ' '; - Os << contrib << ' '; } -void tRhyGroup::read(istream& Is, int version) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythmGroup::Write(ostream& Os) const { - Is >> listen; - Is >> contrib; + Os << mListen << ' '; + Os << mContrib << ' '; } -void JZRhythmGroups::write(ostream& Os) const +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythmGroup::Read(istream& Is, int Version) { + Is >> mListen; + Is >> mContrib; +} + +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythmGroups::Write(ostream& Os) const +{ for (int i = 0; i < MAX_GROUPS; i++) { - g[i].write(Os); + mRhythmGroups[i].Write(Os); } Os << endl; } -void JZRhythmGroups::read(istream& Is, int version) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythmGroups::Read(istream& Is, int Version) { for (int i = 0; i < MAX_GROUPS; i++) { - g[i].read(Is, version); + mRhythmGroups[i].Read(Is, Version); } } - - // pseudo key nr's for harmony browser and sound effects static const int MODE_ALL_OF = -1; static const int MODE_ONE_OF = -2; static const int MODE_PIANO = -3; static const int MODE_CONTROL = -4; - -JZRhythm::JZRhythm(int k) +//***************************************************************************** +//***************************************************************************** +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +JZRhythm::JZRhythm(int Key) : mLabel("random rhythm"), - rhythm(64, 0, 100), - length( 8, 0, 100), - veloc (32, 0, 100), - history(64, 0, 100) + mRhythmArray(64, 0, 100), + mLengthArray(8, 0, 100), + mVelocityArray(32, 0, 100), + mStepsPerCount(4), + mCountPerBar(4), + mBarCount(1), + mKeyCount(1), + mMode(MODE_ALL_OF), + mParameter(0), + mRandomizeFlag(true), + mRhythmGroups(), + mHistoryArray(64, 0, 100), + mStartClock(0), + mNextClock(0) { - mode = MODE_ALL_OF; - n_keys = 1; - keys[0] = k; - parm = 0; - steps_per_count = 4; - count_per_bar = 4; - n_bars = 1; - randomize = true; + mKeys[0] = Key; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRhythm::JZRhythm(const JZRhythm& Other) - : rhythm(Other.rhythm), - length(Other.length), - veloc (Other.veloc), - groups(Other.groups), - history(Other.history) + : mLabel(Other.mLabel), + mRhythmArray(Other.mRhythmArray), + mLengthArray(Other.mLengthArray), + mVelocityArray(Other.mVelocityArray), + mStepsPerCount(Other.mStepsPerCount), + mCountPerBar(Other.mCountPerBar), + mBarCount(Other.mBarCount), + mKeyCount(Other.mKeyCount), + mMode(Other.mMode), + mParameter(Other.mParameter), + mRandomizeFlag(Other.mRandomizeFlag), + mRhythmGroups(Other.mRhythmGroups), + mHistoryArray(Other.mHistoryArray), + mStartClock(Other.mStartClock), + mNextClock(Other.mNextClock) { - mode = Other.mode; - n_keys = Other.n_keys; - for (int i = 0; i < n_keys; i++) + for (int i = 0; i < mKeyCount; i++) { - keys[i] = Other.keys[i]; + mKeys[i] = Other.mKeys[i]; } - parm = Other.parm; - n_bars = Other.n_bars; - steps_per_count = Other.steps_per_count; - count_per_bar = Other.count_per_bar; - randomize = Other.randomize; - groups = Other.groups; - - mLabel = Other.mLabel; } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRhythm& JZRhythm::operator = (const JZRhythm& Rhs) { if (this != &Rhs) { - mode = Rhs.mode; - n_keys = Rhs.n_keys; - for (int i = 0; i < n_keys; i++) + mLabel = Rhs.mLabel; + mRhythmArray = Rhs.mRhythmArray; + mLengthArray = Rhs.mLengthArray; + mVelocityArray = Rhs.mVelocityArray; + mStepsPerCount = Rhs.mStepsPerCount; + mCountPerBar = Rhs.mCountPerBar; + mBarCount = Rhs.mBarCount; + mKeyCount = Rhs.mKeyCount; + for (int i = 0; i < mKeyCount; ++i) { - keys[i] = Rhs.keys[i]; + mKeys[i] = Rhs.mKeys[i]; } - rhythm = Rhs.rhythm; - length = Rhs.length; - veloc = Rhs.veloc; - parm = Rhs.parm; - n_bars = Rhs.n_bars; - steps_per_count = Rhs.steps_per_count; - count_per_bar = Rhs.count_per_bar; - randomize = Rhs.randomize; - groups = Rhs.groups; - history = Rhs.history; - - mLabel = Rhs.mLabel; + mMode = Rhs.mMode; + mParameter = Rhs.mParameter; + mRandomizeFlag = Rhs.mRandomizeFlag; + mRhythmGroups = Rhs.mRhythmGroups; + mHistoryArray = Rhs.mHistoryArray; + mStartClock = Rhs.mStartClock; + mNextClock = Rhs.mNextClock; } return *this; } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- JZRhythm::~JZRhythm() { } - -void JZRhythm::write(ostream& Os) const +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythm::Write(ostream& Os) const { - Os << rhythm; - Os << length; - Os << veloc; + Os << mRhythmArray; + Os << mLengthArray; + Os << mVelocityArray; - Os << steps_per_count << ' '; - Os << count_per_bar << ' '; - Os << n_bars << ' '; - Os << mode << ' '; - Os << n_keys << ' '; - for (int i = 0; i < n_keys; i++) + Os << mStepsPerCount << ' '; + Os << mCountPerBar << ' '; + Os << mBarCount << ' '; + Os << mMode << ' '; + Os << mKeyCount << ' '; + for (int i = 0; i < mKeyCount; i++) { - Os << keys[i] << ' '; + Os << mKeys[i] << ' '; } - Os << parm << endl; + Os << mParameter << endl; WriteString(Os, mLabel.c_str()) << endl; - Os << randomize << ' '; - groups.write(Os); + Os << mRandomizeFlag << ' '; + mRhythmGroups.Write(Os); } - -void JZRhythm::read(istream& Is, int version) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythm::Read(istream& Is, int Version) { - Is >> rhythm; - Is >> length; - Is >> veloc; + Is >> mRhythmArray; + Is >> mLengthArray; + Is >> mVelocityArray; - Is >> steps_per_count; - Is >> count_per_bar; - Is >> n_bars; - Is >> mode; - if (mode >= 0) // old format + Is >> mStepsPerCount; + Is >> mCountPerBar; + Is >> mBarCount; + Is >> mMode; + if (mMode >= 0) // old format { - n_keys = 1; - keys[0] = mode; - mode = MODE_ALL_OF; + mKeyCount = 1; + mKeys[0] = mMode; + mMode = MODE_ALL_OF; } else { - Is >> n_keys; - for (int i = 0; i < n_keys; i++) + Is >> mKeyCount; + for (int i = 0; i < mKeyCount; i++) { - Is >> keys[i]; + Is >> mKeys[i]; } } - Is >> parm; + Is >> mParameter; string Label; ReadString(Is, Label); SetLabel(Label.c_str()); - if (version > 1) + if (Version > 1) { - Is >> randomize; - groups.read(Is, version); + Is >> mRandomizeFlag; + mRhythmGroups.Read(Is, Version); } } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythm::SetLabel(const string& Label) { mLabel = Label; } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRhythm::Clock2i(long clock, const JZBarInfo& BarInfo) const { - int clocks_per_step = BarInfo.GetTicksPerBar() / (steps_per_count * count_per_bar); - return (int)(((clock - start_clock) / clocks_per_step) % rhythm.Size()); + int clocks_per_step = BarInfo.GetTicksPerBar() / (mStepsPerCount * mCountPerBar); + return (int)(((clock - mStartClock) / clocks_per_step) % mRhythmArray.Size()); } +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int JZRhythm::ClocksPerStep(const JZBarInfo& BarInfo) const { - return BarInfo.GetTicksPerBar() / (steps_per_count * count_per_bar); + return BarInfo.GetTicksPerBar() / (mStepsPerCount * mCountPerBar); } - -void JZRhythm::GenInit(long frc) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void JZRhythm::GenInit(int StartClock) { int i; - start_clock = frc; - next_clock = frc; + mStartClock = StartClock; + mNextClock = StartClock; - int nn = rhythm.Size(); - history.Resize(nn); + int Size = mRhythmArray.Size(); + mHistoryArray.Resize(Size); - // initialize history with random values - for (i = 0; i < nn; i++) + // Initialize history with random values. + for (i = 0; i < Size; ++i) { - history[i] = history.Min(); + mHistoryArray[i] = mHistoryArray.Min(); } - for (i = 0; i < nn; i++) + for (i = 0; i < Size; i++) { - if (rhythm.Random(i)) + if (mRhythmArray.Random(i)) { - history[i] = history.Max(); - i += length.Random(); + mHistoryArray[i] = mHistoryArray.Max(); + i += mLengthArray.Random(); } } } - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythm::GenerateEvent(JZTrack* pTrack, long clock, short vel, short len) { int chan = pTrack->mChannel - 1; // generate key events - if (mode == MODE_ALL_OF) + if (mMode == MODE_ALL_OF) { - for (int ii = 0; ii < n_keys; ii++) + for (int ii = 0; ii < mKeyCount; ii++) { - JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, keys[ii], vel, len); + JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, mKeys[ii], vel, len); pTrack->Put(k); } } - else if (mode == MODE_ONE_OF) + else if (mMode == MODE_ONE_OF) { - int ii = (int)(rnd.asDouble() * n_keys); - if (ii < n_keys) + int ii = (int)(rnd.asDouble() * mKeyCount); + if (ii < mKeyCount) { - JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, keys[ii], vel, len); + JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, mKeys[ii], vel, len); pTrack->Put(k); } } - else if (mode == MODE_CONTROL) + else if (mMode == MODE_CONTROL) { // generate controller - JZControlEvent* c = new JZControlEvent(clock, chan, parm - 1, vel); + JZControlEvent* c = new JZControlEvent(clock, chan, mParameter - 1, vel); pTrack->Put(c); } else @@ -312,51 +353,51 @@ #if 0 -void JZRhythm::Generate(JZTrack* pTrack, long fr_clock, long to_clock, long ticks_per_bar) +void JZRhythm::Generate(JZTrack* pTrack, int FromClock, int ToClock, int TicksPerBar) { int chan = pTrack->Channel - 1; - long clock = fr_clock; + long clock = FromClock; - long clocks_per_step = ticks_per_bar / (steps_per_count * count_per_bar); - long total_steps = (to_clock - fr_clock) / clocks_per_step; + long clocks_per_step = TicksPerBar / (mStepsPerCount * mCountPerBar); + long total_steps = (ToClock - FromClock) / clocks_per_step; - while (clock < to_clock) + while (clock < ToClock) { - int i = ((clock - fr_clock) / clocks_per_step) % rhythm.Size(); - if (rhythm.Random(i)) + int i = ((clock - FromClock) / clocks_per_step) % mRhythmArray.Size(); + if (mRhythmArray.Random(i)) { // put event here int rndval; - if (randomize) + if (mRandomizeFlag) { // keep seed < 1.0 - rndval = veloc.Random((double)rhythm[i] / ((double)rhythm.Max() + 0.001)); + rndval = mVelocityArray.Random((double)mRhythmArray[i] / ((double)mRhythmArray.Max() + 0.001)); } else { - rndval = veloc.Random(); + rndval = mVelocityArray.Random(); } - short vel = rndval * 127 / veloc.Size() + 1; - short len = (length.Random() + 1) * clocks_per_step; + short vel = rndval * 127 / mVelocityArray.Size() + 1; + short len = (mLengthArray.Random() + 1) * clocks_per_step; // generate keys from harmony browser if (key == CHORD_KEY || key == BASS_KEY) { if (gpHarmonyBrowser) { - long step = (clock - fr_clock) * total_steps / (to_clock - fr_clock); - int keys[12], n_keys; + long step = (clock - FromClock) * total_steps / (ToClock - FromClock); + int Keys[12], KeyCount; if (key == CHORD_KEY) { - n_keys = gpHarmonyBrowser->GetChordKeys(keys, (int)step, (int)total_steps); + KeyCount = gpHarmonyBrowser->GetChordKeys(Keys, (int)step, (int)total_steps); } else { - n_keys = gpHarmonyBrowser->GetBassKeys(keys, (int)step, (int)total_steps); + mKeyCount = gpHarmonyBrowser->GetBassKeys(Keys, (int)step, (int)total_steps); } - for (int j = 0; j < n_keys; j++) + for (int j = 0; j < mKeyCount; j++) { - JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, keys[j], vel, len - clocks_per_step/2); + JZKeyOnEvent *k = new JZKeyOnEvent(clock, chan, Keys[j], vel, len - clocks_per_step/2); pTrack->Put(k); } } @@ -380,7 +421,7 @@ // generate controller else if (key == CONTROL_KEY) { - JZControlEvent* c = new JZControlEvent(clock, chan, parm - 1, vel); + JZControlEvent* c = new JZControlEvent(clock, chan, mParameter - 1, vel); pTrack->Put(c); } // generate note on events @@ -398,33 +439,33 @@ } #endif - - +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void JZRhythm::GenGroup( JZRndArray& out, int grp, const JZBarInfo& BarInfo, - JZRhythm *rhy[], - int n_rhy) + JZRhythm* rhy[], + int RhythmCount) { out.Clear(); int clocks_per_step = ClocksPerStep(BarInfo); - for (int ri = 0; ri < n_rhy; ri++) + for (int RhythmIndex = 0; RhythmIndex < RhythmCount; ++RhythmIndex) { - JZRhythm* pRhythm = rhy[ri]; - int fuzz = pRhythm->groups[grp].contrib; + JZRhythm* pRhythm = rhy[RhythmIndex]; + int fuzz = pRhythm->mRhythmGroups[grp].mContrib; if (fuzz && pRhythm != this) { - JZRndArray tmp(rhythm); + JZRndArray tmp(mRhythmArray); tmp.Clear(); long clock = BarInfo.GetClock(); ... [truncated message content] |