|
@@ -14,7 +14,6 @@
|
|
|
#import <AVFoundation/AVFoundation.h>
|
|
|
#import "TunerSettingView.h"
|
|
|
#import "KSChoosePicker.h"
|
|
|
-//#import "KSGaugeView.h"
|
|
|
|
|
|
@interface ToneTuningViewController ()<TunerDelegate>
|
|
|
|
|
@@ -49,6 +48,9 @@
|
|
|
|
|
|
@property (nonatomic, strong) NSArray *picthDescArray;
|
|
|
|
|
|
+// A4 频率
|
|
|
+@property (nonatomic, assign) NSInteger A4Frequence;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation ToneTuningViewController
|
|
@@ -64,6 +66,7 @@
|
|
|
|
|
|
- (void)configDefault {
|
|
|
self.chooseFrequence = 440;
|
|
|
+ self.A4Frequence = 440;
|
|
|
self.isTransfer = NO;
|
|
|
}
|
|
|
|
|
@@ -94,17 +97,12 @@
|
|
|
}];
|
|
|
|
|
|
[self.view addSubview:self.bodyView];
|
|
|
- self.bodyView.A4Frequence = self.chooseFrequence;
|
|
|
+ self.bodyView.A4Frequence = self.A4Frequence;
|
|
|
[self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
make.left.right.mas_equalTo(self.view);
|
|
|
make.top.mas_equalTo(self.navView.mas_bottom);
|
|
|
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
|
|
|
}];
|
|
|
-// KSGaugeView *gaugeView = [[KSGaugeView alloc] init];
|
|
|
-// [self.bodyView.plateView addSubview:gaugeView];
|
|
|
-// [gaugeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
-// make.top.bottom.left.right.mas_equalTo(self.bodyView.plateView);
|
|
|
-// }];
|
|
|
[self.bodyView.plateView addSubview:self.plateView];
|
|
|
[self.plateView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
make.top.bottom.left.right.mas_equalTo(self.bodyView.plateView);
|
|
@@ -179,29 +177,29 @@
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
-// if (fabs(output.distance) > 1) {
|
|
|
- self.plateView.gaugeView.value = (NSInteger)output.distance;
|
|
|
- self.bodyView.distance = (NSInteger)output.distance;
|
|
|
-// }
|
|
|
-
|
|
|
-// [self.plateView.gaugeView setValue:output.distance animated:YES];
|
|
|
|
|
|
+ TunerOutput *transferOutput = [tuner getTransferPitchWithA4Frequency:self.A4Frequence toneChangeRate:self.toneChangeRate output:output];
|
|
|
+
|
|
|
+ self.plateView.gaugeView.value = (NSInteger)transferOutput.distance;
|
|
|
+ self.bodyView.distance = (NSInteger)transferOutput.distance;
|
|
|
|
|
|
// 调整频率后
|
|
|
-
|
|
|
+
|
|
|
if (self.isTransfer == NO) {
|
|
|
+
|
|
|
self.bodyView.nomalPitch.text = output.pitch;
|
|
|
self.bodyView.pitchFrequenceLabel.text = [NSString stringWithFormat:@"%@%zd:%.0fHz", output.pitch, output.octave, output.frequency];
|
|
|
self.bodyView.preFrequence.text = [NSString stringWithFormat:@"%@%zd",output.prePitch, output.preOctave];
|
|
|
self.bodyView.nextFrequence.text = [NSString stringWithFormat:@"%@%zd",output.nextPitch, output.nextOctave];
|
|
|
}
|
|
|
else {
|
|
|
- self.bodyView.transferNomalPitch.text = output.pitch;
|
|
|
+
|
|
|
+ self.bodyView.transferNomalPitch.text = transferOutput.pitch;
|
|
|
self.bodyView.transferDesc.text = self.settingView.transferPicthDesc;
|
|
|
-// self.bodyView.transferPitch.text =
|
|
|
- self.bodyView.pitchFrequenceLabel.text = [NSString stringWithFormat:@"%@%zd:%.0fHz", output.pitch, output.octave, output.frequency];
|
|
|
- self.bodyView.preFrequence.text = [NSString stringWithFormat:@"%@%zd",output.prePitch, output.preOctave];
|
|
|
- self.bodyView.nextFrequence.text = [NSString stringWithFormat:@"%@%zd",output.nextPitch, output.nextOctave];
|
|
|
+ self.bodyView.transferPitch.text = [NSString stringWithFormat:@"%@",transferOutput.transferPitch];
|
|
|
+ self.bodyView.pitchFrequenceLabel.text = [NSString stringWithFormat:@"%@%zd:%.0fHz", transferOutput.transferPitch, transferOutput.transferOctave, transferOutput.frequency];
|
|
|
+ self.bodyView.preFrequence.text = [NSString stringWithFormat:@"%@%zd",transferOutput.prePitch, transferOutput.preOctave];
|
|
|
+ self.bodyView.nextFrequence.text = [NSString stringWithFormat:@"%@%zd",transferOutput.nextPitch, transferOutput.nextOctave];
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -231,9 +229,14 @@
|
|
|
break;
|
|
|
case TUNINGACTION_FREQUENCE: // 调整频率
|
|
|
{
|
|
|
- self.chooseFrequence = frequence;
|
|
|
+ self.A4Frequence = frequence;
|
|
|
self.settingView.A4Frequence = frequence;
|
|
|
self.tuner.A4Frequence = frequence;
|
|
|
+ self.forkView.A4Frequence = frequence;
|
|
|
+ if (self.bodyView.isPlaying) {
|
|
|
+ CGFloat changefrequence = frequence / 440.0 * self.chooseFrequence;
|
|
|
+ [self.forkManager changeFrequenceWithFrequence:changefrequence];
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case TUNINGACTION_PLAY: // 播放音叉
|
|
@@ -252,7 +255,9 @@
|
|
|
}
|
|
|
|
|
|
- (void)startForkPlay {
|
|
|
- [self.forkManager setupWithFrequence:self.chooseFrequence];
|
|
|
+
|
|
|
+ CGFloat changefrequence = self.A4Frequence / 440.0 * self.chooseFrequence;
|
|
|
+ [self.forkManager setupWithFrequence:changefrequence];
|
|
|
}
|
|
|
|
|
|
- (void)stopForkPlay {
|
|
@@ -273,13 +278,24 @@
|
|
|
_forkView = [TuningForkSettingView shareInstance];
|
|
|
_forkView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
|
|
|
MJWeakSelf;
|
|
|
- [_forkView forkSettingAction:^(NSInteger frequence) {
|
|
|
+ [_forkView forkSettingAction:^(NSInteger frequence, BOOL isSure) {
|
|
|
NSLog(@"----- frequence %zd", frequence);
|
|
|
+
|
|
|
weakSelf.chooseFrequence = frequence;
|
|
|
- if (weakSelf.forkManager.isPlay) {
|
|
|
- [weakSelf.forkManager changeFrequenceWithFrequence:frequence];
|
|
|
+ if (weakSelf.bodyView.isPlaying) {
|
|
|
+ CGFloat changefrequence = frequence / 440.0 * self.A4Frequence;
|
|
|
+ [weakSelf.forkManager changeFrequenceWithFrequence:changefrequence];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (isSure) {
|
|
|
+ [weakSelf stopForkPlay];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf startForkPlay];
|
|
|
+ }
|
|
|
}
|
|
|
}];
|
|
|
+
|
|
|
}
|
|
|
return _forkView;
|
|
|
}
|
|
@@ -294,7 +310,7 @@
|
|
|
- (TunerSettingView *)settingView {
|
|
|
if (!_settingView) {
|
|
|
_settingView = [TunerSettingView shareInstance];
|
|
|
- _settingView.A4Frequence = self.chooseFrequence;
|
|
|
+ _settingView.A4Frequence = self.A4Frequence;
|
|
|
_settingView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
|
|
|
MJWeakSelf;
|
|
|
[_settingView tunerSettingAction:^(TUNETSETTING_ACTION action, NSInteger toneChangeRate, NSInteger frequence) {
|
|
@@ -312,6 +328,7 @@
|
|
|
self.instrumentPicker = [[KSChoosePicker alloc] initWithTitle:@"" sourceData:self.instrumentArray chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
|
|
|
weakSelf.settingView.instrumentLabel.text = returnValue;
|
|
|
NSInteger pitchRate = [self.picthRateArray[chooseIndex] integerValue];
|
|
|
+ weakSelf.A4Frequence = frequence;
|
|
|
weakSelf.settingView.toneChangeRate = pitchRate;
|
|
|
weakSelf.settingView.transferPicthDesc = self.picthDescArray[chooseIndex];
|
|
|
} cancel:^{
|
|
@@ -321,10 +338,15 @@
|
|
|
}
|
|
|
else if (action == TUNETSETTING_ACTION_SURE) {
|
|
|
// 设置成功
|
|
|
- self.chooseFrequence = frequence;
|
|
|
+ self.A4Frequence = frequence;
|
|
|
self.bodyView.A4Frequence = frequence;
|
|
|
self.toneChangeRate = toneChangeRate;
|
|
|
self.tuner.A4Frequence = frequence;
|
|
|
+ self.forkView.A4Frequence = frequence;
|
|
|
+ if (self.bodyView.isPlaying) {
|
|
|
+ CGFloat changefrequence = frequence / 440.0 * self.chooseFrequence;
|
|
|
+ [self.forkManager changeFrequenceWithFrequence:changefrequence];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -337,14 +359,14 @@
|
|
|
|
|
|
- (NSArray *)picthRateArray {
|
|
|
if (!_picthRateArray) {
|
|
|
- _picthRateArray = @[@0,@1,@8,@1,@0,@-12,@1,@0,@-5,@1,@0,@1];
|
|
|
+ _picthRateArray = @[@0,@-2,@-9,@-2,@0,@-12,@-2,@0,@5,@-2,@0,@-2];
|
|
|
}
|
|
|
return _picthRateArray;
|
|
|
}
|
|
|
|
|
|
- (NSArray *)picthDescArray {
|
|
|
if (!_picthDescArray) {
|
|
|
- _picthDescArray = @[@"C ins.",@"B ins.",@"E ins.",@"B ins.",@"C ins.",@"C调大调 ins.",@"B ins.",@"C ins.",@"F ins.",@"C ins.",@"B ins."];
|
|
|
+ _picthDescArray = @[@"C ins.",@"B♭ ins.",@"E♭ ins.",@"B♭ ins.",@"C ins.",@"C调大调 ins.",@"B♭ ins.",@"C ins.",@"F ins.",@"C ins.",@"B♭ ins."];
|
|
|
}
|
|
|
return _picthDescArray;
|
|
|
}
|