Rev 1574 |
Rev 1615 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* drone.h
* DIN Is Noise is copyright (c) 2006-2020 Jagannathan Sampath
* For more information, please visit https://dinisnoise.org/
*/
#ifndef __drone__
#define __drone__
#include "fader.h"
#include "solver.h"
#include "play.h"
#include "trail.h"
#include "alarm.h"
#include "modulator.h"
#include "noiser.h"
#include "container.h"
#include <string>
#include <map>
#include <ostream>
extern int DRONE_HANDLE_SIZE;
extern int TRAIL_LENGTH;
extern int BOTTOM;
extern float DELTA_VOLUME;
extern float ARROW_U, ARROW_V;
struct din;
struct drone;
typedef std::list<drone*>::iterator drone_iterator;
struct attractee {
int id;
drone* d;
attractee (int _id = -1, drone* _d = 0) {id = _id; d = _d;}
bool operator== (const attractee& ae) {return (d == ae.d);}
};
struct drone {
static float mastervolume;
static int UID; // unique drone id
int id; // id of this drone
play player; // player for this drone
solver sol; // solver for this drone
float step; // determines pitch (see note.h)
float vol; // actual volume
int range; // range number on microtonal-keyboard
float pos; // position in range (0 - left, 1 - right, can go < 0 & > 1 too)
int sel; // selected?
// visual
//
float cx, cy; // unmodulated position
float x, y; // current position
float sx; // snapped x (used for note snap)
int snap; // snap to range edge?
int dy; // height from microtonal-keyboard bottom
float mx, my; // sampled position when modulation afx velocity vector
float xv, yv; // position of velocity vector tip
float xa, ya; // position of acceleration vector tip
float r, g, b; // color
void setcolor ();
trail_t trail; // trail points
box<int> handle; // for picking
int handle_size;
struct arrowt {
float u, v;
arrowt () { reset (); }
void reset () {u = ARROW_U; v = ARROW_V; }
} arrow;
void calc_handle ();
static float stiff;
int conn;
std::list<drone*> connections;
std::list<double> mags;
enum {LINK=0, CHAIN=1};
int type;
drone* eval_conns ();
// states
enum {DEAD=0, RISING, FALLING, ACTIVE};
int state; // current
int frozen; // frozen?
double froze_at; // time when frozen
int freeze ();
int thaw ();
void handle_time_pass ();
fader fdr; // for rising/falling -> fade in/out
fader gab; // for mute/unmute, drone <> noise
float tovol;
static double gabt;
modulator mod; // modulation
// orbitals & rocketry
//
int attractor; // attractor?
int orbiting; // orbiting?
std::list<attractee> attractees; // list of drones attracted by this drone
static float V0; // initial speed
float V; // speed
float vx0, vy0; // initial velocity vector
void initv (float y);
float vx, vy; // current velocity vector
float v_mult; // multiplier for velocity vector used in orbit insertion
void resetv ();
float A; // acceleration
float ax, ay; // acceleration unit vector
float xi, yi; // interim position
double insert; // time to insert into orbit
int gravity; // accelerated by gravity?
int bounces; // number of bounces from bottom of microtonal-keyboard
int launcher; // launches drones?
alarm_t launch_every; // alarm time in seconds
float dpm; // drones per minute
// for launched drone
static double LIFE_TIME, INSERT_TIME;
double birth; // time at birth
double life; // time until death
drone* launched_by;
// targets for launchers to launch drones to
std::vector<drone*> targets;
int cur_target;
int num_targets;
void clear_targets ();
drone* target;
enum {NONE, POINT, USE};
int tracking;
drone* tracked_drone; // the tracked drone
static int ref; // for debug
drone (float bottom = 0.0f);
~drone();
void set_pos (float x, float y);
void set_center (float _cx, float _cy);
void move_center ();
void setmodpos ();
void change_depth (int i, int what, float delta);
void change_bpm (int i, int what, float delta);
void change_bpm (mod_params& mp, float delta);
enum {UNSET=0, INTERPOLATE, EMPLACE};
int update_pv;
void update_pitch_volume ();
int is;
noiser nsr;
void setnoise ();
static std::map<drone*,bool> proc_conn;
// for drone <> noise conversions
struct fin {
virtual void finished (din& d, drone* pd) = 0;
} *finl;
static struct drone2noise : fin {
void finished (din& mkb, drone* pd);
} dnl;
static struct noise2drone : fin {
void finished (din& mkb, drone* pd);
} ndl;
static fin* fins [3]; // 0 = null, 1 = drone2noise, 2 = noise2drone, init @ main.cc
};
struct group {
int n;
std::vector<drone*> drones;
group () {n = 0;}
group (std::vector<drone*> mem, int n);
int member (drone* d) {
std::vector<drone*>::iterator db = drones.begin (), de = drones.end();
if (find (db, de, d) == de) return 0; else return 1;
}
int remove (drone* d) {
if (erase (drones, d)) {
--n;
return 1;
}
return 0;
}
};
struct drone_pendulum_group : group {
int orient;
int depth;
drone_pendulum_group (int o = 0, int d = 0) { orient = o; depth = d;}
drone_pendulum_group (int o, int d, std::vector<drone*> mem, int n) : group (mem, n), orient(o), depth(d) {}
};
std::ostream& operator<< (std::ostream& f, drone::arrowt& aw);
/*struct connect {
int dirty;
drone* d1;
drone* d2;
point<float> p1, p2;
double mag;
connect (drone* _d1, drone* _d2);
int eval (drone** ret);
void draw ();
void align_vel ();
};*/
#endif