comparison Plugins/Input/modplug/modplugbmp.cpp @ 330:4c8545dc17c2 trunk

[svn] Convert to configdb usage.
author chainsaw
date Sun, 25 Dec 2005 08:49:09 -0800
parents 53393c07735b
children 7fa1738514d5
comparison
equal deleted inserted replaced
329:53393c07735b 330:4c8545dc17c2
11 #include "modplugbmp.h" 11 #include "modplugbmp.h"
12 #include <libmodplug/stdafx.h> 12 #include <libmodplug/stdafx.h>
13 #include <libmodplug/sndfile.h> 13 #include <libmodplug/sndfile.h>
14 #include "stddefs.h" 14 #include "stddefs.h"
15 #include "archive/open.h" 15 #include "archive/open.h"
16 #include "libaudacious/configdb.h"
16 17
17 // ModplugXMMS member functions =============================== 18 // ModplugXMMS member functions ===============================
18 19
19 // operations ---------------------------------------- 20 // operations ----------------------------------------
20 ModplugXMMS::ModplugXMMS() 21 ModplugXMMS::ModplugXMMS()
55 mLoopCount = 0; //don't loop 56 mLoopCount = 0; //don't loop
56 } 57 }
57 58
58 void ModplugXMMS::Init(void) 59 void ModplugXMMS::Init(void)
59 { 60 {
60 fstream lConfigFile; 61 ConfigDb *db;
61 string lField, lValue; 62
62 string lConfigFilename; 63 db = bmp_cfg_db_open();
63 bool lValueB; 64
64 char junk; 65 bmp_cfg_db_get_bool(db,"modplug","Surround", &mModProps.mSurround);
65 66 bmp_cfg_db_get_bool(db,"modplug","Oversampling", &mModProps.mOversamp);
66 //I chose to use a separate config file to avoid conflicts 67 bmp_cfg_db_get_bool(db,"modplug","Megabass", &mModProps.mMegabass);
67 lConfigFilename = g_get_home_dir(); 68 bmp_cfg_db_get_bool(db,"modplug","NoiseReduction", &mModProps.mNoiseReduction);
68 lConfigFilename += "/.audacious/modplug-bmp.conf"; 69 bmp_cfg_db_get_bool(db,"modplug","VolumeRamp", &mModProps.mVolumeRamp);
69 lConfigFile.open(lConfigFilename.c_str(), ios::in); 70 bmp_cfg_db_get_bool(db,"modplug","Reverb", &mModProps.mReverb);
70 71 bmp_cfg_db_get_bool(db,"modplug","FastInfo", &mModProps.mFastinfo);
71 if(!lConfigFile.is_open()) 72 bmp_cfg_db_get_bool(db,"modplug","UseFileName", &mModProps.mUseFilename);
72 return; 73 bmp_cfg_db_get_bool(db,"modplug","PreAmp", &mModProps.mPreamp);
73 74 bmp_cfg_db_get_float(db,"modplug","PreAmpLevel", &mModProps.mPreampLevel);
74 while(!lConfigFile.eof()) 75 bmp_cfg_db_get_int(db,"modplug", "Channels", &mModProps.mChannels);
75 { 76 bmp_cfg_db_get_int(db,"modplug", "Bits", &mModProps.mBits);
76 lConfigFile >> lField; 77 bmp_cfg_db_get_int(db,"modplug", "Frequency", &mModProps.mFrequency);
77 if(lField[0] == '#') //allow comments 78 bmp_cfg_db_get_int(db,"modplug", "ResamplineMode", &mModProps.mResamplingMode);
78 { 79 bmp_cfg_db_get_int(db,"modplug", "ReverbDepth", &mModProps.mReverbDepth);
79 do 80 bmp_cfg_db_get_int(db,"modplug", "ReverbDelay", &mModProps.mReverbDelay);
80 { 81 bmp_cfg_db_get_int(db,"modplug", "BassAmount", &mModProps.mBassAmount);
81 lConfigFile.read(&junk, 1); 82 bmp_cfg_db_get_int(db,"modplug", "BassRange", &mModProps.mBassRange);
82 } 83 bmp_cfg_db_get_int(db,"modplug", "SurroundDepth", &mModProps.mSurroundDepth);
83 while(junk != '\n'); 84 bmp_cfg_db_get_int(db,"modplug", "SurroundDelay", &mModProps.mSurroundDelay);
84 } 85 bmp_cfg_db_get_int(db,"modplug", "LoopCount", &mModProps.mLoopCount);
85 else 86
86 { 87 bmp_cfg_db_close(db);
87 if(lField == "reverb_depth")
88 lConfigFile >> mModProps.mReverbDepth;
89 else if(lField == "reverb_delay")
90 lConfigFile >> mModProps.mReverbDelay;
91 else if(lField == "megabass_amount")
92 lConfigFile >> mModProps.mBassAmount;
93 else if(lField == "megabass_range")
94 lConfigFile >> mModProps.mBassRange;
95 else if(lField == "surround_depth")
96 lConfigFile >> mModProps.mSurroundDepth;
97 else if(lField == "surround_delay")
98 lConfigFile >> mModProps.mSurroundDelay;
99 else if(lField == "preamp_volume")
100 lConfigFile >> mModProps.mPreampLevel;
101 else if(lField == "loop_count")
102 lConfigFile >> mModProps.mLoopCount;
103 else
104 {
105 lConfigFile >> lValue;
106 if(lValue == "on")
107 lValueB = true;
108 else
109 lValueB = false;
110
111 if(lField == "surround")
112 mModProps.mSurround = lValueB;
113 else if(lField == "oversampling")
114 mModProps.mOversamp = lValueB;
115 else if(lField == "reverb")
116 mModProps.mReverb = lValueB;
117 else if(lField == "megabass")
118 mModProps.mMegabass = lValueB;
119 else if(lField == "noisereduction")
120 mModProps.mNoiseReduction = lValueB;
121 else if(lField == "volumeramping")
122 mModProps.mVolumeRamp = lValueB;
123 else if(lField == "fastinfo")
124 mModProps.mFastinfo = lValueB;
125 else if(lField == "use_filename")
126 mModProps.mUseFilename = lValueB;
127 else if(lField == "preamp")
128 mModProps.mPreamp = lValueB;
129
130 else if(lField == "channels")
131 {
132 if(lValue == "mono")
133 mModProps.mChannels = 1;
134 else
135 mModProps.mChannels = 2;
136 }
137 else if(lField == "frequency")
138 {
139 if(lValue == "22050")
140 mModProps.mFrequency = 22050;
141 else if(lValue == "11025")
142 mModProps.mFrequency = 11025;
143 else
144 mModProps.mFrequency = 44100;
145 }
146 else if(lField == "bits")
147 {
148 if(lValue == "8")
149 mModProps.mBits = 8;
150 else
151 mModProps.mBits = 16;
152 }
153 else if(lField == "resampling")
154 {
155 if(lValue == "nearest")
156 mModProps.mResamplingMode = SRCMODE_NEAREST;
157 else if(lValue == "linear")
158 mModProps.mResamplingMode = SRCMODE_LINEAR;
159 else if(lValue == "spline")
160 mModProps.mResamplingMode = SRCMODE_SPLINE;
161 else
162 mModProps.mResamplingMode = SRCMODE_POLYPHASE;
163 }
164 } //if(numerical value) else
165 } //if(comment) else
166 } //while(!eof)
167
168 lConfigFile.close();
169 } 88 }
170 89
171 bool ModplugXMMS::CanPlayFile(const string& aFilename) 90 bool ModplugXMMS::CanPlayFile(const string& aFilename)
172 { 91 {
173 string lExt; 92 string lExt;
717 return "off"; 636 return "off";
718 } 637 }
719 638
720 void ModplugXMMS::SetModProps(const Settings& aModProps) 639 void ModplugXMMS::SetModProps(const Settings& aModProps)
721 { 640 {
722 fstream lConfigFile; 641 ConfigDb *db;
723 string lConfigFilename;
724
725 mModProps = aModProps; 642 mModProps = aModProps;
726 643
727 // [Reverb level 0(quiet)-100(loud)], [delay in ms, usually 40-200ms] 644 // [Reverb level 0(quiet)-100(loud)], [delay in ms, usually 40-200ms]
728 if(mModProps.mReverb) 645 if(mModProps.mReverb)
729 { 646 {
770 false 687 false
771 ); 688 );
772 CSoundFile::SetResamplingMode(mModProps.mResamplingMode); 689 CSoundFile::SetResamplingMode(mModProps.mResamplingMode);
773 mPreampFactor = exp(mModProps.mPreampLevel); 690 mPreampFactor = exp(mModProps.mPreampLevel);
774 691
775 lConfigFilename = g_get_home_dir(); 692 db = bmp_cfg_db_open();
776 lConfigFilename += "/.audacious/modplug-bmp.conf"; 693
777 lConfigFile.open(lConfigFilename.c_str(), ios::out); 694 bmp_cfg_db_set_bool(db,"modplug","Surround", mModProps.mSurround);
778 695 bmp_cfg_db_set_bool(db,"modplug","Oversampling", mModProps.mOversamp);
779 lConfigFile << "# Modplug BMP plugin config file\n" 696 bmp_cfg_db_set_bool(db,"modplug","Megabass", mModProps.mMegabass);
780 << "# Modplug (C) 1999 Olivier Lapicque\n" 697 bmp_cfg_db_set_bool(db,"modplug","NoiseReduction", mModProps.mNoiseReduction);
781 << "# XMMS port (C) 1999 Kenton Varda\n" 698 bmp_cfg_db_set_bool(db,"modplug","VolumeRamp", mModProps.mVolumeRamp);
782 << "# BMP port (C) 2004 Theofilos Intzoglou" << endl; 699 bmp_cfg_db_set_bool(db,"modplug","Reverb", mModProps.mReverb);
783 700 bmp_cfg_db_set_bool(db,"modplug","FastInfo", mModProps.mFastinfo);
784 lConfigFile << "# ---Effects---" << endl; 701 bmp_cfg_db_set_bool(db,"modplug","UseFileName", mModProps.mUseFilename);
785 lConfigFile << "reverb " << Bool2OnOff(mModProps.mReverb) << endl; 702 bmp_cfg_db_set_bool(db,"modplug","PreAmp", mModProps.mPreamp);
786 lConfigFile << "reverb_depth " << mModProps.mReverbDepth << endl; 703 bmp_cfg_db_set_float(db,"modplug","PreAmpLevel", mModProps.mPreampLevel);
787 lConfigFile << "reverb_delay " << mModProps.mReverbDelay << endl; 704 bmp_cfg_db_set_int(db,"modplug", "Channels", mModProps.mChannels);
788 lConfigFile << endl; 705 bmp_cfg_db_set_int(db,"modplug", "Bits", mModProps.mBits);
789 lConfigFile << "surround " << Bool2OnOff(mModProps.mSurround) << endl; 706 bmp_cfg_db_set_int(db,"modplug", "Frequency", mModProps.mFrequency);
790 lConfigFile << "surround_depth " << mModProps.mSurroundDepth << endl; 707 bmp_cfg_db_set_int(db,"modplug", "ResamplineMode", mModProps.mResamplingMode);
791 lConfigFile << "surround_delay " << mModProps.mSurroundDelay << endl; 708 bmp_cfg_db_set_int(db,"modplug", "ReverbDepth", mModProps.mReverbDepth);
792 lConfigFile << endl; 709 bmp_cfg_db_set_int(db,"modplug", "ReverbDelay", mModProps.mReverbDelay);
793 lConfigFile << "megabass " << Bool2OnOff(mModProps.mMegabass) << endl; 710 bmp_cfg_db_set_int(db,"modplug", "BassAmount", mModProps.mBassAmount);
794 lConfigFile << "megabass_amount " << mModProps.mBassAmount << endl; 711 bmp_cfg_db_set_int(db,"modplug", "BassRange", mModProps.mBassRange);
795 lConfigFile << "megabass_range " << mModProps.mBassRange << endl; 712 bmp_cfg_db_set_int(db,"modplug", "SurroundDepth", mModProps.mSurroundDepth);
796 lConfigFile << endl; 713 bmp_cfg_db_set_int(db,"modplug", "SurroundDelay", mModProps.mSurroundDelay);
797 lConfigFile << "oversampling " << Bool2OnOff(mModProps.mOversamp) << endl; 714 bmp_cfg_db_set_int(db,"modplug", "LoopCount", mModProps.mLoopCount);
798 lConfigFile << "noisereduction " << Bool2OnOff(mModProps.mNoiseReduction) << endl; 715
799 lConfigFile << "volumeramping " << Bool2OnOff(mModProps.mVolumeRamp) << endl; 716 bmp_cfg_db_close(db);
800 lConfigFile << "fastinfo " << Bool2OnOff(mModProps.mFastinfo) << endl;
801 lConfigFile << "use_filename " << Bool2OnOff(mModProps.mUseFilename) << endl;
802 lConfigFile << "loop_count " << mModProps.mLoopCount << endl;
803 lConfigFile << endl;
804 lConfigFile << "preamp " << Bool2OnOff(mModProps.mPreamp) << endl;
805 lConfigFile << "preamp_volume " << mModProps.mPreampLevel << endl;
806 lConfigFile << endl;
807
808 lConfigFile << "# ---Quality---" << endl;
809 lConfigFile << "channels ";
810 if(mModProps.mChannels == 1)
811 lConfigFile << "mono" << endl;
812 else
813 lConfigFile << "stereo" << endl;
814 lConfigFile << "bits " << (int)mModProps.mBits << endl;
815 lConfigFile << "frequency " << mModProps.mFrequency << endl;
816 lConfigFile << "resampling ";
817 switch(mModProps.mResamplingMode)
818 {
819 case SRCMODE_NEAREST:
820 lConfigFile << "nearest" << endl;
821 break;
822 case SRCMODE_LINEAR:
823 lConfigFile << "linear" << endl;
824 break;
825 case SRCMODE_SPLINE:
826 lConfigFile << "spline" << endl;
827 break;
828 default:
829 case SRCMODE_POLYPHASE:
830 lConfigFile << "fir" << endl;
831 break;
832 };
833
834 lConfigFile.close();
835 } 717 }
836 718
837 ModplugXMMS gModplugXMMS; 719 ModplugXMMS gModplugXMMS;