Ejemplo n.º 1
0
        public string MakeHelpString(bool common)
        {
            StringBuilder builder = new StringBuilder();

            try {
                foreach (KeyValuePair <string, VoiceParm> entry in voiceParmsByName)
                {
                    string    name = entry.Key;
                    VoiceParm parm = entry.Value;
                    if (common && !parm.common)
                    {
                        continue;
                    }
                    builder.Append(string.Format("{0}: {1} default {2}",
                                                 name, valueKindNames[(int)parm.valueKind], parm.value.ToString()));
                    if (parm.valueKind == ValueKind.Int && (parm.imin != Int32.MinValue || parm.imax != Int32.MaxValue))
                    {
                        builder.Append(string.Format(" min {0} max {1}", parm.imin, parm.imax));
                    }
                    else if (parm.valueKind == ValueKind.Float && (parm.fmin != Int32.MinValue || parm.fmax != Int32.MaxValue))
                    {
                        builder.Append(string.Format(" min {0} max {1}", parm.fmin, parm.fmax));
                    }
                    builder.Append(string.Format(" ({0})\n", parm.description));
                }
            }
            catch (Exception e) {
                log.Error("VoiceParmSet.MakeHelpString: exception " + e.Message + "; Stack trace\n" + e.StackTrace.ToString());
            }
            return(builder.ToString());
        }
Ejemplo n.º 2
0
        public VoiceParmSet(Object[] parmArray)
        {
            int len = parmArray.Length;

            if ((len & 1) != 0)
            {
                log.Error("VoiceParmSet: Odd number of parms " + parmArray);
                len--;
            }
            for (int i = 0; i < len; i += 2)
            {
                string    name        = parmArray[i].ToString();
                string    value       = parmArray[i + 1].ToString();
                VoiceParm defaultParm = defaultVoiceParms.GetNamedParm(name);
                if (defaultParm == null)
                {
                    log.Error("VoiceParmSet: no default parm for '" + name + "'");
                    continue;
                }
                VoiceParm parmCopy = new VoiceParm(defaultParm);
                CheckValidParm(parmCopy, value);
                if (parmCopy.ret.errorMessage != "")
                {
                    log.Error(parmCopy.ret.errorMessage);
                }
                else
                {
                    parmCopy.value = value;
                    Add(parmCopy);
                }
            }
        }
Ejemplo n.º 3
0
        public static string StringValue(VoiceParm parm)
        {
            if (parm.ret != null)
            {
                switch (parm.valueKind)
                {
                case ValueKind.Int:
                    return(parm.ret.iValue.ToString());

                case ValueKind.Long:
                    return(parm.ret.lValue.ToString());

                case ValueKind.Float:
                    return(parm.ret.fValue.ToString());

                case ValueKind.Bool:
                    return(parm.ret.bValue ? "true" : "false");

                case ValueKind.String:
                    return(parm.ret.sValue);

                default:
                    log.ErrorFormat("VoiceParm.StringValue: For parm '{0}', unknown valueKind {1}",
                                    parm.name, parm.valueKind);
                    return("None");
                }
            }
            log.ErrorFormat("VoiceParm.StringValue: For parm '{0}', ret is null!", parm.name);
            return("None");
        }
Ejemplo n.º 4
0
        public void Add(VoiceParm newParm)
        {
            Dictionary <int, VoiceParm> parms;

            if (!voiceKindParms.TryGetValue(newParm.kind, out parms))
            {
                parms = new Dictionary <int, VoiceParm>();
                voiceKindParms[newParm.kind] = parms;
            }
            VoiceParm parm;

            if (parms.TryGetValue(newParm.ctlIndex, out parm))
            {
                log.ErrorFormat("VoiceParmCollection.Add: for parameter {0} of kind {1} and index {2}, the index is already in the kind collection",
                                newParm.name, newParm.kind, newParm.ctlIndex);
            }
            else if (voiceParmsByName.TryGetValue(newParm.name, out parm))
            {
                log.ErrorFormat("VoiceParmCollection.Add: parameter {0} of kind {1} is already the name index",
                                newParm.name, newParm.kind);
            }
            else
            {
                parm = newParm;
                parms[newParm.ctlIndex] = parm;
                // Also, add it to the name dictionary
                voiceParmsByName[newParm.name] = parm;
                CheckValidParm(parm, parm.value.ToString());
                if (parm.ret.errorMessage != "")
                {
                    log.Error("VoiceParmSet.Add: " + parm.ret.errorMessage);
                }
            }
        }
Ejemplo n.º 5
0
        public List <VoiceParm> GetParmsOfKindOrDefault(VoiceParmKind kind, bool reconfigure)
        {
            List <VoiceParm> parms         = GetParmsOfKind(kind);
            List <VoiceParm> defaultOfKind = defaultVoiceParms.GetParmsOfKind(kind);

            if (parms == null)
            {
                if (reconfigure)
                {
                    return(new List <VoiceParm>());
                }
                else
                {
                    return(new List <VoiceParm>(defaultOfKind));
                }
            }
            List <VoiceParm> returnedParms = new List <VoiceParm>();

            foreach (VoiceParm defParm in defaultOfKind)
            {
                VoiceParm parm = GetNamedParm(defParm.name);
                if (parm != null)
                {
//                     log.InfoFormat("VoiceParmSet.GetParmsOfKindOrDefault: defParm.name {0} parm.name {1} parm.value {2}, parm.ret.lValue {3}",
//                             defParm.name, parm.name, parm.value, parm.ret.lValue);
                    returnedParms.Add(parm);
                }
                else if (!reconfigure)
                {
                    returnedParms.Add(defParm);
                }
            }
            return(returnedParms);
        }
Ejemplo n.º 6
0
 public VoiceParm(VoiceParm other)
 {
     this.kind        = other.kind;
     this.name        = other.name;
     this.description = other.description;
     this.valueKind   = other.valueKind;
     this.value       = other.value;
     this.imin        = other.imin;
     this.imax        = other.imax;
     this.fmin        = other.fmin;
     this.fmax        = other.fmax;
     this.ctlIndex    = other.ctlIndex;
     this.ret         = other.ret;
 }
Ejemplo n.º 7
0
        public ParmStatus CheckValidParm(VoiceParm parm, string value)
        {
            //log.InfoFormat("VoiceParmCollection.CheckValidParm: for parameter {0}, value is {1}", parm.name, value);
            ParmStatus ret = new ParmStatus();

            parm.ret = ret;
            if (parm == null)
            {
                ret.errorMessage = "There is no parameter named '" + parm.name + "'";
                return(ret);
            }
            switch (parm.valueKind)
            {
            case ValueKind.Int:
                try {
                    ret.iValue = Int32.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' can't be parsed",
                                                     parm.name, value);
                    return(ret);
                }
                if (ret.iValue < parm.imin || ret.iValue > parm.imax)
                {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' is outside the range from {2} to {3}",
                                                     parm.name, ret.iValue, parm.imin, parm.imax);
                    return(ret);
                }
                break;

            case ValueKind.Long:
                try {
                    ret.lValue = Int64.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' can't be parsed",
                                                     parm.name, value);
                    return(ret);
                }
                break;

            case ValueKind.Float:
                try {
                    ret.fValue = Single.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Float parameter '{0}' value '{1}' can't be parsed",
                                                     parm.name, value);
                    return(ret);
                }
                if (ret.fValue < parm.fmin || ret.fValue > parm.fmax)
                {
                    ret.errorMessage = string.Format("Float parameter '{0}' value '{1}' is outside the range from {2} to {3}",
                                                     parm.name, ret.fValue, parm.fmin, parm.fmax);
                    return(ret);
                }
                break;

            case ValueKind.Bool:
                try {
                    ret.bValue = Boolean.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Boolean parameter '{0}' value '{1}' can't be parsed",
                                                     parm.name, value);
                    return(ret);
                }
                break;

            case ValueKind.String:
                ret.sValue = value;
                break;
            }
            return(ret);
        }
Ejemplo n.º 8
0
        public void Add(VoiceParmKind kind, string name, string description, ValueKind valueKind, Object value, int index, bool common, float min, float max)
        {
            VoiceParm newParm = new VoiceParm(kind, name, description, valueKind, value, index, common, min, max);

            Add(newParm);
        }
Ejemplo n.º 9
0
        public ParmStatus CheckValidParm(VoiceParm parm, string value)
        {
            //log.InfoFormat("VoiceParmCollection.CheckValidParm: for parameter {0}, value is {1}", parm.name, value);
            ParmStatus ret = new ParmStatus();
            parm.ret = ret;
            if (parm == null) {
                ret.errorMessage = "There is no parameter named '" + parm.name + "'";
                return ret;
            }
            switch (parm.valueKind) {

            case ValueKind.Int:
                try {
                    ret.iValue = Int32.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' can't be parsed",
                        parm.name, value);
                    return ret;
                }
                if (ret.iValue < parm.imin || ret.iValue > parm.imax) {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' is outside the range from {2} to {3}",
                        parm.name, ret.iValue, parm.imin, parm.imax);
                    return ret;
                }
                break;

            case ValueKind.Long:
                try {
                    ret.lValue = Int64.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Int parameter '{0}' value '{1}' can't be parsed",
                        parm.name, value);
                    return ret;
                }
                break;

            case ValueKind.Float:
                try {
                    ret.fValue = Single.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Float parameter '{0}' value '{1}' can't be parsed",
                        parm.name, value);
                    return ret;
                }
                if (ret.fValue < parm.fmin || ret.fValue > parm.fmax) {
                    ret.errorMessage = string.Format("Float parameter '{0}' value '{1}' is outside the range from {2} to {3}",
                        parm.name, ret.fValue, parm.fmin, parm.fmax);
                    return ret;
                }
                break;

            case ValueKind.Bool:
                try {
                    ret.bValue = Boolean.Parse(value);
                }
                catch (Exception) {
                    ret.errorMessage = string.Format("Boolean parameter '{0}' value '{1}' can't be parsed",
                        parm.name, value);
                    return ret;
                }
                break;

            case ValueKind.String:
                ret.sValue = value;
                break;

            }
            return ret;
        }
Ejemplo n.º 10
0
 public void Add(VoiceParm newParm)
 {
     Dictionary<int, VoiceParm> parms;
     if (!voiceKindParms.TryGetValue(newParm.kind, out parms)) {
         parms = new Dictionary<int, VoiceParm>();
         voiceKindParms[newParm.kind] = parms;
     }
     VoiceParm parm;
     if (parms.TryGetValue(newParm.ctlIndex, out parm))
         log.ErrorFormat("VoiceParmCollection.Add: for parameter {0} of kind {1} and index {2}, the index is already in the kind collection",
             newParm.name, newParm.kind, newParm.ctlIndex);
     else if (voiceParmsByName.TryGetValue(newParm.name, out parm))
         log.ErrorFormat("VoiceParmCollection.Add: parameter {0} of kind {1} is already the name index",
             newParm.name, newParm.kind);
     else {
         parm = newParm;
         parms[newParm.ctlIndex] = parm;
         // Also, add it to the name dictionary
         voiceParmsByName[newParm.name] = parm;
         CheckValidParm(parm, parm.value.ToString());
         if (parm.ret.errorMessage != "")
             log.Error("VoiceParmSet.Add: " + parm.ret.errorMessage);
     }
 }
Ejemplo n.º 11
0
 public void Add(VoiceParmKind kind, string name, string description, ValueKind valueKind, Object value, int index, bool common, float min, float max)
 {
     VoiceParm newParm = new VoiceParm(kind, name, description, valueKind, value, index, common, min, max);
     Add(newParm);
 }
Ejemplo n.º 12
0
 public static string StringValue(VoiceParm parm)
 {
     if (parm.ret != null) {
         switch (parm.valueKind) {
         case ValueKind.Int:
             return parm.ret.iValue.ToString();
         case ValueKind.Long:
             return parm.ret.lValue.ToString();
         case ValueKind.Float:
             return parm.ret.fValue.ToString();
         case ValueKind.Bool:
             return (parm.ret.bValue ? "true" : "false");
         case ValueKind.String:
             return parm.ret.sValue;
         default:
             log.ErrorFormat("VoiceParm.StringValue: For parm '{0}', unknown valueKind {1}",
                 parm.name, parm.valueKind);
             return "None";
         }
     }
     log.ErrorFormat("VoiceParm.StringValue: For parm '{0}', ret is null!", parm.name);
     return "None";
 }
Ejemplo n.º 13
0
 public VoiceParmSet(Object[] parmArray)
 {
     int len = parmArray.Length;
     if ((len & 1) != 0) {
         log.Error("VoiceParmSet: Odd number of parms " + parmArray);
         len--;
     }
     for (int i=0; i<len; i+=2) {
         string name = parmArray[i].ToString();
         string value = parmArray[i+1].ToString();
         VoiceParm defaultParm = defaultVoiceParms.GetNamedParm(name);
         if (defaultParm == null) {
             log.Error("VoiceParmSet: no default parm for '" + name + "'");
             continue;
         }
         VoiceParm parmCopy = new VoiceParm(defaultParm);
         CheckValidParm(parmCopy, value);
         if (parmCopy.ret.errorMessage != "")
             log.Error(parmCopy.ret.errorMessage);
         else {
             parmCopy.value = value;
             Add(parmCopy);
         }
     }
 }
Ejemplo n.º 14
0
 public VoiceParm(VoiceParm other)
 {
     this.kind = other.kind;
     this.name = other.name;
     this.description = other.description;
     this.valueKind = other.valueKind;
     this.value = other.value;
     this.imin = other.imin;
     this.imax = other.imax;
     this.fmin = other.fmin;
     this.fmax = other.fmax;
     this.ctlIndex = other.ctlIndex;
     this.ret = other.ret;
 }