Skip to content

Commit

Permalink
Added options page
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyCorbett committed Aug 28, 2017
1 parent 7ccfc85 commit 905f450
Show file tree
Hide file tree
Showing 40 changed files with 1,231 additions and 281 deletions.
Binary file added MasterImages/BackButton.ico
Binary file not shown.
Binary file added MasterImages/BackButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MasterImages/SettingsButton.ico
Binary file not shown.
Binary file added MasterImages/SettingsButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions OnlyR.Core/Models/RecordingDeviceInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Core.Models
{
public class RecordingDeviceInfo
{
public int Id { get; set; }
public string Name { get; set; }
}
}
2 changes: 2 additions & 0 deletions OnlyR.Core/OnlyR.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
<ItemGroup>
<Compile Include="EventArgs\SamplesReportEventArgs.cs" />
<Compile Include="EventArgs\RecordingProgressEventArgs.cs" />
<Compile Include="Models\RecordingDeviceInfo.cs" />
<Compile Include="Recorder\AudioRecorder.cs" />
<Compile Include="Enums\RecordingStatus.cs" />
<Compile Include="EventArgs\RecordingStatusChangeEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Recorder\NoDevicesException.cs" />
<Compile Include="Recorder\RecordingConfig.cs" />
<Compile Include="Samples\SampleAggregator.cs" />
</ItemGroup>
Expand Down
34 changes: 33 additions & 1 deletion OnlyR.Core/Recorder/AudioRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using NAudio.CoreAudioApi;
using NAudio.Lame;
using NAudio.Wave;
using OnlyR.Core.Enums;
using OnlyR.Core.EventArgs;
using OnlyR.Core.Models;
using OnlyR.Core.Samples;

namespace OnlyR.Core.Recorder
Expand Down Expand Up @@ -63,10 +66,12 @@ public void Start(RecordingConfig recordingConfig)
if (_recordingStatus == RecordingStatus.NotRecording)
{
InitAggregator(recordingConfig.SampleRate);
CheckRecordingDevice(recordingConfig);

_waveSource = new WaveIn
{
WaveFormat = new WaveFormat(recordingConfig.SampleRate, recordingConfig.ChannelCount)
WaveFormat = new WaveFormat(recordingConfig.SampleRate, recordingConfig.ChannelCount),
DeviceNumber = recordingConfig.RecordingDevice
};

_waveSource.DataAvailable += WaveSourceDataAvailableHandler;
Expand All @@ -80,6 +85,20 @@ public void Start(RecordingConfig recordingConfig)
}
}

private static void CheckRecordingDevice(RecordingConfig recordingConfig)
{
int deviceCount = WaveIn.DeviceCount;
if(deviceCount == 0)
{
throw new NoDevicesException();
}

if(recordingConfig.RecordingDevice >= deviceCount)
{
recordingConfig.RecordingDevice = 0;
}
}

private void InitAggregator(int sampleRate)
{
if (_sampleAggregator != null)
Expand Down Expand Up @@ -154,5 +173,18 @@ private int GetDampedVolumeLevel(float volLevel)
return _dampedLevel;
}

public static IEnumerable<RecordingDeviceInfo> GetRecordingDeviceList()
{
List<RecordingDeviceInfo> result = new List<RecordingDeviceInfo>();

int count = WaveIn.DeviceCount;
for(int n=0; n<count; ++n)
{
var caps = WaveIn.GetCapabilities(n);
result.Add(new RecordingDeviceInfo { Id = n, Name = caps.ProductName });
}

return result;
}
}
}
18 changes: 18 additions & 0 deletions OnlyR.Core/Recorder/NoDevicesException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Core.Recorder
{
[Serializable]
public class NoDevicesException : Exception
{
public NoDevicesException()
: base("No recording devices found")
{

}
}
}
1 change: 1 addition & 0 deletions OnlyR.Core/Recorder/RecordingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace OnlyR.Core.Recorder
{
public class RecordingConfig
{
public int RecordingDevice { get; set; }
public DateTime RecordingDate { get; set; }
public int TrackNumber { get; set; }
public string DestFilePath { get; set; }
Expand Down
17 changes: 16 additions & 1 deletion OnlyR/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Threading;
using System.Windows;
using AutoMapper;
using OnlyR.Model;
using OnlyR.Utils;
using Serilog;

Expand Down Expand Up @@ -30,9 +33,19 @@ protected override void OnStartup(StartupEventArgs e)
.CreateLogger();

Log.Logger.Information("==== Launched ====");

ConfigureAutoMapper();
}
}

private static void ConfigureAutoMapper()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<ObjectMappingProfile>();
});
}

private bool AnotherInstanceRunning()
{
_appMutex = new Mutex(true, _appString, out var newInstance);
Expand All @@ -41,7 +54,9 @@ private bool AnotherInstanceRunning()

protected override void OnExit(ExitEventArgs e)
{
_appMutex?.Dispose();
Log.Logger.Information("==== Exit ====");
}

}
}
Binary file added OnlyR/Images/BackButton.ico
Binary file not shown.
Binary file added OnlyR/Images/SettingsButton.ico
Binary file not shown.
50 changes: 4 additions & 46 deletions OnlyR/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:volumeMeter="clr-namespace:OnlyR.VolumeMeter"
x:Class="OnlyR.MainWindow"
mc:Ignorable="d"
DataContext="{Binding Main, Mode=OneWay, Source={StaticResource Locator}}"
Title="O N L Y - R" Height="292" Width="268" ResizeMode="CanMinimize" Closing="Window_Closing">

<Window.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis" />

<Style x:Key="RecorderBtnStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="85" />
<Setter Property="Grid.Column" Value="1" />
<Setter Property="Grid.Row" Value="0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Margin" Value="10,10,10,0" />
<Setter Property="VerticalAlignment" Value="Top" />
</Style>
</Window.Resources>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="86*"/>
<ColumnDefinition Width="235*"/>
</Grid.ColumnDefinitions>

<Button Style="{StaticResource RecorderBtnStyle}"
Visibility="{Binding Path=IsNotRecording, Converter={StaticResource BoolToVis}}"
Command="{Binding StartRecordingCommand}" >
<Image Source="Images\StartButton3.ico" Margin="10"></Image>
</Button>

<!-- ReSharper disable once Xaml.MissingGridIndex -->
<Button Style="{StaticResource RecorderBtnStyle}"
Visibility="{Binding Path=IsRecordingOrStopping, Converter={StaticResource BoolToVis}}"
Command="{Binding StopRecordingCommand}" >
<Image Source="Images\StopButton3.ico" Margin="10"></Image>
</Button>

<volumeMeter:VduControl Margin="10" Grid.Column="0" Grid.Row="0"
VolumeLevel="{Binding VolumeLevelAsPercentage, Mode=OneWay}"/>

<Border Grid.Column="1" BorderThickness="2" BorderBrush="#FFF19C7C" Margin="10,100,10,10" Padding="4">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" Text="{Binding StatusStr}" Foreground="CadetBlue"/>
<TextBlock TextWrapping="Wrap" Text="{Binding ElapsedTimeStr}" FontSize="32"/>
</StackPanel>
</Border>
</Grid>
Title="O N L Y - R" Height="286" Width="268" ResizeMode="CanMinimize" Closing="Window_Closing">

<ContentControl Content="{Binding CurrentPage}" />

</Window>
14 changes: 14 additions & 0 deletions OnlyR/Model/BitRateItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Model
{
public class BitRateItem
{
public string Name { get; set; }
public int ActualBitRate { get; set; }
}
}
14 changes: 14 additions & 0 deletions OnlyR/Model/ChannelItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Model
{
public class ChannelItem
{
public string Name { get; set; }
public int ChannelCount { get; set; }
}
}
14 changes: 14 additions & 0 deletions OnlyR/Model/MaxRecordingTimeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Model
{
public class MaxRecordingTimeItem
{
public string Name { get; set; }
public int ActualMinutes { get; set; }
}
}
26 changes: 26 additions & 0 deletions OnlyR/Model/ObjectMappingProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OnlyR.Core.Models;

namespace OnlyR.Model
{
/// <summary>
/// Used to configure all mappings between 'data' objects. AutoMapper is a general-purpose data mapper
/// that we use to map models between layers
/// </summary>

internal class ObjectMappingProfile : AutoMapper.Profile
{
public ObjectMappingProfile()
{
// CreateMap<source, dest>();

CreateMap<RecordingDeviceInfo, RecordingDeviceItem>()
.ForMember(dest => dest.DeviceId, opts => opts.MapFrom(src => src.Id))
.ForMember(dest => dest.DeviceName, opts => opts.MapFrom(src => src.Name));
}
}
}
14 changes: 14 additions & 0 deletions OnlyR/Model/RecordingDeviceItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Model
{
public class RecordingDeviceItem
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
}
}
14 changes: 14 additions & 0 deletions OnlyR/Model/SampleRateItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlyR.Model
{
public class SampleRateItem
{
public string Name { get; set; }
public int ActualSampleRate { get; set; }
}
}
34 changes: 34 additions & 0 deletions OnlyR/OnlyR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=6.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.1.1\lib\net45\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -122,7 +125,20 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Model\BitRateItem.cs" />
<Compile Include="Model\ChannelItem.cs" />
<Compile Include="Model\MaxRecordingTimeItem.cs" />
<Compile Include="Model\ObjectMappingProfile.cs" />
<Compile Include="Model\RecordingCandidate.cs" />
<Compile Include="Model\RecordingDeviceItem.cs" />
<Compile Include="Model\SampleRateItem.cs" />
<Compile Include="Pages\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModel\IPage.cs" />
<Compile Include="Pages\RecordingPage.xaml.cs">
<DependentUpon>RecordingPage.xaml</DependentUpon>
</Compile>
<Compile Include="Services\Audio\AudioService.cs" />
<Compile Include="Services\Audio\IAudioService.cs" />
<Compile Include="Services\Options\IOptionsService.cs" />
Expand All @@ -136,6 +152,10 @@
<Compile Include="Utils\FileUtils.cs" />
<Compile Include="Utils\NativeMethods.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\Messages\NavigateMessage.cs" />
<Compile Include="ViewModel\RecordingPageViewModel.cs" />
<Compile Include="ViewModel\Messages\ShutDownMessage.cs" />
<Compile Include="ViewModel\SettingsPageViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="VolumeMeter\VduControl.cs" />
<Page Include="MainWindow.xaml">
Expand All @@ -150,6 +170,14 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Pages\RecordingPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\SettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -208,5 +236,11 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\SettingsButton.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\BackButton.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit 905f450

Please sign in to comment.