diff --git a/Mobile/NUI/Piano/.gitignore b/Mobile/NUI/Piano/.gitignore new file mode 100755 index 00000000..e553c746 --- /dev/null +++ b/Mobile/NUI/Piano/.gitignore @@ -0,0 +1,180 @@ +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.DotSettings + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# .NET Core +*.project.lock.json +*.project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + + +### Android START ### +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +### Android Patch ### +gen-external-apklibs + + +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ +/captures + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + +### Android END ### + +### Resharper ### + +_Resharper* \ No newline at end of file diff --git a/Mobile/NUI/Piano/LICENSE b/Mobile/NUI/Piano/LICENSE new file mode 100755 index 00000000..70b133e5 --- /dev/null +++ b/Mobile/NUI/Piano/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2017 Samsung + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano.sln b/Mobile/NUI/Piano/Piano.sln new file mode 100755 index 00000000..ef7943a7 --- /dev/null +++ b/Mobile/NUI/Piano/Piano.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32929.386 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piano.Tizen.Mobile", "Piano\Piano.Tizen.Mobile\Piano.Tizen.Mobile.csproj", "{88E15381-DFC8-41CA-9D73-078B77F8A6BE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {20650979-F309-4E7A-A3F4-836C2B3E9834} + EndGlobalSection +EndGlobal diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.cs new file mode 100755 index 00000000..71b8db28 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.cs @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Piano.Models; +using Piano.Views; +using System; +using Tizen.NUI; + +namespace Piano.Tizen.Mobile +{ + class Program : NUIApplication + { + protected override void OnCreate() + { + base.OnCreate(); + + Window window = Window.Instance; + window.BackgroundColor = Color.Cyan; + window.KeyEvent += OnKeyEvent; + + try + { + Sound.Init(); + } + catch (Exception e) + { + global::Tizen.Log.Error("Piano", "Init : " + e.Message); + } + + MainPage page = new MainPage(); + window.Add(page); + window.AddAvailableOrientation(Window.WindowOrientation.Landscape); + } + + public void OnKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) + { + Exit(); + } + } + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.csproj b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.csproj new file mode 100755 index 00000000..d14b274e --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.csproj @@ -0,0 +1,38 @@ + + + + Exe + netcoreapp3.1 + 1 + + + + portable + + + None + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml new file mode 100755 index 00000000..da2470a1 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml.cs new file mode 100755 index 00000000..63d46dfc --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Controls/Key.xaml.cs @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Tizen.NUI; +using Tizen.NUI.Binding; +using Tizen.NUI.BaseComponents; + +namespace Piano.Controls +{ + /// + /// Interaction logic for Key.xaml. + /// + public partial class Key : ImageView + { + #region fields + + /// + /// Local storage of + /// + private int _soundNumber; + private Timer mViewTimer; + + #endregion + + #region properties + + /// + /// Bindable property that allows to set image source for pressed state. + /// + public static BindableProperty PressedImageSourceProperty = + BindableProperty.Create(nameof(PressedImageSource), typeof(string), typeof(Key)); + + /// + /// Bindable property that allows to set image source for unpressed state. + /// + public static BindableProperty UnPressedImageSourceProperty = + BindableProperty.Create(nameof(UnPressedImageSource), typeof(string), typeof(Key), + propertyChanged: UnPressedImageSourcePropertyChanged); + + public Vector4 LayoutBounds + { + set + { + PositionX = value.X * Window.Instance.Size.Height; + PositionY = value.Y * Window.Instance.Size.Width; + SizeWidth = value.Z * Window.Instance.Size.Height; + SizeHeight = value.W * Window.Instance.Size.Width; + } + } + /// + /// Gets or sets sound index that will be played. + /// + public int SoundNumber + { + get => _soundNumber; + set + { + _soundNumber = value; + OnPropertyChanged(); + } + } + + /// + /// Gets or sets image source for pressed state. + /// + public string PressedImageSource + { + get => GetValue(PressedImageSourceProperty).ToString(); + set => SetValue(PressedImageSourceProperty, value); + } + + /// + /// Gets or sets image source for unpressed state. + /// + public string UnPressedImageSource + { + get => GetValue(UnPressedImageSourceProperty).ToString(); + set => SetValue(UnPressedImageSourceProperty, value); + } + + /// + /// Gets or sets command that is executed on click. + /// + public Command OnClickedCommand { get; set; } + + #endregion + + #region methods + + /// + /// Default class constructor. + /// + public Key() + { + InitializeComponent(); + Root.TouchEvent += OnTouchEvent; + } + + private bool OnTouchEvent(object source, View.TouchEventArgs e) + { + ExecuteClickCommand(); + return false; + } + + /// + /// Invoked on image source change. + /// Updates image source. + /// + /// The bindable object that contains the property. + /// Old value of the property. + /// New value of the property. + private static void UnPressedImageSourcePropertyChanged(BindableObject bindable, object oldValue, + object newValue) + { + if (bindable is Key key) + { + key.UpdateImageSource(newValue.ToString()); + } + } + + /// + /// Executed on image click. + /// + private void ExecuteClickCommand() + { + UpdateImageSource(PressedImageSource); + //OnClickedCommand?.Execute(null); + + mViewTimer = new Timer(300); + mViewTimer.Tick += OnTimerTick; + mViewTimer.Start(); + } + + private bool OnTimerTick(object sender, Timer.TickEventArgs args) + { + UpdateImageSource(UnPressedImageSource); + + mViewTimer.Stop(); + mViewTimer.Dispose(); + + return false; + } + + /// + /// Updates image source. + /// + /// New image source. + private void UpdateImageSource(string newSource) + { + ResourceUrl = newSource; + } + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/ISound.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/ISound.cs new file mode 100755 index 00000000..f7a18752 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/ISound.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Threading.Tasks; + +namespace Piano.Models +{ + /// + /// Interface containing methods of sound player. + /// + public interface ISound + { + #region methods + + /// + /// Initializes sound player. + /// + /// Task with initialization. + Task Init(); + + /// + /// Plays sound with given index. + /// + /// Sound index. + /// + /// Task with bool result. + /// Result is true if playing was successful, false otherwise. + /// + Task Play(int soundIndex); + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/Sound.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/Sound.cs new file mode 100755 index 00000000..bc844d38 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Models/Sound.cs @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Threading.Tasks; +using Tizen.NUI.Binding; +using Piano.Tizen.Mobile.Services; + +namespace Piano.Models +{ + /// + /// Model for sound player. + /// + public static class Sound + { + #region fields + + /// + /// Sound player context. + /// + private static readonly ISound _sound; + + #endregion + + #region methods + + /// + /// Default class constructor. + /// + static Sound() + { + _sound = new SoundService(); + } + + /// + /// Initializes sound player. + /// + /// Task with initialization. + public static Task Init() + { + return _sound.Init(); + } + + /// + /// Plays sound with given index. + /// + /// Sound index. + /// + /// Task with bool result. + /// Result is true if playing was successful, false otherwise. + /// + public static Task Play(int soundIndex) + { + return _sound.Play(soundIndex); + } + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Piano.csproj b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Piano.csproj new file mode 100755 index 00000000..ce72b0fc --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Piano.csproj @@ -0,0 +1,22 @@ + + + + netcoreapp3.1 + + + + + + + + + + + + + + + + + + diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/ViewModels/KeyViewModel.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/ViewModels/KeyViewModel.cs new file mode 100755 index 00000000..05e452b7 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/ViewModels/KeyViewModel.cs @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Piano.Models; +using Tizen.NUI.Binding; + +namespace Piano.ViewModels +{ + /// + /// ViewModel class for single key. + /// + public class KeyViewModel : BindableObject + { + #region properties + + /// + /// Bindable property that allows to set sound index that will be played. + /// + public static BindableProperty SoundNumberProperty = +#pragma warning disable Reflection // The code contains reflection + BindableProperty.Create(nameof(SoundNumber), typeof(int), typeof(KeyViewModel), 0); +#pragma warning restore Reflection // The code contains reflection + + /// + /// Bindable property that allows to set command that plays sound. + /// + public static BindableProperty PlaySoundCommandProperty = +#pragma warning disable Reflection // The code contains reflection + BindableProperty.Create(nameof(PlaySoundCommand), typeof(Command), typeof(KeyViewModel)); +#pragma warning restore Reflection // The code contains reflection + + /// + /// Gets or sets sound index that will be played. + /// + public int SoundNumber + { + get => (int)GetValue(SoundNumberProperty); + set => SetValue(SoundNumberProperty, value); + } + + /// + /// Gets or sets command that plays sound. + /// + public Command PlaySoundCommand + { + get => (Command)GetValue(PlaySoundCommandProperty); + set => SetValue(PlaySoundCommandProperty, value); + } + + #endregion + + #region methods + + /// + /// Default class constructor. + /// + public KeyViewModel() + { + PlaySoundCommand = new Command(PlaySound); + } + + /// + /// Plays sound. + /// + private async void PlaySound() + { + await Sound.Play(SoundNumber); + } + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml new file mode 100755 index 00000000..37b8ae86 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml.cs new file mode 100755 index 00000000..5627a483 --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Piano/Views/MainPage.xaml.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Tizen.NUI; +using Tizen.NUI.BaseComponents; + +namespace Piano.Views +{ + /// + /// Interaction logic for MainPage.xaml + /// + public partial class MainPage + { + #region methods + + /// + /// Default class constructor. + /// + public MainPage() + { + InitializeComponent(); + } + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Services/SoundService.cs b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Services/SoundService.cs new file mode 100755 index 00000000..0b98f23c --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/Services/SoundService.cs @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Piano.Models; +using System.Threading.Tasks; +using Piano.Tizen.Mobile.Services; +using Tizen.Applications; +using Tizen.Multimedia; +using Tizen.NUI.Binding; + +namespace Piano.Tizen.Mobile.Services +{ + /// + /// Service that plays sounds. + /// + public class SoundService : ISound + { + #region fields + + /// + /// Maximum sound index. + /// + private const int MAX_SOUND_INDEX = 13; + + /// + /// Indicates if player is initialized. + /// + private bool _initialized; + + /// + /// Contains every sounds. + /// + private Player[] _sounds; + + #endregion + + #region methods + + /// + /// Initializes sound player. + /// + /// Task with initialization. + public async Task Init() + { + if (_initialized) + { + return; + } + + var resPath = Application.Current.DirectoryInfo.Resource; + _sounds = new Player[MAX_SOUND_INDEX + 1]; + + for (var i = 0; i <= MAX_SOUND_INDEX; i++) + { + var player = new Player + { + IsLooping = false + }; + + player.SetSource(new MediaUriSource($"file://{resPath}/sounds/{i}.wav")); + + await player.PrepareAsync(); + + _sounds[i] = player; + } + + _initialized = true; + } + + /// + /// Plays sound with given index. + /// + /// Sound index. + /// + /// Task with bool result. + /// Result is true if playing was successful, false otherwise. + /// + public async Task Play(int soundIndex) + { + if (!_initialized || soundIndex < 0 || soundIndex > MAX_SOUND_INDEX) + { + return false; + } + + var player = _sounds[soundIndex]; + + if (player.State == PlayerState.Idle) + { + return false; + } + + await player.SetPlayPositionAsync(0, false); + + player.Start(); + + return true; + } + + #endregion + } +} \ No newline at end of file diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black.png b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black.png new file mode 100755 index 00000000..fb1625cc Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black.png differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black_pressed.png b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black_pressed.png new file mode 100755 index 00000000..2358f4a4 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/black_pressed.png differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/0.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/0.wav new file mode 100755 index 00000000..ef150a5b Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/0.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/1.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/1.wav new file mode 100755 index 00000000..8875e121 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/1.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/10.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/10.wav new file mode 100755 index 00000000..d07fd656 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/10.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/11.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/11.wav new file mode 100755 index 00000000..1f37f7f9 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/11.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/12.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/12.wav new file mode 100755 index 00000000..1884f1df Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/12.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/13.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/13.wav new file mode 100755 index 00000000..0aa029a0 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/13.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/2.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/2.wav new file mode 100755 index 00000000..fdda07be Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/2.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/3.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/3.wav new file mode 100755 index 00000000..586f12ea Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/3.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/4.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/4.wav new file mode 100755 index 00000000..98560c5f Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/4.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/5.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/5.wav new file mode 100755 index 00000000..291e4e12 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/5.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/6.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/6.wav new file mode 100755 index 00000000..e6803aae Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/6.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/7.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/7.wav new file mode 100755 index 00000000..9f699f8f Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/7.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/8.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/8.wav new file mode 100755 index 00000000..c16a5d61 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/8.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/9.wav b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/9.wav new file mode 100755 index 00000000..71dca928 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/sounds/9.wav differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white.png b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white.png new file mode 100755 index 00000000..a7813061 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white.png differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white_pressed.png b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white_pressed.png new file mode 100755 index 00000000..d8a98814 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/res/white_pressed.png differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/shared/res/Piano.Tizen.Mobile.png b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/shared/res/Piano.Tizen.Mobile.png new file mode 100755 index 00000000..9f3cb986 Binary files /dev/null and b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/shared/res/Piano.Tizen.Mobile.png differ diff --git a/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/tizen-manifest.xml b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/tizen-manifest.xml new file mode 100755 index 00000000..d9f5f8bd --- /dev/null +++ b/Mobile/NUI/Piano/Piano/Piano.Tizen.Mobile/tizen-manifest.xml @@ -0,0 +1,14 @@ + + + + + + + Piano.Tizen.Mobile.png + + + + + + + diff --git a/Mobile/NUI/Piano/README.md b/Mobile/NUI/Piano/README.md new file mode 100755 index 00000000..51d61afc --- /dev/null +++ b/Mobile/NUI/Piano/README.md @@ -0,0 +1,14 @@ +# Piano +Piano is a sample application that demonstrates how to play sounds using [Tizen Multimedia API](https://samsung.github.io/TizenFX/stable/api/Tizen.Multimedia.html). + +![MainPage](./Screenshots/main_page.png) + +### Features +* Playing sound on key press. + +### Prerequisites +* [Visual Studio](https://www.visualstudio.com/) - Buildtool, IDE +* [Visual Studio Tools for Tizen](https://docs.tizen.org/application/vstools/install) - Visual Studio plugin for Tizen .NET application development + +### Author +* Guowei Wang diff --git a/Mobile/NUI/Piano/Screenshots/main_page.png b/Mobile/NUI/Piano/Screenshots/main_page.png new file mode 100755 index 00000000..41545713 Binary files /dev/null and b/Mobile/NUI/Piano/Screenshots/main_page.png differ