1
//=========================================================
4
// $Id: random.h,v 1.1 2002/02/27 11:52:59 muse Exp $
6
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
8
// This code is an adaption of the random rhythm generator taken
9
// from "The JAZZ++ Midi Sequencer"
10
// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all
12
// Distributed under the GNU General Public License
13
//=========================================================
31
// gcc > 2.7.2 does not have ACG anymore?
35
#include <ACG.h> // random generator from libg++
40
class tRandomGenerator
45
extern tRandomGenerator rnd;
54
// array of probabilities
58
friend class tArrayEdit;
61
int n; // number of elements in array
65
int Null() { return nul; }
66
void SetNull(int n) { nul = n; }
67
tRndArray(int n, int min, int max);
68
tRndArray & operator = (const tRndArray &);
69
tRndArray(tRndArray const &);
72
int &operator[] (int i) { return array[i]; }
73
int operator[] (int i) const { return array[i]; }
75
double operator[](double f);
76
float operator[](float f) {
78
double operator[](double f) const;
79
float operator[](float f) const {
81
return (float)operator[]((double)f);
83
int Size() const { return n; }
84
int Min() const { return min; }
85
int Max() const { return max; }
86
void SetMinMax(int min, int max);
87
void Resize(int nn) { n = nn; }
89
friend ostream & operator << (ostream &, tRndArray const &);
90
friend istream & operator >> (istream &, tRndArray &);
92
int Random(); // returns index 0..n-1 (arrayvalues -> empiric distribution)
93
int Random(double rndval); // returns index 0..n-1 (arrayvalues -> empiric distribution)
94
int Random(int i); // return 0/1
95
int Interval(int seed);
97
void SetUnion(tRndArray &o, int fuzz);
98
void SetDifference(tRndArray &o, int fuzz);
99
void SetIntersection(tRndArray &o, int fuzz);
100
void SetInverse(int fuzz);
101
int Fuzz(int fuzz, int v1, int v2) const;
107
#define ARED_XTICKS 2
108
#define ARED_YTICKS 4
109
#define ARED_MINMAX 8
110
#define ARED_RHYTHM 16
111
#define ARED_BLOCKS 32
112
#define ARED_LINES 64
115
class tArrayEditDrawBars {
117
virtual void DrawBars() = 0;
121
class tArrayEdit : public wxCanvas
125
long x, y, w, h, ynul;
126
void DrawBar(int i, int black);
128
int dragging; // Dragging-Event valid
129
int index; // ctrl down: drag this one
132
int &n, &min, &max, &nul; // shorthand for array.n, array.min, ...
134
tArrayEditDrawBars *draw_bars;
136
// array size is mapped to this range for x-tick marks
139
virtual void DrawXTicks();
140
virtual void DrawYTicks();
141
virtual void DrawLabel();
142
virtual void DrawNull();
143
int Index(wxMouseEvent &e);
148
virtual const char *GetXText(int xval); // Text for x-tickmarks
149
virtual const char *GetYText(int yval); // Text for y-tickmarks
153
tArrayEdit(wxFrame *parent, tRndArray &array, long xx, long yy, long ww, long hh, int style_bits = (ARED_GAP | ARED_XTICKS));
154
virtual ~tArrayEdit();
156
virtual void OnPaint();
157
virtual void OnSize(int ww, int hh);
158
virtual void OnEvent(wxMouseEvent &e);
159
virtual int Dragging(wxMouseEvent &);
160
virtual int ButtonDown(wxMouseEvent &);
161
virtual int ButtonUp(wxMouseEvent &);
163
virtual void SetLabel(char const *llabel);
164
void Enable(int enable = 1);
165
void SetStyle(int style) { style_bits = style; }
166
// min and max value in array (both values inclusive)
167
void SetYMinMax(int min, int max);
168
// for display x-axis only, does not resize the array (both values inclusive)
169
void SetXMinMax(int xmin, int xmax);
170
void DrawBarLine (long xx);
171
void SetDrawBars(tArrayEditDrawBars *x) { draw_bars = x; }
177
class tRhyArrayEdit : public tArrayEdit
183
virtual void DrawXTicks();
185
tRhyArrayEdit(wxFrame *parent, tRndArray &array, long xx, long yy, long ww, long hh, int style_bits = (ARED_GAP | ARED_XTICKS | ARED_RHYTHM));
186
void SetMeter(int steps_per_count, int count_per_bar, int n_bars);