~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to mplugins/random.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//  $Id: random.h,v 1.1 2002/02/27 11:52:59 muse Exp $
 
5
//
 
6
//  (C) Copyright 2001 Werner Schweer (ws@seh.de)
 
7
//
 
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 
 
11
//  rights reserved.
 
12
//  Distributed under the GNU General Public License
 
13
//=========================================================
 
14
 
 
15
#if 0
 
16
#ifndef random_h
 
17
#define random_h
 
18
 
 
19
#ifndef wx_wxh
 
20
#include "wx.h"
 
21
#endif
 
22
 
 
23
#ifndef _FSTREAM_H
 
24
#include <fstream.h>
 
25
#endif
 
26
 
 
27
#ifndef dynarray_h
 
28
#include "dynarray.h"
 
29
#endif
 
30
 
 
31
// gcc > 2.7.2 does not have ACG anymore?
 
32
#define USE_ACG 0
 
33
 
 
34
#if USE_ACG
 
35
#include <ACG.h>        // random generator from libg++
 
36
extern ACG rnd;
 
37
 
 
38
#else
 
39
 
 
40
class tRandomGenerator
 
41
{
 
42
  public:
 
43
    double asDouble();
 
44
};
 
45
extern tRandomGenerator rnd;
 
46
 
 
47
#endif
 
48
 
 
49
 
 
50
#undef min
 
51
#undef max
 
52
 
 
53
 
 
54
// array of probabilities
 
55
 
 
56
class tRndArray
 
57
{
 
58
  friend class tArrayEdit;
 
59
  protected:
 
60
    tIntArray array;
 
61
    int n;      // number of elements in array
 
62
    int nul, min, max;
 
63
 
 
64
  public:
 
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 &);
 
70
 
 
71
    virtual ~tRndArray();
 
72
    int &operator[] (int i)             { return array[i]; }
 
73
    int  operator[] (int i) const       { return array[i]; }
 
74
#ifdef FOR_MSW
 
75
    double operator[](double f);
 
76
    float operator[](float f) {
 
77
#else
 
78
    double operator[](double f) const;
 
79
    float operator[](float f) const {
 
80
#endif
 
81
      return (float)operator[]((double)f);
 
82
    }
 
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; }
 
88
 
 
89
    friend ostream & operator << (ostream &, tRndArray const &);
 
90
    friend istream & operator >> (istream &, tRndArray &);
 
91
 
 
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);
 
96
 
 
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;
 
102
    void Clear();
 
103
};
 
104
 
 
105
 
 
106
#define ARED_GAP        1
 
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
 
113
 
 
114
 
 
115
class tArrayEditDrawBars {
 
116
  public:
 
117
    virtual void DrawBars() = 0;
 
118
};
 
119
 
 
120
 
 
121
class tArrayEdit : public wxCanvas
 
122
{
 
123
protected:
 
124
  // paint position
 
125
  long x, y, w, h, ynul;
 
126
  void DrawBar(int i, int black);
 
127
 
 
128
  int dragging;         // Dragging-Event valid
 
129
  int index;            // ctrl down: drag this one
 
130
 
 
131
  tRndArray &array;
 
132
  int &n, &min, &max, &nul;     // shorthand for array.n, array.min, ...
 
133
  char *label;
 
134
  tArrayEditDrawBars *draw_bars;
 
135
 
 
136
  // array size is mapped to this range for x-tick marks
 
137
  int xmin, xmax;
 
138
 
 
139
  virtual void DrawXTicks();
 
140
  virtual void DrawYTicks();
 
141
  virtual void DrawLabel();
 
142
  virtual void DrawNull();
 
143
  int  Index(wxMouseEvent &e);
 
144
 
 
145
  int  enabled;
 
146
  int  style_bits;
 
147
 
 
148
  virtual const char *GetXText(int xval);  // Text for x-tickmarks
 
149
  virtual const char *GetYText(int yval);  // Text for y-tickmarks
 
150
 
 
151
 
 
152
public:
 
153
  tArrayEdit(wxFrame *parent, tRndArray &array, long xx, long yy, long ww, long hh, int style_bits = (ARED_GAP | ARED_XTICKS));
 
154
  virtual ~tArrayEdit();
 
155
 
 
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 &);
 
162
 
 
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; }
 
172
  void Init() {}
 
173
};
 
174
 
 
175
 
 
176
 
 
177
class tRhyArrayEdit : public tArrayEdit
 
178
{
 
179
    int steps_per_count;
 
180
    int count_per_bar;
 
181
    int n_bars;
 
182
  protected:
 
183
    virtual void DrawXTicks();
 
184
  public:
 
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);
 
187
};
 
188
 
 
189
 
 
190
#endif
 
191
#endif
 
192