X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpiano-pedal-performer.cc;h=4a24625e04b8160a8def7bccd35e796985b64c53;hb=a6a51abfd0195a3cf7d6ea095cf69808852f21ce;hp=8393fbe83d7079a1167f155b9a3b530552293444;hpb=bdf4ab13203502e7ec7cf9cf5896527643a07c1f;p=lilypond.git diff --git a/lily/piano-pedal-performer.cc b/lily/piano-pedal-performer.cc index 8393fbe83d..4a24625e04 100644 --- a/lily/piano-pedal-performer.cc +++ b/lily/piano-pedal-performer.cc @@ -1,13 +1,32 @@ /* - piano-pedal-performer.cc -- implement Piano_pedal_performer + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2000--2015 Jan Nieuwenhuizen - (c) 2000--2005 Jan Nieuwenhuizen + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "performer.hh" + #include "audio-item.hh" +#include "international.hh" +#include "stream-event.hh" +#include "warn.hh" + +#include "translator.icc" + +enum Pedal_type {SOSTENUTO, SUSTAIN, UNA_CORDA, NUM_PEDAL_TYPES}; /** perform Piano pedals @@ -16,130 +35,157 @@ class Piano_pedal_performer : public Performer { struct Pedal_info { - char const *name_; - Music *start_req_; - Drul_array req_drul_; + Stream_event *start_event_; + Drul_array event_drul_; }; public: TRANSLATOR_DECLARATIONS (Piano_pedal_performer); - ~Piano_pedal_performer (); protected: virtual void initialize (); - virtual bool try_music (Music *); - virtual void create_audio_elements (); - virtual void stop_translation_timestep (); - virtual void start_translation_timestep (); - + static const char *pedal_type_str (int t); + void process_music (); + void stop_translation_timestep (); + void start_translation_timestep (); + void listen_sustain (Stream_event *); + void listen_una_corda (Stream_event *); + void listen_sostenuto (Stream_event *); private: - Link_array audios_; - Pedal_info *info_alist_; + vector audios_; + Pedal_info info_alist_[NUM_PEDAL_TYPES]; }; -Piano_pedal_performer::Piano_pedal_performer () +Piano_pedal_performer::Piano_pedal_performer (Context *c) + : Performer (c) { - info_alist_ = 0; } -Piano_pedal_performer::~Piano_pedal_performer () +const char * +Piano_pedal_performer::pedal_type_str (int t) { - delete[] info_alist_; + switch (t) + { + case SOSTENUTO: + return "Sostenuto"; + case SUSTAIN: + return "Sustain"; + case UNA_CORDA: + return "UnaCorda"; + default: + programming_error ("Unknown pedal type"); + return 0; + } } void Piano_pedal_performer::initialize () { - info_alist_ = new Pedal_info[4]; Pedal_info *p = info_alist_; - char *names [] = { "Sostenuto", "Sustain", "UnaCorda", 0 }; - char **np = names; - do + for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++) { - p->name_ = *np; - p->req_drul_[START] = 0; - p->req_drul_[STOP] = 0; - p->start_req_ = 0; - - p++; + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; + p->start_event_ = 0; } - while (* (np++)); } void -Piano_pedal_performer::create_audio_elements () +Piano_pedal_performer::process_music () { - for (Pedal_info *p = info_alist_; p && p->name_; p++) + Pedal_info *p = info_alist_; + for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++) { - if (p->req_drul_[STOP]) - { - if (!p->start_req_) - { - p->req_drul_[STOP]->origin ()->warning (_f ("can't find start of piano pedal: `%s'", String (p->name_))); - } - else - { - Audio_piano_pedal *a = new Audio_piano_pedal; - a->type_string_ = String (p->name_); - a->dir_ = STOP; - audios_.push (a); - } - p->start_req_ = 0; - } - - if (p->req_drul_[START]) - { - p->start_req_ = p->req_drul_[START]; - Audio_piano_pedal *a = new Audio_piano_pedal; - a->type_string_ = String (p->name_); - a->dir_ = START; - audios_.push (a); - } - p->req_drul_[START] = 0; - p->req_drul_[STOP] = 0; + string pedal_type = pedal_type_str (i); + if (p->event_drul_[STOP]) + { + if (!p->start_event_) + p->event_drul_[STOP]->origin ()->warning (_f ("cannot find start of piano pedal: `%s'", pedal_type)); + else + { + Audio_piano_pedal *a = new Audio_piano_pedal; + a->type_string_ = pedal_type; + a->dir_ = STOP; + audios_.push_back (a); + Audio_element_info info (a, p->event_drul_[STOP]); + announce_element (info); + } + p->start_event_ = 0; + } + + if (p->event_drul_[START]) + { + p->start_event_ = p->event_drul_[START]; + Audio_piano_pedal *a = new Audio_piano_pedal; + a->type_string_ = pedal_type; + a->dir_ = START; + audios_.push_back (a); + Audio_element_info info (a, p->event_drul_[START]); + announce_element (info); + } + p->event_drul_[START] = 0; + p->event_drul_[STOP] = 0; } } void Piano_pedal_performer::stop_translation_timestep () { - for (int i = 0; i < audios_.size (); i++) - play_element (audios_[i]); audios_.clear (); } void Piano_pedal_performer::start_translation_timestep () { - for (Pedal_info *p = info_alist_; p && p->name_; p++) + Pedal_info *p = info_alist_; + for (int i = 0; i < NUM_PEDAL_TYPES; i++, p++) { - p->req_drul_[STOP] = 0; - p->req_drul_[START] = 0; + p->event_drul_[STOP] = 0; + p->event_drul_[START] = 0; } } -bool -Piano_pedal_performer::try_music (Music *r) +void +Piano_pedal_performer::listen_sostenuto (Stream_event *r) { - if (r->is_mus_type ("pedal-event")) - { - for (Pedal_info *p = info_alist_; p->name_; p++) - { - String nm = p->name_ + String ("Event"); - if (ly_c_equal_p (r->get_property ("name"), - scm_str2symbol (nm.to_str0 ()))) - { - Direction d = to_dir (r->get_property ("span-direction")); - p->req_drul_[d] = r; - return true; - } - } - } - return false; + Direction d = to_dir (r->get_property ("span-direction")); + info_alist_[SOSTENUTO].event_drul_[d] = r; } -ADD_TRANSLATOR (Piano_pedal_performer, "", "", - "pedal-event", - "", "", ""); +void +Piano_pedal_performer::listen_sustain (Stream_event *r) +{ + Direction d = to_dir (r->get_property ("span-direction")); + info_alist_[SUSTAIN].event_drul_[d] = r; +} + +void +Piano_pedal_performer::listen_una_corda (Stream_event *r) +{ + Direction d = to_dir (r->get_property ("span-direction")); + info_alist_[UNA_CORDA].event_drul_[d] = r; +} + +void +Piano_pedal_performer::boot () +{ + ADD_LISTENER (Piano_pedal_performer, sostenuto); + ADD_LISTENER (Piano_pedal_performer, sustain); + ADD_LISTENER (Piano_pedal_performer, una_corda); +} + +ADD_TRANSLATOR (Piano_pedal_performer, + /* doc */ + "", + + /* create */ + "", + + /* read */ + "", + + /* write */ + "" + );