diff options
-rw-r--r-- | src/engine/LearnRequest.cpp | 3 | ||||
-rw-r--r-- | src/engine/Loader.cpp | 4 | ||||
-rw-r--r-- | src/engine/Machine.cpp | 4 | ||||
-rw-r--r-- | src/engine/MachineBuilder.cpp | 12 | ||||
-rw-r--r-- | src/engine/MidiAction.cpp | 2 | ||||
-rw-r--r-- | src/engine/Node.cpp | 5 | ||||
-rw-r--r-- | src/engine/Problem.cpp | 2 | ||||
-rw-r--r-- | src/engine/SMFDriver.cpp | 24 | ||||
-rw-r--r-- | src/engine/SMFReader.cpp | 4 | ||||
-rw-r--r-- | src/engine/SMFWriter.cpp | 2 | ||||
-rw-r--r-- | src/gui/NodePropertiesWindow.cpp | 4 |
11 files changed, 35 insertions, 31 deletions
diff --git a/src/engine/LearnRequest.cpp b/src/engine/LearnRequest.cpp index eabf568..81ef0e3 100644 --- a/src/engine/LearnRequest.cpp +++ b/src/engine/LearnRequest.cpp @@ -55,8 +55,7 @@ LearnRequest::finish(TimeStamp time) _node->set_enter_action(_enter_action); _node->set_exit_action(_exit_action); - //TimeDuration duration = quantize(_quantization, time - _start_time); - //_node->set_duration(duration); + _node->set_duration(time - _start_time); } } diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp index 1a85e29..32e8d19 100644 --- a/src/engine/Loader.cpp +++ b/src/engine/Loader.cpp @@ -178,7 +178,7 @@ Loader::load(const Glib::ustring& uri) Created::iterator tail_i = created.find(tail); Created::iterator head_i = created.find(head); - if (( tail_i != created.end()) && ( head_i != created.end()) ) { + if (tail_i != created.end() && head_i != created.end()) { const SharedPtr<Node> tail = tail_i->second; const SharedPtr<Node> head = head_i->second; @@ -193,7 +193,7 @@ Loader::load(const Glib::ustring& uri) } - if (machine && ( machine->nodes().size() > 0) ) { + if (machine && machine->nodes().size() > 0) { machine->reset(NULL, machine->time()); return machine; } else { diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index 0792331..4b548a7 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -275,8 +275,8 @@ Machine::exit_node(Context& context, s != node->edges().end(); ++s) { if (!(*s)->head()->is_active() - && ( rand_normal > range_min) - && ( rand_normal < range_min + (*s)->probability()) ) { + && rand_normal > range_min + && rand_normal < range_min + (*s)->probability()) { enter_node(context, (*s)->head(), updates); break; diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp index 8bdd5d4..bb8f7c2 100644 --- a/src/engine/MachineBuilder.cpp +++ b/src/engine/MachineBuilder.cpp @@ -73,7 +73,7 @@ MachineBuilder::set_node_duration(SharedPtr<Node> node, Raul::TimeStamp q_dur = quantize(TimeStamp(d.unit(), _quantization), d); // Never quantize a note to duration 0 - if (q_dur.is_zero() && ( node->enter_action() || node->exit_action() )) { + if (q_dur.is_zero() && (node->enter_action() || node->exit_action())) { q_dur = _quantization; // Round up } node->set_duration(q_dur); @@ -223,9 +223,9 @@ MachineBuilder::event(Raul::TimeStamp time_offset, // Trim useless delay node if possible (these appear after poly sections) if (is_delay_node(_connect_node) && _connect_node->duration().is_zero() - && ( _connect_node->edges().size() == 1) - && ( (*_connect_node->edges().begin())->head() == - resolved) ) { + && (_connect_node->edges().size() == 1) + && ((*_connect_node->edges().begin())->head() == + resolved)) { _connect_node->edges().clear(); assert(_connect_node->edges().empty()); @@ -290,8 +290,8 @@ MachineBuilder::resolve() const size_t ev_size = action->event_size(); const unsigned char* ev = action->event(); - if (( ev_size == 3) - && ( (ev[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON) ) { + if (ev_size == 3 && + (ev[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON) { unsigned char note_off[3] = { ((LV2_MIDI_MSG_NOTE_OFF & 0xF0) | (ev[0] & 0x0F)), ev[1], diff --git a/src/engine/MidiAction.cpp b/src/engine/MidiAction.cpp index a646f67..268279f 100644 --- a/src/engine/MidiAction.cpp +++ b/src/engine/MidiAction.cpp @@ -62,7 +62,7 @@ MidiAction::set_event(size_t size, const byte* new_event) byte* const event = _event.load(); if (size <= _max_size) { _event = NULL; - if (( size > 0) && new_event) { + if (size > 0 && new_event) { memcpy(event, new_event, size); } _size = size; diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp index c0e4654..4de00d2 100644 --- a/src/engine/Node.cpp +++ b/src/engine/Node.cpp @@ -42,9 +42,8 @@ Node::Node(TimeDuration duration, bool initial) {} Node::Node(const Node& copy) - : Stateful() - , // don't copy RDF ID - _enter_time(copy._enter_time) + : Stateful() // don't copy RDF ID + , _enter_time(copy._enter_time) , _duration(copy._duration) , _enter_action(ActionFactory::copy(copy._enter_action)) , _exit_action(ActionFactory::copy(copy._exit_action)) diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp index 5c5992d..2db4f45 100644 --- a/src/engine/Problem.cpp +++ b/src/engine/Problem.cpp @@ -357,7 +357,7 @@ Problem::distance(const std::vector<uint8_t>& source, // Enhanced Dynamic Programming ASM Algorithm" // (http://www.acm.org/~hlb/publications/asm/asm.html) - if (( i > 2) && ( j > 2) ) { + if (i > 2 && j > 2) { uint16_t trans = _matrix[i - 2][j - 2] + 1; if (source[i - 2] != t_j) { trans++; diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index a07f47d..da7fecb 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -55,7 +55,7 @@ SMFDriver::learn(const string& filename, unsigned track, double q, //assert(q.unit() == max_duration.unit()); SharedPtr<Machine> m(new Machine(max_duration.unit())); SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>( - new MachineBuilder(m, q, false)); + new MachineBuilder(m, q, false)); SMFReader reader; if (!reader.open(filename)) { @@ -87,7 +87,7 @@ SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration) { SharedPtr<Machine> m(new Machine(max_duration.unit())); SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>( - new MachineBuilder(m, q, false)); + new MachineBuilder(m, q, false)); SMFReader reader; if (!reader.open(filename)) { @@ -125,16 +125,22 @@ SMFDriver::learn_track(SharedPtr<MachineBuilder> builder, uint32_t ev_size; uint32_t ev_delta_time; - uint64_t t = 0; - double unquantized_t = 0; + Raul::TimeUnit unit = Raul::TimeUnit(TimeUnit::BEATS, MACHINA_PPQN); + + uint64_t t = 0; while (reader.read_event(4, buf, &ev_size, &ev_delta_time) >= 0) { - unquantized_t += ev_delta_time; - t = quantize(q, unquantized_t); + t += ev_delta_time; + + const uint32_t beats = t / (uint32_t)reader.ppqn(); + const uint32_t smf_ticks = t % (uint32_t)reader.ppqn(); + const double frac = smf_ticks / (double)reader.ppqn(); + const uint32_t ticks = frac * MACHINA_PPQN; - builder->set_time(TimeStamp(max_duration.unit(), (double)t)); + // TODO: quantize + builder->set_time(TimeStamp(unit, beats, ticks)); - if ((!max_duration.is_zero()) && ( t > max_duration.to_double()) ) { + if (!max_duration.is_zero() && t > max_duration.to_double()) { break; } @@ -151,7 +157,7 @@ SMFDriver::run(SharedPtr<Machine> machine, Raul::TimeStamp max_time) { // FIXME: unit kludge (tempo only) Context context(_forge, machine->time().unit().ppt(), - _writer->unit().ppt(), 120.0); + _writer->unit().ppt(), 120.0); context.set_sink(this); context.time().set_slice(TimeStamp(max_time.unit(), 0, 0), context.time().beats_to_ticks(max_time)); diff --git a/src/engine/SMFReader.cpp b/src/engine/SMFReader.cpp index 62cdd26..d482eb5 100644 --- a/src/engine/SMFReader.cpp +++ b/src/engine/SMFReader.cpp @@ -184,7 +184,7 @@ SMFReader::seek_to_track(unsigned track) throw (std::logic_error) fseek(_fd, chunk_size, SEEK_CUR); } - if (!feof(_fd) && ( track_pos == track) ) { + if (!feof(_fd) && track_pos == track) { _track = track; _track_size = chunk_size; return true; @@ -310,7 +310,7 @@ SMFReader::read_var_len(FILE* fd) throw (PrematureEOF) uint32_t value; uint8_t c; - if ( (value = getc(fd)) & 0x80) { + if ((value = getc(fd)) & 0x80) { value &= 0x7F; do { if (feof(fd)) { diff --git a/src/engine/SMFWriter.cpp b/src/engine/SMFWriter.cpp index 41abfe0..388aa1f 100644 --- a/src/engine/SMFWriter.cpp +++ b/src/engine/SMFWriter.cpp @@ -221,7 +221,7 @@ SMFWriter::write_var_len(uint32_t value) uint32_t buffer = value & 0x7F; - while ( (value >>= 7) ) { + while ((value >>= 7)) { buffer <<= 8; buffer |= ((value & 0x7F) | 0x80); } diff --git a/src/gui/NodePropertiesWindow.cpp b/src/gui/NodePropertiesWindow.cpp index 52ad5af..9a76420 100644 --- a/src/gui/NodePropertiesWindow.cpp +++ b/src/gui/NodePropertiesWindow.cpp @@ -89,7 +89,7 @@ void NodePropertiesWindow::set_node(SharedPtr<Machina::Client::ClientObject> node) { _node = node; -#if 0 + #if 0 SharedPtr<MidiAction> enter_action = PtrCast<MidiAction>(node->enter_action()); if (enter_action && ( enter_action->event_size() > 1) && ( (enter_action->event()[0] & 0xF0) == 0x90) ) { @@ -102,7 +102,7 @@ NodePropertiesWindow::set_node(SharedPtr<Machina::Client::ClientObject> node) _note_spinbutton->hide(); } _duration_spinbutton->set_value(node->duration().to_double()); -#endif + #endif } void |