00001 #include <qstring.h> 00002 #include <cstdio> 00003 #include <cstdlib> 00004 00005 using namespace std; 00006 #include "volumebase.h" 00007 00008 VolumeBase::VolumeBase() 00009 { 00010 volume = 80; 00011 current_mute_state=MUTE_OFF; 00012 internal_vol = false; 00013 }; 00014 00015 int VolumeBase::GetCurrentVolume(void) 00016 { 00017 return volume; 00018 } 00019 00020 void VolumeBase::SetCurrentVolume(int value) 00021 { 00022 volume = value; 00023 if (volume < 0) 00024 { 00025 volume = 0; 00026 } 00027 else if (volume > 100) 00028 { 00029 volume = 100; 00030 } 00031 UpdateVolume(); 00032 00033 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 00034 controlLabel += "MixerVolume"; 00035 gContext->SaveSetting(controlLabel, volume); 00036 } 00037 00038 void VolumeBase::AdjustCurrentVolume(int change) 00039 { 00040 SetCurrentVolume(volume + change); 00041 } 00042 00043 void VolumeBase::SetMute(bool on) 00044 { 00045 if (on) 00046 { 00047 current_mute_state = MUTE_BOTH; 00048 } 00049 else 00050 { 00051 current_mute_state = MUTE_OFF; 00052 } 00053 UpdateVolume(); 00054 } 00055 00056 void VolumeBase::ToggleMute(void) 00057 { 00058 SetMute(current_mute_state == MUTE_OFF); 00059 } 00060 00061 kMuteState VolumeBase::GetMute(void) 00062 { 00063 return current_mute_state; 00064 } 00065 00066 kMuteState VolumeBase::IterateMutedChannels(void) 00067 { 00068 // mute states are checked in GetAudioData 00069 switch (current_mute_state) 00070 { 00071 case MUTE_OFF: 00072 current_mute_state = MUTE_LEFT; 00073 break; 00074 case MUTE_LEFT: 00075 current_mute_state = MUTE_RIGHT; 00076 break; 00077 case MUTE_RIGHT: 00078 current_mute_state = MUTE_BOTH; 00079 break; 00080 case MUTE_BOTH: 00081 current_mute_state = MUTE_OFF; 00082 break; 00083 } 00084 UpdateVolume(); 00085 return (current_mute_state); 00086 } 00087 00088 void VolumeBase::UpdateVolume(void) 00089 { 00090 int new_volume = volume; 00091 if (current_mute_state == MUTE_BOTH) 00092 { 00093 new_volume = 0; 00094 } 00095 00096 // TODO: Avoid assumption that there are 2 channels! 00097 for (int i = 0; i < 2; i++) 00098 { 00099 SetVolumeChannel(i, new_volume); 00100 } 00101 00102 // Individual channel muting is handled in GetAudioData, 00103 // this code demonstrates the old method. 00104 // if (current_mute_state == MUTE_LEFT) 00105 // { 00106 // SetVolumeChannel(0, 0); 00107 // } 00108 // else if (current_mute_state == MUTE_RIGHT) 00109 // { 00110 // SetVolumeChannel(1, 0); 00111 // } 00112 } 00113 00114 void VolumeBase::SyncVolume(void) 00115 { 00116 // Read the volume from the audio driver and setup our internal state to match 00117 volume = GetVolumeChannel(0); 00118 } 00119
1.5.5