}
-Audio_key::Audio_key () // Key_def const& k)
+Audio_key::Audio_key (int acc, bool major)
{
- //fixme.
+ accidentals_=acc;
+ major_=major;
}
Audio_dynamic::Audio_dynamic (Real volume)
class Audio_key : public Audio_item
{
public:
- Audio_key (); //Newkey_def const& key);
- // FIXME
+ Audio_key (int acc, bool major);
+
+ int accidentals_;
+ bool major_;
};
class Audio_instrument : public Audio_item
virtual void announce_element (Audio_element_info);
protected:
Array<Audio_element_info> announce_info_arr_;
+ void create_audio_elements ();
private:
- void create_audio_elements ();
void acknowledge_audio_elements ();
};
(c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
*/
+#include "lily-guile.hh"
#include "command-request.hh"
#include "audio-item.hh"
#include "performer.hh"
void
Key_performer::create_audio_elements ()
{
- if (key_req_l_ &&
- gh_list_p (key_req_l_->get_mus_property ("pitch-alist")))
+ if (key_req_l_)
{
- audio_p_ = new Audio_key (); // *key_req_l_->key_);
+ SCM pitchlist = key_req_l_->get_mus_property ("pitch-alist");
+ SCM proc = scm_eval2 (ly_symbol2scm ("accidentals-in-key"), SCM_EOL);
+ SCM acc = gh_call1 (proc, pitchlist);
+ proc = scm_eval2 (ly_symbol2scm ("major-key"), SCM_EOL);
+ SCM major = gh_call1 (proc, pitchlist);
+ audio_p_ = new Audio_key (gh_scm2int(acc), major == SCM_BOOL_T);
Audio_element_info info (audio_p_, key_req_l_);
announce_element (info);
key_req_l_ = 0;
String
Midi_key::str () const
{
- // fxime.
- int sharps_i = 0; //audio_l_->key_.sharps_i ();
- int flats_i = 0; //audio_l_->key_.flats_i ();
-
- // midi cannot handle non-conventional keys
- if (flats_i && sharps_i)
- {
- String str = _f ("unconventional key: flats: %d, sharps: %d", flats_i,
- sharps_i);
- flats_i = sharps_i = 0;
- }
- int accidentals_i = sharps_i - flats_i;
-
String str = "ff5902";
- str += String_convert::i2hex_str (accidentals_i, 2, '0');
-
- // (int)audio_l_->key_.minor_b ()
- str += String_convert::i2hex_str (0, 2, '0');
+ str += String_convert::i2hex_str (audio_l_->accidentals_, 2, '0');
+ if (audio_l_->major_)
+ str += String_convert::i2hex_str (0, 2, '0');
+ else
+ str += String_convert::i2hex_str (1, 2, '0');
return String_convert::hex2bin_str (str);
}
instrument_p_ = new Audio_instrument (str);
announce_element (Audio_element_info (instrument_p_, 0));
}
+ Performer_group_performer::create_audio_elements ();
}
void
if (gh_pair_p (fr)
&& scm_equal_p (fr, prev_fraction_) != SCM_BOOL_T)
{
+ prev_fraction_ = fr;
int b = gh_scm2int (gh_car (fr));
int o = gh_scm2int (gh_cdr (fr));
\accepts Voice;
\consists "Key_performer";
- \consists "Time_signature_performer";
\consists "Tempo_performer";
+ \consists "Time_signature_performer";
dynamicStyle = #"dynamic"
};
\translator { \StaffContext }
;; 90 == 90/127 == 0.71 is supposed to be the default value
;; urg: we should set this at start of track
(define dynamic-default-volume 0.71)
+
+;; Count number of sharps minus number of flats
+(define (accidentals-in-key pitch-list)
+ (apply + (map cdr pitch-list)))
+
+;; Characterise the key as major if the alteration of the
+;; third scale note is the same as that of the main note
+;; Note: MIDI cannot handle other tonalities than major/minor.
+(define (major-key pitch-list)
+ (eq? (cdr (list-ref pitch-list 4)) (cdr (list-ref pitch-list 6))))