#include "ofApp.h"
void ofApp::setup(){
currentIndex = 0;
string filePath = "morse.csv";
font.load("frabk.ttf", 122);
ofFile file(filePath);
if(!file.exists()){
ofLogError("The file " + filePath + " is missing");
}
ofBuffer buffer(file);
for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) {
string line = *it;
vector<string> words = ofSplitString(line, ",");
if (words.size()>=2) {
MorseCodeSymbol symbol;
symbol.character = words[0];
symbol.code = words[1];
morseCodeSymbols.push_back(symbol);
ofLogVerbose("symbol.character: " + symbol.character);
ofLogVerbose("symbol.code: " + symbol.code);
}
}
player.setup();
}
void ofApp::update(){
player.update();
}
void ofApp::draw(){
ofDrawBitmapString("PRESS A KEY (A-Z, 0-9) TO PLAY MORSE CODE", 20, 20);
string line1 = currentSymbol.character;
string line2 = currentSymbol.code;
font.drawString(line1, (ofGetWidth() - font.stringWidth(line1))/2, ofGetHeight()/2);
font.drawString(line2, (ofGetWidth() - font.stringWidth(line2))/2, ofGetHeight()/2+font.stringHeight(line1));
}
void ofApp::keyPressed(int key){
string myKey;
myKey = (char) key;
myKey = ofToUpper(myKey);
for (unsigned int i=0; i<morseCodeSymbols.size(); i++) {
if (morseCodeSymbols[i].character == myKey){
currentSymbol = morseCodeSymbols[i];
player.playCode(currentSymbol.code);
}
}
}
void ofApp::keyReleased(int key){
}
void ofApp::mouseMoved(int x, int y ){
}
void ofApp::mouseDragged(int x, int y, int button){
}
void ofApp::mousePressed(int x, int y, int button){
}
void ofApp::mouseReleased(int x, int y, int button){
}
void ofApp::mouseEntered(int x, int y){
}
void ofApp::mouseExited(int x, int y){
}
void ofApp::windowResized(int w, int h){
}
void ofApp::gotMessage(ofMessage msg){
}
void ofApp::dragEvent(ofDragInfo dragInfo)
{
}
Comments