Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | 9fe374b | 2016-01-06 10:17:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 3 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 4 | * Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Alexandre Lision | 8521baa | 2015-03-13 11:08:00 -0400 | [diff] [blame] | 19 | */ |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 20 | #import "AudioPrefsVC.h" |
| 21 | |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 22 | //LRC |
| 23 | #import <api/avmodel.h> |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 24 | |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 25 | @interface AudioPrefsVC () |
| 26 | |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 27 | @property (assign) IBOutlet NSPopUpButton *outputDeviceList; |
| 28 | @property (assign) IBOutlet NSPopUpButton *inputDeviceList; |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 29 | @end |
| 30 | |
| 31 | @implementation AudioPrefsVC |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 32 | @synthesize outputDeviceList; |
| 33 | @synthesize inputDeviceList; |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 34 | @synthesize avModel; |
| 35 | QMetaObject::Connection audioDeviceEvent; |
| 36 | |
| 37 | -(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil avModel:(lrc::api::AVModel*) avModel |
| 38 | { |
| 39 | if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) |
| 40 | { |
| 41 | self.avModel = avModel; |
| 42 | } |
| 43 | return self; |
| 44 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 45 | |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 46 | - (void)loadView |
| 47 | { |
| 48 | [super loadView]; |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 49 | [self connectdDeviceEvent]; |
| 50 | [self addDevices]; |
| 51 | } |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 52 | |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 53 | -(void) addDevices { |
| 54 | [inputDeviceList removeAllItems]; |
| 55 | [outputDeviceList removeAllItems]; |
| 56 | auto inputDevices = avModel->getAudioInputDevices(); |
| 57 | auto inputDevice = avModel->getInputDevice(); |
| 58 | for (auto device : inputDevices) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 59 | [inputDeviceList addItemWithTitle: device.toNSString()]; |
Kateryna Kostiuk | 3cbc166 | 2019-07-18 14:57:53 -0400 | [diff] [blame] | 60 | if(device == inputDevice) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 61 | [inputDeviceList selectItemWithTitle:inputDevice.toNSString()]; |
Kateryna Kostiuk | 3cbc166 | 2019-07-18 14:57:53 -0400 | [diff] [blame] | 62 | } |
Kateryna Kostiuk | 74fe20c | 2018-06-14 12:05:53 -0400 | [diff] [blame] | 63 | } |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 64 | auto outputDevices = avModel->getAudioOutputDevices(); |
| 65 | auto outputDevice = avModel->getOutputDevice(); |
| 66 | for (auto device : outputDevices) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 67 | [outputDeviceList addItemWithTitle: device.toNSString()]; |
Kateryna Kostiuk | 3cbc166 | 2019-07-18 14:57:53 -0400 | [diff] [blame] | 68 | if(device == outputDevice) { |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 69 | [outputDeviceList selectItemWithTitle:outputDevice.toNSString()]; |
Kateryna Kostiuk | 3cbc166 | 2019-07-18 14:57:53 -0400 | [diff] [blame] | 70 | } |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 71 | } |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 74 | -(void)connectdDeviceEvent { |
| 75 | QObject::disconnect(audioDeviceEvent); |
| 76 | audioDeviceEvent = QObject::connect(avModel, |
| 77 | &lrc::api::AVModel::deviceEvent, |
| 78 | [=]() { |
Kateryna Kostiuk | 3cbc166 | 2019-07-18 14:57:53 -0400 | [diff] [blame] | 79 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, |
| 80 | 1 * NSEC_PER_SEC), |
| 81 | dispatch_get_main_queue(), ^{ |
| 82 | [self addDevices]; |
| 83 | }); |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 84 | }); |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | - (IBAction)chooseOutput:(id)sender { |
| 88 | int index = [sender indexOfSelectedItem]; |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 89 | auto output = [self.outputDeviceList itemTitleAtIndex:index]; |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 90 | avModel->setOutputDevice(QString::fromNSString(output)); |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | - (IBAction)chooseInput:(id)sender { |
| 94 | int index = [sender indexOfSelectedItem]; |
Kateryna Kostiuk | 5d90c3b | 2019-07-18 12:03:52 -0400 | [diff] [blame] | 95 | auto input = [self.inputDeviceList itemTitleAtIndex:index]; |
Kateryna Kostiuk | c867eb9 | 2020-03-08 13:15:17 -0400 | [diff] [blame] | 96 | avModel->setInputDevice(QString::fromNSString(input)); |
Alexandre Lision | 611b8c1 | 2015-03-20 18:07:17 -0400 | [diff] [blame] | 97 | } |
Alexandre Lision | 4a7b95e | 2015-02-20 10:06:43 -0500 | [diff] [blame] | 98 | |
| 99 | @end |