/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 1997--2012 Jan Nieuwenhuizen <janneke@gnu.org>
+ Copyright (C) 1997--2014 Jan Nieuwenhuizen <janneke@gnu.org>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "duration.hh"
#include "international.hh"
+#include "libc-extension.hh"
#include "main.hh"
#include "midi-stream.hh"
#include "misc.hh"
Midi_note::Midi_note (Audio_note *a)
: Midi_channel_item (a),
audio_ (a),
- dynamic_byte_ (a->dynamic_ && a->dynamic_->volume_ >= 0
- ? Byte (a->dynamic_->volume_ * 0x7f) : Byte (0x5a))
+ dynamic_byte_ (min (max (Byte ((a->dynamic_ && a->dynamic_->volume_ >= 0
+ ? a->dynamic_->volume_ * 0x7f : 0x5a)
+ + a->extra_velocity_),
+ Byte (0)), Byte (0x7f)))
{
}
static const Real full_fine_scale = 0x3FFF;
static const Real full_coarse_scale = 0x7F;
bool fine_resolution = (control_function->lsb_control_number_ >= 0);
- int value = lround (value_ * (fine_resolution ?
- full_fine_scale : full_coarse_scale));
+ // value_ is in range [0.0 .. 1.0]. For directional value ranges,
+ // #CENTER will correspond to 0.5 exactly, and my_round rounds
+ // upwards when in case of doubt. That means that center position
+ // will round to 0x40 or 0x2000 by a hair's breadth.
+ int value = (int) my_round (value_ * (fine_resolution ?
+ full_fine_scale : full_coarse_scale));
Byte status_byte = (char) (0xB0 + channel_);
str += ::to_string ((char)status_byte);
str += ::to_string ((char)(control_function->msb_control_number_));