bool Morse::StringToMorse (QString &line) { line += '\0'; for (int i = 0; i < line.size () - 1; ++i) { switch (line.at(i).unicode ()) { case 'A': *this << A; if (line.at (i + 1) == ' ') continue; else *this << MINI_SPACE; break; case 'B': *this << B; if (line.at (i + 1) == ' ') continue; else *this << MINI_SPACE; break; //
void Morse::PlayLinePoints () { QTimer::singleShot (duration_point_, this, SLOT ( Mute () )); sound_.play (); } void Morse::Mute () { if (line_points_.empty ()) { // sound_.stop (); return; } if (line_points_.at (0)) { // sound_.setMuted (false); line_points_.remove (0); QTimer::singleShot (duration_point_, this, SLOT ( Mute () )); return; } else { sound_.setMuted (true); // line_points_.remove (0); QTimer::singleShot (duration_point_, this, SLOT ( Mute () )); return; } }
// QMap<QChar, QBitArray> codes_;
void Morse::MiniSpace () { if (stop_) { this->Stop (); return; } sound_.setMuted (true); ++id_element_; // if ( id_element_ == codes_.value ( string_to_play_.at (id_char_) ).size () ) { ++id_char_; id_element_ = 0; QTimer::singleShot (duration_dot_ * 3, this, SLOT ( Mute() )); // return; } QTimer::singleShot (duration_dot_, this, SLOT ( Mute() )); // } void Morse::Space () { if (stop_) { this->Stop (); return; } sound_.setMuted (true); // 7 // , 4 QTimer::singleShot (duration_dot_ * 4, this, SLOT ( Mute() )); } void Morse::Mute () { if (stop_) { this->Stop (); return; } if (id_char_ == string_to_play_.size ()) { // this->Stop (); return; } if (string_to_play_.at (id_char_) == ' ') { Space(); ++id_char_; // return; } if (codes_.find ( string_to_play_.at (id_char_) ) == codes_.end ()) { qDebug() << string_to_play_.at (id_char_) << ": No code!"; sound_.stop (); return; } sound_.setMuted (false); // if ( codes_.value ( string_to_play_.at (id_char_) ).at (id_element_)) { QTimer::singleShot (duration_dot_, this, SLOT ( MiniSpace() )); // } else { QTimer::singleShot (duration_dot_ * 3, this, SLOT ( MiniSpace() )); // } } bool Morse::Play () { if (!stop_) return false; if (string_to_play_ == "") return false; stop_ = false; id_char_ = 0; id_element_ = 0; sound_.setMuted (true); // sound_.play (); Mute (); } void Morse::Stop () { if (stop_) return; sound_.stop (); id_char_ = 0; id_element_ = 0; stop_ = true; }
Source: https://habr.com/ru/post/267605/
All Articles