aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/engine/Evolver.cpp8
-rw-r--r--src/engine/Problem.cpp9
-rw-r--r--src/engine/machina/Problem.hpp3
3 files changed, 15 insertions, 5 deletions
diff --git a/src/engine/Evolver.cpp b/src/engine/Evolver.cpp
index 1d4decc..73ff12f 100644
--- a/src/engine/Evolver.cpp
+++ b/src/engine/Evolver.cpp
@@ -74,11 +74,13 @@ Evolver::_run()
while (true) {
_ga->iteration();
+ //cout << "I" << endl;
- if (_ga->best_fitness() > old_best) {
+ float new_best = _ga->best_fitness();
+ if (new_best > old_best) {
_improvement = true;
- old_best = _ga->best_fitness();
- cout << "NEW BEST: " << old_best << endl;
+ old_best = new_best;
+ cout << "NEW BEST: " << new_best << endl;
}
}
}
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index 654d0a3..6c6fdd3 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -41,6 +41,7 @@ Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
uint32_t ev_size;
uint32_t delta_time;
while (smf.read_event(4, buf, &ev_size, &delta_time) >= 0) {
+ _target._length += delta_time / (double)smf.ppqn();
if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
const uint8_t note = buf[1];
++_target._note_frequency[note];
@@ -48,6 +49,8 @@ Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
}
}
+ cout << "Target length: " << _target._length << endl;
+
_target.compute();
}
@@ -55,6 +58,8 @@ Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
float
Problem::fitness(const Machine& const_machine) const
{
+ //cout << "f";
+
// kluuudge
Machine& machine = const_cast<Machine&>(const_machine);
@@ -72,9 +77,11 @@ Problem::fitness(const Machine& const_machine) const
time.set_start(0);
time.set_length(2*ppqn);
- while (time.start_ticks() < _target._n_notes * ppqn) {
+ while (eval->_n_notes < _target._n_notes) {
machine.run(time);
time.set_start(time.start_ticks() + 2*ppqn);
+ if (time.start_beats() >= _target._length)
+ break;
}
eval->compute();
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp
index abfc534..96ecb39 100644
--- a/src/engine/machina/Problem.hpp
+++ b/src/engine/machina/Problem.hpp
@@ -40,7 +40,7 @@ public:
private:
struct Evaluator : public Raul::MIDISink {
- Evaluator(const Problem& problem) : _problem(problem), _n_notes(0) {
+ Evaluator(const Problem& problem) : _problem(problem), _n_notes(0), _length(0) {
for (uint8_t i=0; i < 128; ++i)
_note_frequency[i] = 0;
}
@@ -52,6 +52,7 @@ private:
float _note_frequency[128];
size_t _n_notes;
+ double _length;
};
Evaluator _target;