Files
midi_ios/QXLive/HomePage(声播)/View/房间/设置/QXSingerConfigView.m
2025-08-14 10:07:49 +08:00

397 lines
16 KiB
Objective-C

//
// QXSingerConfigView.m
// QXLive
//
// Created by 启星 on 2025/6/19.
//
#import "QXSingerConfigView.h"
#import "QXAgoraEngine.h"
@interface QXSingerConfigView()<UIGestureRecognizerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *earLabel;
@property (nonatomic,strong)UISwitch *earSwitch;
@property (nonatomic,strong)UILabel *voiceLabel;
@property (nonatomic,strong)QXSliser *voiceSliser;
@property (nonatomic,strong)UILabel *musicLabel;
@property (nonatomic,strong)QXSliser *musicSliser;
/// 混响
@property (nonatomic,strong)UILabel *effectLabel;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)NSArray *audioArray;
@property (nonatomic,strong)QXRoomSettingModel *audioModel;
///变声
@property (nonatomic,strong)UILabel *voiceEffectLabel;
@property (nonatomic,strong)NSArray *voiceArray;
@end
@implementation QXSingerConfigView
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
tap.delegate = self;
[self addGestureRecognizer:tap];
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 350)];
// self.bgView.backgroundColor = [UIColor whiteColor];
[self addSubview:self.bgView];
self.bgImageView = [[UIImageView alloc] initWithFrame:self.bgView.bounds];
self.bgImageView.image = [UIImage imageNamed:@"room_sound_bg"];
[self.bgView addSubview:self.bgImageView];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 118, 24)];
self.titleLabel.font = [UIFont systemFontOfSize:16];
self.titleLabel.textColor = RGB16A(0xffffff, 1);
self.titleLabel.text = QXText(@"调音台");
[self.bgView addSubview:self.titleLabel];
self.earSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.bgView.width-16-45, 0, 45, 45)];
self.earSwitch.centerY = self.titleLabel.centerY;
self.earSwitch.onTintColor = QXConfig.themeColor;
self.earSwitch.thumbTintColor = [UIColor whiteColor];
self.earSwitch.backgroundColor = RGB16A(0xffffff, 0.2);
[self.earSwitch addRoundedCornersWithRadius:15];
[self.earSwitch addTarget:self action:@selector(earAction:) forControlEvents:(UIControlEventValueChanged)];
self.earSwitch.on = [[QXAgoraEngine sharedEngine] ktv_GetErfan];
[self.bgView addSubview:self.earSwitch];
self.earLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.earSwitch.left-100, 0, 90, 20)];
self.earLabel.centerY = self.titleLabel.centerY;
self.earLabel.textAlignment = NSTextAlignmentRight;
self.earLabel.font = [UIFont systemFontOfSize:14];
self.earLabel.text = QXText(@"耳返");
self.earLabel.textColor = RGB16A(0xffffff, 1);
[self.bgView addSubview:self.earLabel];
self.voiceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.titleLabel.bottom+20, 160, 21)];
self.voiceLabel.font = [UIFont systemFontOfSize:14];
self.voiceLabel.text = QXText(@"人声 100%");
self.voiceLabel.textColor = RGB16A(0xffffff, 1);
[self.bgView addSubview:self.voiceLabel];
self.voiceSliser = [[QXSliser alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.voiceLabel.bottom+8, self.bgView.width-32, 18)];
self.voiceSliser.minimumValue = 0;
self.voiceSliser.maximumValue = 100;
self.voiceSliser.value = 100;
self.voiceSliser.minimumTrackTintColor = QXConfig.themeColor;
self.voiceSliser.maximumTrackTintColor = [UIColor whiteColor];
self.voiceSliser.thumbTintColor = QXConfig.themeColor;
[self.voiceSliser addTarget:self action:@selector(voiceSliderAction:) forControlEvents:(UIControlEventValueChanged)];
[self.bgView addSubview:self.voiceSliser];
self.musicLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.voiceSliser.bottom+12, 160, 21)];
self.musicLabel.font = [UIFont systemFontOfSize:14];
float musicVolume = [[QXAgoraEngine sharedEngine] ktv_GetBanzouVolume];
self.musicLabel.text = [NSString stringWithFormat:@"%@ %d",QXText(@"伴奏"),(int)musicVolume*100];
self.musicLabel.textColor = RGB16A(0xffffff, 1);
[self.bgView addSubview:self.musicLabel];
self.musicSliser = [[QXSliser alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.musicLabel.bottom+8, self.bgView.width-32, 18)];
[self.musicSliser addTarget:self action:@selector(musicSliderAction:) forControlEvents:(UIControlEventValueChanged)];
self.musicSliser.minimumValue = 0;
self.musicSliser.maximumValue = 100;
self.musicSliser.value = musicVolume*100;
self.musicSliser.minimumTrackTintColor = QXConfig.themeColor;
self.musicSliser.maximumTrackTintColor = [UIColor whiteColor];
self.musicSliser.thumbTintColor = QXConfig.themeColor;
[self.bgView addSubview:self.musicSliser];
self.effectLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 160, 21)];
self.effectLabel.font = [UIFont systemFontOfSize:14];
self.effectLabel.text = [NSString stringWithFormat:@"%@",QXText(@"混响")];
self.effectLabel.textColor = RGB16A(0xffffff, 1);
// [self.bgView addSubview:self.effectLabel];
QXRoomSettingModel *md1 = [[QXRoomSettingModel alloc] init];
md1.name = @"原声";
md1.icon = @"room_voice_normal";
QXRoomSettingModel *md2 = [[QXRoomSettingModel alloc] init];
md2.name = @"唱片机";
md2.icon = @"room_voice_record";
QXRoomSettingModel *md3 = [[QXRoomSettingModel alloc] init];
md3.name = @"三维声音";
md3.icon = @"room_voice_3d";
QXRoomSettingModel *md4 = [[QXRoomSettingModel alloc] init];
md4.name = @"虚拟环绕";
md4.icon = @"room_voice_cycle";
QXRoomSettingModel *md5 = [[QXRoomSettingModel alloc] init];
md5.name = @"KTV";
md5.icon = @"room_voice_ktv";
// self.audioArray = @[md1,md2,md3,md4,md5];
self.audioArray = @[md1,md2,md5];
QXRoomSettingModel *md6 = [[QXRoomSettingModel alloc] init];
md6.name = @"老人";
md6.icon = @"room_voice_oldman";
QXRoomSettingModel *md7 = [[QXRoomSettingModel alloc] init];
md7.name = @"猪八戒";
md7.icon = @"room_voice_pig";
QXRoomSettingModel *md8 = [[QXRoomSettingModel alloc] init];
md8.name = @"三维声音";
md8.icon = @"room_voice_uncal";
QXRoomSettingModel *md9 = [[QXRoomSettingModel alloc] init];
md9.name = @"姐姐";
md9.icon = @"room_voice_sister";
QXRoomSettingModel *md10 = [[QXRoomSettingModel alloc] init];
md10.name = @"女孩";
md10.icon = @"room_voice_girl";
self.voiceArray = @[md6,md7,md8,md9,md10];
// CGFloat itemWidth = (SCREEN_WIDTH - 11*4-32)/5.0;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// layout.itemSize = CGSizeMake(itemWidth, ScaleWidth(54));
layout.minimumLineSpacing = 11;
layout.minimumInteritemSpacing = 11;
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
layout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 30);
layout.footerReferenceSize = CGSizeZero;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.musicSliser.bottom+12, self.bgView.width , self.bgView.height-self.effectLabel.bottom-12) collectionViewLayout:layout];
[self.collectionView registerClass:[QXVoiceEffectCell class] forCellWithReuseIdentifier:@"QXVoiceEffectCell"];
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
[self.bgView addSubview:self.collectionView];
self.voiceEffectLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 160, 30)];
self.voiceEffectLabel.font = [UIFont systemFontOfSize:14];
self.voiceEffectLabel.text = [NSString stringWithFormat:@"%@",QXText(@"混响")];
self.voiceEffectLabel.textColor = RGB16A(0xffffff, 1);
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if (section == 0) {
return self.audioArray.count;
}else{
return self.voiceArray.count;
}
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXVoiceEffectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXVoiceEffectCell" forIndexPath:indexPath];
if (indexPath.section == 0) {
cell.model = self.audioArray[indexPath.row];
}else{
cell.model = self.voiceArray[indexPath.row];
}
return cell;
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
if (indexPath.section == 0) {
[header addSubview:self.effectLabel];
}else{
[header addSubview:self.voiceEffectLabel];
}
return header;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat itemWidth = (SCREEN_WIDTH - 11*4-32)/5.0;
if (indexPath.section == 0) {
return CGSizeMake(itemWidth, ScaleWidth(54));;
}
return CGSizeMake(itemWidth, ScaleWidth(69));;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
QXRoomSettingModel *model;
if (indexPath.section == 0) {
if (indexPath.row == 0) {
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetOff];
}else if(indexPath.row == 1){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetRoomAcousPhonograph];
}else if(indexPath.row == 2){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetRoomAcous3DVoice];
}else if(indexPath.row == 3){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetRoomAcousVirtualSurroundSound];
}else if(indexPath.row == 4){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetRoomAcousticsKTV];
}
model = self.audioArray[indexPath.row];
}else{
if (indexPath.row == 0) {
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetVoiceChangerEffectOldMan];
}else if(indexPath.row == 1){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetVoiceChangerEffectPigKin];
}else if(indexPath.row == 2){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetVoiceChangerEffectUncle];
}else if(indexPath.row == 3){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetVoiceChangerEffectBoy];
}else if(indexPath.row == 4){
[[QXAgoraEngine sharedEngine].agoraKit setAudioEffectPreset:AgoraAudioEffectPresetVoiceChangerEffectGirl];
}
model = self.voiceArray[indexPath.row];
}
if (model.isSelected) {
return;
}else{
self.audioModel.isSelected = NO;
model.isSelected = YES;
self.audioModel = model;
}
[collectionView reloadData];
// self.audioModel
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
return touch.view == self;
}
-(void)earAction:(UISwitch*)sender{
if (sender.isOn) {
[sender setOn:YES animated:YES];
[[QXAgoraEngine sharedEngine] ktv_SetErfan:YES];
}else{
[sender setOn:NO animated:YES];
[[QXAgoraEngine sharedEngine] ktv_SetErfan:NO];
}
}
-(void)voiceSliderAction:(QXSliser*)slider{
self.voiceLabel.text = [NSString stringWithFormat:@"人声 %d%%",(int)slider.value];
[[QXAgoraEngine sharedEngine] ktv_SetRenshengVolume:slider.value/100.0];
}
-(void)musicSliderAction:(QXSliser*)slider{
self.musicLabel.text = [NSString stringWithFormat:@"伴奏 %d%%",(int)slider.value];
[[QXAgoraEngine sharedEngine] ktv_SetBanzouVolume:slider.value/100.0];
}
-(void)showInView:(UIView *)view{
[view addSubview:self];
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT-350;
}];
}
-(void)hide{
[UIView animateWithDuration:0.3 animations:^{
self.bgView.y = SCREEN_HEIGHT;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
@end
@implementation QXSliser
-(CGRect)trackRectForBounds:(CGRect)bounds{
bounds.size.height=self.frame.size.height;
self.layer.cornerRadius = self.frame.size.height/2;
bounds.origin.y = 0;
return bounds;
}
//-(CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value{
// bounds.origin.x = -5;
// return bounds;
//}
@end
@implementation QXVoiceEffectCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self initSubviews];
}
return self;
}
-(void)setModel:(QXRoomSettingModel *)model{
_model = model;
self.titleLabel.text = model.name;
self.effectImageView.image = [UIImage imageNamed:model.icon];
self.selecteBtn.hidden = !model.isSelected;
self.coverView.hidden = model.isSelected;
}
-(void)initSubviews{
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont systemFontOfSize:14];
self.titleLabel.textColor = [UIColor whiteColor];
[self.contentView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.centerY.equalTo(self.contentView);
}];
self.effectImageView = [[UIImageView alloc] init];
// self.effectImageView.backgroundColor = [UIColor redColor];
[self.effectImageView addRoundedCornersWithRadius:12];
[self.contentView addSubview:self.effectImageView];
[self.effectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.equalTo(self.contentView);
}];
self.coverView = [[UIView alloc] init];
self.coverView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];
[self.coverView addRoundedCornersWithRadius:12];
[self.contentView addSubview:self.coverView];
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.equalTo(self.contentView);
}];
self.selecteBtn = [[UIButton alloc] init];
// [self.selecteBtn setImage:[UIImage imageNamed:@"login_agreement_nor"] forState:(UIControlStateNormal)];
[self.selecteBtn setImage:[UIImage imageNamed:@"login_agreement_sel"] forState:(UIControlStateNormal)];
self.selecteBtn.userInteractionEnabled = NO;
[self.contentView addSubview:self.selecteBtn];
[self.selecteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(20, 20));
make.top.mas_equalTo(4);
make.right.mas_equalTo(-4);
}];
}
@end