1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: random.h,v 1.1.1.1 2003/10/29 10:06:15 wschweer Exp $
//
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
//
// This code is an adaption of the random rhythm generator taken
// from "The JAZZ++ Midi Sequencer"
// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all
// rights reserved.
// Distributed under the GNU General Public License
//=========================================================
#if 0
#ifndef random_h
#define random_h
#ifndef wx_wxh
#include "wx.h"
#endif
#ifndef _FSTREAM_H
#include <fstream.h>
#endif
#ifndef dynarray_h
#include "dynarray.h"
#endif
// gcc > 2.7.2 does not have ACG anymore?
#define USE_ACG 0
#if USE_ACG
#include <ACG.h> // random generator from libg++
extern ACG rnd;
#else
class tRandomGenerator
{
public:
double asDouble();
};
extern tRandomGenerator rnd;
#endif
#undef min
#undef max
// array of probabilities
class tRndArray
{
friend class tArrayEdit;
protected:
tIntArray array;
int n; // number of elements in array
int nul, min, max;
public:
int Null() { return nul; }
void SetNull(int n) { nul = n; }
tRndArray(int n, int min, int max);
tRndArray & operator = (const tRndArray &);
tRndArray(tRndArray const &);
virtual ~tRndArray();
int &operator[] (int i) { return array[i]; }
int operator[] (int i) const { return array[i]; }
#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; }
int Min() const { return min; }
int Max() const { return max; }
void SetMinMax(int min, int max);
void Resize(int nn) { n = nn; }
friend ostream & operator << (ostream &, tRndArray const &);
friend istream & operator >> (istream &, tRndArray &);
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
int Interval(int seed);
void SetUnion(tRndArray &o, int fuzz);
void SetDifference(tRndArray &o, int fuzz);
void SetIntersection(tRndArray &o, int fuzz);
void SetInverse(int fuzz);
int Fuzz(int fuzz, int v1, int v2) const;
void Clear();
};
#define ARED_GAP 1
#define ARED_XTICKS 2
#define ARED_YTICKS 4
#define ARED_MINMAX 8
#define ARED_RHYTHM 16
#define ARED_BLOCKS 32
#define ARED_LINES 64
class tArrayEditDrawBars {
public:
virtual void DrawBars() = 0;
};
class tArrayEdit : public wxCanvas
{
protected:
// paint position
long x, y, w, h, ynul;
void DrawBar(int i, int black);
int dragging; // Dragging-Event valid
int index; // ctrl down: drag this one
tRndArray &array;
int &n, &min, &max, &nul; // shorthand for array.n, array.min, ...
char *label;
tArrayEditDrawBars *draw_bars;
// array size is mapped to this range for x-tick marks
int xmin, xmax;
virtual void DrawXTicks();
virtual void DrawYTicks();
virtual void DrawLabel();
virtual void DrawNull();
int Index(wxMouseEvent &e);
int enabled;
int style_bits;
virtual const char *GetXText(int xval); // Text for x-tickmarks
virtual const char *GetYText(int yval); // Text for y-tickmarks
public:
tArrayEdit(wxFrame *parent, tRndArray &array, long xx, long yy, long ww, long hh, int style_bits = (ARED_GAP | ARED_XTICKS));
virtual ~tArrayEdit();
virtual void OnPaint();
virtual void OnSize(int ww, int hh);
virtual void OnEvent(wxMouseEvent &e);
virtual int Dragging(wxMouseEvent &);
virtual int ButtonDown(wxMouseEvent &);
virtual int ButtonUp(wxMouseEvent &);
virtual void SetLabel(char const *llabel);
void Enable(int enable = 1);
void SetStyle(int style) { style_bits = style; }
// 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 (long xx);
void SetDrawBars(tArrayEditDrawBars *x) { draw_bars = x; }
void Init() {}
};
class tRhyArrayEdit : public tArrayEdit
{
int steps_per_count;
int count_per_bar;
int n_bars;
protected:
virtual void DrawXTicks();
public:
tRhyArrayEdit(wxFrame *parent, tRndArray &array, long xx, long yy, long ww, long hh, int style_bits = (ARED_GAP | ARED_XTICKS | ARED_RHYTHM));
void SetMeter(int steps_per_count, int count_per_bar, int n_bars);
};
#endif
#endif
|