00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "chansetup.h"
00020 #include "chanparse.h"
00021 #include "chanshare.h"
00022 #include <notify.h>
00023
00024 SetupType* SetupDB = (SetupType*)0;
00025
00026 class SetupParseFunctor : public ChanParseFunctor {
00027 public:
00028 INLINE SetupParseFunctor(void) : ChanParseFunctor() {}
00029 virtual ~SetupParseFunctor(void);
00030
00031 virtual void operator()(std::string);
00032 };
00033
00034 SetupParseFunctor::~SetupParseFunctor(void) {
00035 return;
00036 }
00037
00038 void SetupParseFunctor::operator()(std::string S) {
00039 std::string sym;
00040
00041 ChanEatFrontWhite(S);
00042 sym = ChanReadNextWord(S);
00043 ChanCheckScoping(S);
00044 ChanDescope(S);
00045
00046 SetupItem s;
00047
00048 bool stereo = ChanReadNextBool(S);
00049
00050
00051
00052
00053 ChanCheckScoping(S);
00054 int i = S.find_first_of(")");
00055 std::string stmp = S.substr(1, i-2);
00056 S.erase(0, i+1);
00057 ChanEatFrontWhite(S);
00058 ChanViewport v(ChanReadNextFloat(stmp), ChanReadNextFloat(stmp),
00059 ChanReadNextFloat(stmp), ChanReadNextFloat(stmp));
00060 if (!stmp.empty()) {
00061
00062 nout << "error, tailing text in viewport spec '" << stmp << "'" << endl;
00063 stmp.erase(0, std::string::npos);
00064 }
00065 SetupFOV fov;
00066 if (S[0] == '#') {
00067 bool b = ChanReadNextBool(S);
00068 if (b) {
00069
00070 nout << "error, cannot have #t for FOV spec" << endl;
00071 b = false;
00072 }
00073 fov.setFOV();
00074 } else if (S[0] == '(') {
00075 i = S.find_first_of(")");
00076 stmp = S.substr(1, i-2);
00077 S.erase(0, i+1);
00078 ChanEatFrontWhite(S);
00079 fov.setFOV(ChanReadNextFloat(stmp), ChanReadNextFloat(stmp));
00080 if (!stmp.empty()) {
00081
00082 nout << "error, trailing text after fov spec '" << stmp << "'" << endl;
00083 stmp.erase(0, std::string::npos);
00084 }
00085 } else {
00086 fov.setFOV(ChanReadNextFloat(S));
00087 }
00088 SetupItem::Orientation orie = SetupItem::Up;
00089 if (!S.empty()) {
00090 stmp = ChanReadNextWord(S);
00091 if (stmp == "up") {
00092
00093 orie = SetupItem::Up;
00094 } else if (stmp == "down") {
00095 orie = SetupItem::Down;
00096 } else if (stmp == "left") {
00097 orie = SetupItem::Left;
00098 } else if (stmp == "right") {
00099 orie = SetupItem::Right;
00100 } else {
00101
00102 nout << "error, invalid orientation '" << stmp << "'" << endl;
00103 stmp.erase(0, std::string::npos);
00104 }
00105 }
00106 if (!S.empty()) {
00107
00108 nout << "error, trailing text on setup spec '" << S << "'" << endl;
00109 S.erase(0, std::string::npos);
00110 }
00111
00112
00113 s.setState(stereo, false, -1, v, fov, orie);
00114
00115 if (chancfg_cat.is_debug()) {
00116 chancfg_cat->debug() << "parsed a setup called '" << sym << "':" << endl;
00117 chancfg_cat->debug() << " is" << (s.getStereo()?" ":" not ")
00118 << "a stereo setup" << endl;
00119 chancfg_cat->debug() <<" is" << (s.getHWChan()?" ":" not ")
00120 << "a HW channel setup" << endl;
00121 chancfg_cat->debug() << " prefered HW channel number: " << s.getChan()
00122 << endl;
00123 ChanViewport qv(s.getViewport());
00124 chancfg_cat->debug() << " sub viewport: (" << qv.left() << ", "
00125 << qv.right() << ", " << qv.bottom() << ", "
00126 << qv.top() << ")" << endl;
00127 SetupFOV qf(s.getFOV());
00128 switch (qf.getType()) {
00129 case SetupFOV::Invalid:
00130 chancfg_cat->debug() << " FOV is invalid" << endl;
00131 break;
00132 case SetupFOV::Default:
00133 chancfg_cat->debug() << " FOV takes defaults" << endl;
00134 break;
00135 case SetupFOV::Horizontal:
00136 chancfg_cat->debug() << " FOV specifies only horizontal: "
00137 << qf.getHoriz() << endl;
00138 break;
00139 case SetupFOV::Both:
00140 chancfg_cat->debug() << " FOV: " << qf.getHoriz() << " x "
00141 << qf.getVert() << endl;
00142 break;
00143 default:
00144 chancfg_cat->debug() << " FOV is of an unknown type (" << (int)qf.getType()
00145 << ")" << endl;
00146 }
00147 switch (s.getOrientation()) {
00148 case SetupItem::Up:
00149 chancfg_cat->debug() << " setup is oriented Up" << endl;
00150 break;
00151 case SetupItem::Down:
00152 chancfg_cat->debug() << " setup is oriented Down" << endl;
00153 break;
00154 case SetupItem::Left:
00155 chancfg_cat->debug() << " setup is oriented Left" << endl;
00156 break;
00157 case SetupItem::Right:
00158 chancfg_cat->debug() << " setup is oriented Right" << endl;
00159 break;
00160 default:
00161 chancfg_cat->debug() << " setup has an unknown orientation ("
00162 << (int)s.getOrientation() << ")" << endl;
00163 }
00164 }
00165 (*SetupDB)[sym] = s;
00166 }
00167
00168
00169 void ResetSetup() {
00170 if (SetupDB != (SetupType *)NULL) {
00171 delete SetupDB;
00172 }
00173 SetupDB = new SetupType;
00174 }
00175
00176 void ParseSetup(istream& is) {
00177 SetupParseFunctor s;
00178 ChanParse(is, &s);
00179 }