/** @file * @author Edouard DUPIN * @copyright 2019, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ #include #include #include #include #include #include #include #include #include #include #include #include ETK_DECLARE_TYPE(appl::Windows); ETK_DECLARE_TYPE(appl::wordMode); appl::Windows::Windows() : propertyCount(this, "count", 5, "Number of time we restart a record"), propertyInput(this, "input", "microphone", "play microphone stream", &appl::Windows::inputChangeValue), propertyRandom(this, "random", false, "play in random mode"), propertyCorpusPath(this, "corpus-path", "USER_DATA:///corpus/" + etk::toString(echrono::Clock::now()), "corpus root path"), propertyUserName(this, "user-name", "Unknow", "User name to identify the corpus source"), propertyUserBirthYear(this, "user-year", 0, "Birth year of the user to distingush the age of the user"), propertyWordMode(this, "word-mode", appl::wordMode::wordMode_ALL_WORD, "Word list mode"), m_composer(null) { addObjectType("appl::Windows"); propertyTitle.setDirectCheck("River IO viewer"); // set property list: propertyWordMode.add(appl::wordMode::wordMode_ALL_WORD, "ALL_WORD"); propertyWordMode.add(appl::wordMode::wordMode_ORDERED_WORD, "ORDERED_WORD"); propertyWordMode.add(appl::wordMode::wordMode_SELECTED_WORD, "SELECTED_WORD"); propertyWordMode.add(appl::wordMode::wordMode_NUMBER, "NUMBER"); } void appl::Windows::inputChangeValue() { ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); if (tmpDisp != null) { tmpDisp->propertyInput.set(propertyInput.get()); } } void appl::Windows::init() { ewol::widget::Windows::init(); APPL_ERROR("Load Application"); etk::String composition = etk::String(""); composition += "\n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += " \n"; composition += "\n"; m_composer = ewol::widget::Composer::create(); if (m_composer == null) { APPL_CRITICAL(" An error occured ... in the windows creation ..."); return; } APPL_ERROR("Composer LOAD [BEGIN]"); m_composer->loadFromString(composition); setSubWidget(m_composer); APPL_ERROR("Composer LOAD [ END ]"); subBind(ewol::widget::Button, "bt-record", signalPressed, sharedFromThis(), &appl::Windows::onCallbackRecord); subBind(ewol::widget::Button, "bt-reset", signalPressed, sharedFromThis(), &appl::Windows::onCallbackGenerate); subBind(ewol::widget::Button, "bt-next", signalPressed, sharedFromThis(), &appl::Windows::resetCount); subBind(ewol::widget::Button, "bt-next", signalPressed, sharedFromThis(), &appl::Windows::next); subBind(ewol::widget::Button, "bt-remove", signalPressed, sharedFromThis(), &appl::Windows::remove); subBind(appl::widget::DataViewer, "displayer", signalFinished, sharedFromThis(), &appl::Windows::onCallbackFinished); } void appl::Windows::onCallbackFinished() { APPL_INFO("Recording is finished"); ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); if (tmpDisp != null) { m_previousFiles = tmpDisp->store(propertyCorpusPath.get(), propertyUserName.get(), propertyUserBirthYear.get(), m_textToSay, "FR_fr"); m_count++; if (m_count >= propertyCount.get()) { m_count = 0; next(); } else { updateCurentLabel(); tmpDisp->recordToggle(); } } } void appl::Windows::resetCount() { m_count = 0; } void appl::Windows::onCallbackRecord() { APPL_INFO("Start/stop Record of data"); ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); if (tmpDisp != null) { tmpDisp->recordToggle(); } } void appl::Windows::stop() { APPL_INFO("stop Record of data"); ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); if (tmpDisp != null) { tmpDisp->stop(); } } void appl::Windows::onCallbackGenerate() { ememory::SharedPtr tmpDisp = ememory::dynamicPointerCast(getSubObjectNamed("displayer")); if (tmpDisp != null) { tmpDisp->stop(); tmpDisp->reset(); tmpDisp->start(); } } void appl::Windows::remove() { for (auto& elem: m_previousFiles) { APPL_INFO("Remove file " << elem); etk::uri::remove(elem); } m_previousFiles.clear(); } void appl::Windows::next() { m_total++; m_listPos++; int32_t id = m_listPos-1; if (propertyWordMode.get() == wordMode_ALL_WORD) { if (propertyRandom.get() == false) { if (id >= appl::wordList::getWord_FR_count()) { stop(); } } else { id = appl::wordList::getRandWord_FR(); } configureNewText(appl::wordList::getWord_FR(id)); } else if (propertyWordMode.get() == wordMode_ORDERED_WORD) { if (propertyRandom.get() == false) { if (id >= appl::wordList::getWord_FR_ordered_count()) { stop(); } } else { id = appl::wordList::getRandWord_FR_ordered(); } configureNewText(appl::wordList::getWord_FR_ordered(id)); } else if (propertyWordMode.get() == wordMode_NUMBER) { if (propertyRandom.get() == false) { if (id >= appl::wordList::getWord_number_count()) { stop(); } } else { id = appl::wordList::getRandWord_number(); } configureNewText(appl::wordList::getWord_number(id)); } else if (propertyWordMode.get() == wordMode_SELECTED_WORD) { if (propertyRandom.get() == false) { if (id >= appl::wordList::getWord_FR_selected_count()) { stop(); } } else { id = appl::wordList::getRandWord_FR_selected(); } configureNewText(appl::wordList::getWord_FR_selected(id)); } } void appl::Windows::updateCurentLabel() { auto elem = ememory::dynamicPointerCast(getSubObjectNamed("text-to-say")); if (elem == null) { return; } elem->propertyValue.set("[" + etk::toString(m_count+1) + "/" + etk::toString(propertyCount.get()) + "] "+ m_textToSay + "
" + etk::toString(m_listPos) + " total="+ etk::toString(m_total)); } void appl::Windows::configureNewText(const etk::String& _text) { m_textToSay = _text; updateCurentLabel(); onCallbackGenerate(); }