00001 #include <cstdio> 00002 #include <cstdlib> 00003 00004 #include <algorithm> 00005 using namespace std; 00006 00007 #include <QString> 00008 00009 #include "volumebase.h" 00010 #include "mythcorecontext.h" 00011 00012 VolumeBase::VolumeBase() : 00013 volume(80), current_mute_state(kMuteOff) 00014 { 00015 internal_vol = gCoreContext->GetNumSetting("MythControlsVolume", 1); 00016 swvol = swvol_setting = 00017 (gCoreContext->GetSetting("MixerDevice", "default").toLower() == "software"); 00018 } 00019 00020 bool VolumeBase::SWVolume(void) const 00021 { 00022 return swvol; 00023 } 00024 00025 void VolumeBase::SWVolume(bool set) 00026 { 00027 if (swvol_setting) 00028 return; 00029 swvol = set; 00030 } 00031 00032 uint VolumeBase::GetCurrentVolume(void) const 00033 { 00034 return volume; 00035 } 00036 00037 void VolumeBase::SetCurrentVolume(int value) 00038 { 00039 volume = max(min(value, 100), 0); 00040 UpdateVolume(); 00041 00042 QString controlLabel = gCoreContext->GetSetting("MixerControl", "PCM"); 00043 controlLabel += "MixerVolume"; 00044 gCoreContext->SaveSetting(controlLabel, volume); 00045 } 00046 00047 void VolumeBase::AdjustCurrentVolume(int change) 00048 { 00049 SetCurrentVolume(volume + change); 00050 } 00051 00052 MuteState VolumeBase::SetMuteState(MuteState mstate) 00053 { 00054 current_mute_state = mstate; 00055 UpdateVolume(); 00056 return current_mute_state; 00057 } 00058 00059 void VolumeBase::ToggleMute(void) 00060 { 00061 bool is_muted = GetMuteState() == kMuteAll; 00062 SetMuteState((is_muted) ? kMuteOff : kMuteAll); 00063 } 00064 00065 MuteState VolumeBase::GetMuteState(void) const 00066 { 00067 return current_mute_state; 00068 } 00069 00070 MuteState VolumeBase::NextMuteState(MuteState cur) 00071 { 00072 MuteState next = cur; 00073 00074 switch (cur) 00075 { 00076 case kMuteOff: 00077 next = kMuteLeft; 00078 break; 00079 case kMuteLeft: 00080 next = kMuteRight; 00081 break; 00082 case kMuteRight: 00083 next = kMuteAll; 00084 break; 00085 case kMuteAll: 00086 next = kMuteOff; 00087 break; 00088 } 00089 00090 return (next); 00091 } 00092 00093 void VolumeBase::UpdateVolume(void) 00094 { 00095 int new_volume = volume; 00096 bool save = true; 00097 if (current_mute_state == kMuteAll) 00098 { 00099 new_volume = 0; 00100 save = false; 00101 } 00102 00103 if (swvol) 00104 { 00105 SetSWVolume(new_volume, save); 00106 return; 00107 } 00108 00109 for (int i = 0; i < channels; i++) 00110 { 00111 SetVolumeChannel(i, new_volume); 00112 } 00113 00114 // Individual channel muting is handled in GetAudioData, 00115 // this code demonstrates the old method. 00116 // if (current_mute_state == kMuteLeft) 00117 // { 00118 // SetVolumeChannel(0, 0); 00119 // } 00120 // else if (current_mute_state == kMuteRight) 00121 // { 00122 // SetVolumeChannel(1, 0); 00123 // } 00124 } 00125 00126 void VolumeBase::SyncVolume(void) 00127 { 00128 // Read the volume from the audio driver and setup our internal state to match 00129 if (swvol) 00130 volume = GetSWVolume(); 00131 else 00132 volume = GetVolumeChannel(0); 00133 } 00134 00135 void VolumeBase::SetChannels(int new_channels) 00136 { 00137 channels = new_channels; 00138 }
1.6.3