I do not think I have the boost libraries; my compiler gave me errors starting on the "using namespace" line and after that it did not like anything that referenced boost methods, plus it said that the directory for boost files did not exist (I am paraphrasing here). How do I get this library, and is it simply a matter of unzipping a bunch of files to my include path or is there more to it?
Have a great day, Alex
----- Original Message ----- From: "Ken Perry" <whistler@xxxxxxxxxxxxx To: <programmingblind@xxxxxxxxxxxxx Date sent: Sun, 8 Jun 2008 18:21:20 -0700 Subject: Alex beep code example threads
Alex I want to first say if I was doing this I would make sure to
not use
just beep and I would code in a call to the wave function so you
could use a
sound card. I guess if the person didn't have a sound card you
could check
for it and then use the pc speaker. With that said I liked your
little
project and though I would show you how it would be done with the
boost
thread and date libraries. Now if you don't have boost installed
I can tell
you how to do that if you want to. Here is the code that I made
though and
it works.
#include "boost/date_time/posix_time/posix_time.hpp" #include <boost/thread.hpp #include <boost/bind.hpp #include <iostream #include <windows.h #include <string
using namespace boost::posix_time; using namespace boost::gregorian; using namespace std;
enum PERIOD { HOUR, QUARTER, HALF, THREEQUARTER, };
bool beeps = true;
void chime (PERIOD when) { intchimes = 0; // used to repeat chimes for the
minutes
long LastChime;//used to not repeat when it has already chimed //get the current time from the clock -- one second resolution ptime now = second_clock::local_time ();
//set the start last_time so that it doesn't ring instantly if (when == HOUR) LastChime = now.time_of_day ().hours (); else LastChime = now.time_of_day ().minutes ();
while (1) { Sleep (1000); now = second_clock::local_time ();
if (beeps == true) { switch (when) { case HOUR: if (LastChime != now.time_of_day ().hours ()) {for (long i = 0; i < now.time_of_day ().hours ();
i++)
{ Beep (244, 500); Sleep (500); } LastChime = now.time_of_day ().hours (); } break; case QUARTER: if ((LastChime != now.time_of_day ().minutes ()) && (now.time_of_day ().minutes () == 15)) chimes = 1; break; case HALF: if ((LastChime != now.time_of_day ().minutes ()) && (now.time_of_day ().minutes () == 30)) chimes = 2; break; case THREEQUARTER: if ((LastChime != now.time_of_day ().minutes ()) && (now.time_of_day ().minutes () == 45)) chimes = 3; break; }; //end switch
if (chimes > 0) { for (; chimes > 0; chimes--) { Beep (488, 500); Sleep (500); } LastChime = now.time_of_day ().minutes (); } } //end if beeps true } //end while
}
void input () { string cmd; while (1) { cin >> cmd;
if (cmd[0] == 'b') { beeps = true; cout << "Beeps turned on." << endl; } else if (cmd[0] == 's') { beeps = false; cout << "Beeps turned off." << endl; } else if (cmd[0] == 'q') { cout << "Turning off beeper." << endl; exit (0); }
} }
int main () { boost::thread_group Tg; Tg.create_thread (boost::bind (chime, HOUR)); Tg.create_thread (boost::bind (chime, QUARTER)); Tg.create_thread (boost::bind (chime, HALF)); Tg.create_thread (boost::bind (chime, THREEQUARTER)); Tg.create_thread (boost::bind (input));
Tg.join_all (); std::cout << "Done! =)" << std::endl; std::cin.get (); return 0; }
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind