Application «Quy Band

advertisement
The Ministry of Education and Science of the Republic of Kazakhstan
regional Kazakh-Turkish Lyceum of Atyrau for gifted children
Nurtay Bekarys
Saipolla Saken
11 grade
Application «Quy Band»
Categorie: programming
Scientific adviser: Piriyev Elbrus Kemalovich
Teacher of Computer Science of
Atyrau Kazakh-Turkish Lyceum
Atyrau - 2015
1
Annotation
Research objective: gist of the study is to interpret the Kazakh national instruments into
smart devices, thereby spread the Kazakh culture.
Hypothesis: implementation of this project will make a step in the development of the
economy, as well as spread part of our culture and raise the level of popularity of national
instruments to the level of those which are currently considered to be known.
Investigation phases:
1. Recording sounds of instruments
2. Distribution of the recorded sounds to frequencies of notes
3. Creation the main class for the interpretation of sounds using the library LibGDX in
JAVA
4. Adding auxiliary classes
5. Alfa testing
Research technique: processed information from two books about Android application
development and 1 book about programming in Java. The sounds were decomposed for
the notes using a special formula.
Novelty of research and independence degree: special outlets focused on the
distribution of applications, such as Play Market and Appstore provide opportunities for
projects. Although at the moment there are applications that interpret the musical
instruments, there is no application that was designed correctly for implementing and
interpreting the Kazakh national instruments.
Conclusions: in fact, it is very challenging to render precisely the sound of each note of
national instruments. Also there are some glitches in the keynotes. But in general, the
interpretation passed successful, although it requires some modifications.
Areas of practical application: Obviously instruments are not cheap. Thus, using the
application, you can learn how to play not difficult music and Quis, and superficially (or
maybe in depth) learn about Kazakh national instruments. Furthermore, via this
application you can superficially (or maybe in depth) learn about Kazakh national
instruments.
2
Аннотация
Цель исследования: суть исследования в том, чтобы интерпретировать казахские
национальные инструменты в смарт устройства, тем самым распространить
Казахскую культуру.
Гипотеза исследования: реализация этого проекта сделает шаг в развитии
экономики, а также распространит часть нашей культуры и поднимет уровень
популярности национальных инструментов на уровень тех, которые на данный
момент считаются известнейшими.
Этапы исследования:
1. Запись звуков инструментов
2. Распределение записанных звуков по частотам нот
3. Создание основного класса, для интерпретации звуков используя библиотеку
LibGDX на JAVA
4. Добавление вспомогательных классов
5. Альфа тестирование
Методика исследования: обработаны информации с 2 книг по разработке
приложении на Android и 2 книг по программированию на языке Java. Разложение
звуков на ноты используя специальную формулу.
Новизна исследования и степень самостоятельности: специальные торговые
точки, ориентированные на распространение приложений, такие как Play Market и
Appstore дают перспективы для реализации проектов. Хотя на данный момент
существуют приложения, интерпретирующие музыкальные инструменты, не было
разработано приложение корректно реализующий и интерпретирующий казахские
национальные инструменты.
Результаты работы: фактически, очень трудно воспроизвести до точности
звучание каждой ноты национальных инструментов, есть некоторые погрешности в
тональности. Но в целом интерпретация прошла успешно, хотя и требует
некоторых доработок
Области практического применения: приложение даёт хорошее представление о
казахских национальных инструментах и, к тому же инструменты стоят не дёшево.
Таким образом, при помощи приложения можно научиться играть не сложные
исполнения и Кюи, и поверхностно (а может и углубленно) познать казахские
национальные инструменты.
3
Introduction
Programming for Android, thanks to the flexibility of the platform allows you
to create memorable and useful mobile applications to virtually any need. Therefore,
because of the vast majority of smartphones running the Linux operating system,
application development for Android opens up broad prospects. Over recent years,
indicators characterizing the level of demand for mobile devices is growing. The
relevance of programming Android applications confirmed by the figures. By the
beginning of 2013 70% of smartphone users around the world have been equipped
with the Android OS compared with 20% of users of iOS. The wide range of products
from brands Samsung, Acer, HTC, etc., in various price categories contributing to the
spread of smartphones based on Android among all segments of the population - from
students to executives of large companies. Android is sweeping the planet, and every
year the number of users of the system will only increase.
Today, experts in the field of information technology are developing mobile
applications that allow you to solve a lot of problems, for example, teaching people to
play musical instruments. So, the essence of our study is to interpret the Kazakh
national instrument in smart devices thereby spread the Kazakh culture.
Objectives for this project are:
• Learning Java programming language
• Studying auxiliary virtual engine LibGDX
• Recording acoustic-clear sounds for instruments
• The distribution of the recorded sounds in frequencies of notes
• Creating the application
• Alpha testing
The application has been written in Java, in the development environment Intellij
IDEA using cross-platform engine LibGdx, and in order to run the application on
Android there has been added Android SDK. The app has been tested on the emulator
android -AVD (Android Virtual Device) and on actual devices. The first interpreted
musical instrument was a "zhetіgen".
4
1. Object-Oriented Programming in Java and the creation of classes
Firstly, in order to create an application for Android or any other device you
need a programming language and a few important libraries. In our case, we use Java.
Why Java? Because it is the main language used to develop applications for the
Android operating system.
Java is an object-oriented programming language developed by Sun
Microsystems, which later was acquired by Oracle. Java applications are usually
broadcast in a special byte code, and then looking at what architecture was launched,
converted Java-machine (JVM) to machine code.
By default all programming languages are divided into 3 groups: native,
scripting languages and using the VM (Virtual Machine). The latter group solves such
problems as cross-platform. It is possible to write code without worrying about the
architecture of the device, be it a mobile phone, computer, or home appliances. Java
refer to this type of language, as it has its own virtual machine. The advantage of this
method of program execution is complete independence of the bytecode from the
operating system and hardware that allows using Java-based applications on any
device. But Java has disadvantages. Often to the disadvantage of the virtual machine
are low productivity. According to the site shootout.alioth.debian.org, seven different
applications of Java Runtime averaged a half to two times larger than C / C ++, Java,
in some cases, faster, and in some cases 7 times slower.
Since Java is cross-platform and suitable for almost any operating system, we
began to write with it the code for the application. To do this, we need JavaJDK 6.0
or JDK 7.0 and you need to install the development environment. We prefer Intelij
IDEA from the company JetBrains. It has very intuitive and flexible user interface
and in the future will be very convenient to port applications to Android.
5
K
Fig.1.Logo of the environment of development from Intellij IDEA
To start writing a code it is necessary to create the project initially. Creation
of any application in IntelliJ IDEA begins with creation of the project, so creation
of the “Quy Band” project will be our first step. This project will contain the Java
module for our Java appendix.
1.If any project isn't open at present, press the Create New Project button on the
home screen. Otherwise, select the New Project item in the File menu. As a result
the master of creation of the project will open.
2.In the left panel choose Java Module.
3.In the right part of the page, in the field of Project name, enter the name of the
project: Quy Band
6
K
Fig. 2
4.If before you never adjusted JDK in IntelliJ IDEA in (in that case in the field of
Project SDK you will see <none>), it is necessary to make it now. Instead of <none> press New and in a submenu choose JDK. In the Select Home Directory for JDK window choose a directory in which JDK
was established and press OK.
K
Fig. 3
The JDK version which you chose, will appear in the field of Project SDK. Click
Next. 7
Consider that the specified JDK version will be connected by default with all
projects and modules which will be created further.
5.On the following page the master's choice for the indication of additional
technologies which will be supported in our module is carried out. As our appendix
will be "the old kind Java appendix", we don't need any of these technologies. So
simply press the Finish button.
Wait while IntelliJ IDEA creates necessary structures of the project. When this
process comes to the end, you can see structure of your new project in the Project
window.
1.1 Creation of a class
1. For creation of the project press ALT + INSERT. In the New window with the
allocated com.digitalstels.quyband package we choose Java Class from the list
of available actions and we press Enter.
K
Fig. 4
2. In the appeared Create New Class window in the field of Name we enter the name
Main. In the field of Kind we leave Class and we press Enter to confirm creation of
class.
8
K
Fig. 5
The created class Main appears in structure of the project:
K
Fig. 6
On it all preparations are finished.
2. Addition of auxiliary libraries LibGDX and AndroidSDK
To start programming needs to add the additional library – LibGDX engine.
LibGDX– an interesting, simple engine in use, open-source from the Austrian
company BadlogicGames. This engine was written in language which we now use,
Java. Games can be run on Windows, Linux, Mac OS X, Android and iOS. If there
are no difficult functionalities in the program, it is possible to start the program and
on the browser. As our program is aimed at the Android environment, it is ideal for
this purpose. In addition LibGDX is productive and is free (open-source).
At first it is necessary to download library from the official site of
libgdx.badlogicgames.com. Having downloaded assembly of LibGDX, we will
unpack it and we will look inside. We look for the gdx-setup.jar file there — this is
our client. We run our client and we will see this window:
9
K
Fig. 7. Loading LibGDX window
We see two buttons here: Generate – to create the project, Advanced – it is more
than settings.
So, we look at the top part of the panel:
1.Name — here to us need to enter the name of our appendix. We will enter quy-band
here
2.Package — a java-package of our game. We enter com.digitalstels.quyband here
3.Gameclass — this class — in some way "kernel" of our game. We enter Main here
4.Destination — where to put the created application. Choose the catalog convenient
to you.
5. Android SDK – we choose the library preset by android. That the appendix started
working at android Android SDK is necessary. First of all, we need an ADT package
(Android Developer Tools) of Bundle, it can be downloaded from the official site of
developer .android.com. It includes:
• Android Developer Tools — a plug-in.
• Android SDK — the latest version of Android SDK.
• Tools and platform means of Android SDK — a debugging facility and
applications testing.
• The image of system for the Android emulator — allows to create and test
applications on various virtual devices.
10
K
Fig. 8. Andropid SDK Manager. Downloading earlier versions of SDK
We don't touch the LibGDX Version button. In the Sub projects panel we
choose platforms on which we want to create the application. We need android and
desktop, from the others ticks are cleaned. The Extensions panel is necessary for
addition of auxiliary libraries, such as Box2d, Controllers, Tools, etc. Small squares
we leave empty.
We press Generate. Now we import the project created by us to Intellij IDEA.
For this purpose we come into the environment of development and we choose the
Import project button. In the appeared window we choose the build.gradle file and
we press OK. We press OK once again, and generation of LibGDX of the project
began.
K
Fig. 9
11
3. Class Game and interface Screen
The class Game realizing the ApplicationListener interface is responsible for
all processes in the appendix, from processing of input before drawing the image and
reproduction of sounds.
K
Fig. 10. The class Game the realizing ApplicationListener interface
The class Game has such methods: create (), pause (), resume (), render (), resize
(), dispose (), setScreen () and getScreen (). All these methods are, as if life cycle of
a class:
• Create () – this method is caused at the first opening of the appendix and answers
for initialization of the appendix;
• Render () – this method is responsible for drawing of each shot, that is he is called
each shot;
• Pause () – is caused at an exit from the appendix;
• Resume () – is caused when opening the appendix when it wasn't closed
completely yet;
• Dispose () – this method is caused at full closing of the appendix, it disconnects all
methods and classes;
• Resize () – this method is caused at change of a display resolution;
• SetScreen () – is caused when we want to change the screen (the menu screen, the
choice screen) appendices, that is moves the appendix on different classes;
• GetScreen () – returns a class (screen) which is at the moment active.
We are inherited from this class.
K
Fig. 11. The class Main inherited from the class Game
The Screen interface is an interface which demands realization, and serves as a
template for screens (classes). Screens on which the appendix switches, are created,
realizing this interface. In it there are such interesting methods which I am
12
responsible for life cycle of the screen. They: render (), resize (), show (), hide (),
pause (), resume () and dispose ().
• Show () – this method is caused, when the screen to become active;
• Hide () – this method is caused, when the screen any more active;
This interface will be realized by 2 classes: MenuScreen and GameScreen. The first
class will serve as a class for the menu screen, and the second – the main screen of
the appendix.
@
Fig. 12. Class GameScreen
@
Fig. 13. Class MenuScreen
The class Main will switch between these two screens.
13
4. Drawing of attributes and images
The concept of a scene (stage) and actors (actors) well will be suitable for
drawing of images and attachment of function to them. Strings, tools, buttons – all
these objects are actors. Each actor has certain properties: the size, situation on the
screen, visibility, an angle of rotation. The scene is that invisible part where there are
all actors. Thus, the concept of actors and a scene is a convenient way to break all
game into independent parts which interact with each other.
4.1 Stage
For each screen we will create own scene. They will reproduce actors.
Transition buttons between screens, strings, tools and other will be actors.
K
Fig. 14. Class GameScreen scene
!
Fig. 15. Class MenuScreen scene
Now the created scenes need to be included in the appendix. We add to the method
render () two calls:
K
Fig. 16.
14
The the stage.draw() is intended for drawing of actors. This method causes the
method draw() in each actor. The method stage.act () allows actors to execute various
actions (the movements, reproduction of sounds, etc.) and it similarly causes the
method act() in all actors attached to a scene. Parameter of this method (delta) – time
in seconds which passed from the moment of the last call of act () (actually, from the
moment of drawing of the last shot).
4.2 Actor
Actor is a class which creates actors, but can't independently be drawn. We
will create another class which will initialize actors, and we will transfer the created
actors to scenes that to start using them.
K
Fig. 17. Class for actors
This class redefined the method draw(). It is visible that two parameters – Batch and
number (parentAlpha) are transferred to it. Batch is an renderer of the image.
ParentAlpha is the variable designating transparency of the drawn actor. The method
batch.draw() has 5 parameters: texture, X, Y, width and height.
• Texture - it is a parameter with loaded texture;
• X - it is a coordinate on X on which the texture will be drawn;
• Y – it is coordinate on Y on which the texture will be drawn;
• Width – texture width;
• Height – texture height.
By means of this class, we will create the actors who are responsible for
interpretation of the tool.
5. Data processing. InputProcessor and InputListener.
Of what our program consists? It consists of virtual buttons which by pressing
certain sounds are made. That each button made the sound, the handler is necessary.
We will begin with that we have two big approaches to input processing.
15
The first approach — is continuous poll of the devices processing contacts. In
English-speaking literature it is called as polling. It means that we in our basis cycle
interrogate the devices interesting us regarding their state, for example, we learn
pressed at present the virtual button on the screen. This approach developed the first,
it simple and obvious in use, but longer in realization. You will be able to control
some devices by means of only such approach — for example, the accelerometer or a
compass.
The second approach — is event. The framework which we use, provides us
special classes which react to certain events. Our task — to create handlers of these
events. Event approach is ideal for us. For this purpose we created some actors and
attached to them actions (event).
K
Fig. 18. Processing of the button
In libGDX input possibilities are concentrated in the Input module. In this case
we are interested only in small part — the touch screen. For these purposes in
libGDX there is an InputProcessor interface. In InputProcessor there are qualifiers,
such as keyDown, keyUp, mouseMoved, touchDown, touchUp, touchDragged,
etc. From them it is only necessary for us the last two: touchDown and touchUp.
TouchDown - is caused when we press a finger the screen in Android. TouchUp – is
caused when we take away a finger from the screen.
To create sounding of strings, first of all, we import sounds of strings to our
project. After that we bind each sound on each separate area of the screen by means
of public boolean touchDown (int screenX, int screenY, int pointer, int button);
After that we use the code public boolean touchUp (int screenX, int
screenY, int pointer, int button). This team answers deduction of a key, by means of
it we can control sounding duration.
16
K
Fig. 19.
6. Playing the recored samples.
By help of the Wavosaur program we spread out one sound to notes. And now
it was necessary to bind each sound by means of touchDown qualifier. LibGDX
supports three types of audio of a format: ogg, mp3 and wav. We will use the most
widespread look – a MP3. All sounds which we use, we add to the assets folder
which is located in the android folder. To load files it is only necessary to write:
Sound mp3Sound = Gdx.audio.newSound (Gdx.files.internal(“<name>.mp3”));
@
Fig. 20. Initialization of sounds
To play the sound it is only necessary to add:
mp3Sound.play();
@
Fig. 21. Playing the sound after pressing
17
7. Testing in different platforms
Our alpha version of an application is almost ready. As mentioned before , the
written code can be compiled and run in operating systems such as Android , Mac
OS, Windows and iOS. We have tested the application on Mac OS , Windows and , of
course , on Android. This is how the main menu:
K
Fig. 22. Main menu (first category:Zhetigen)
18
@
Fig. 23. Main menu (second category: Shankobyz)
19
View of the instruments themselves:
@
Fig. 24. First Instrument - Zhetigen
As you can see at the screen - it has 7 strings and every string has its own sound,
which is not similar to other’s. Also we have added settings for the zhetigen (with this
feature we can change the tone of the sound).
20
K
Fig. 25. Zhetigen settings
Also , except Zhetigen we have added a Shankobyz (later we are going to add more
instruments and improve user interface):
21
K
Fig. 26. Instrument - Shankobyz
We have tested the application on Mac OS X :
22
@
Fig. 27.
@
Fig.28.
23
@
Fig. 29.
@
Fig. 30.
24
Conclusion
Today there are a lot of people , who want to learn play in Kazakh musical
instruments. But instruments cost very expensive, approximately 40 000 - 60 000 TG.
But not everyone can afford to buy such an expensive tool. In this case our
application can be helpful to learn playing or practice skills, because our application
is free. Also with this application foreigners, who interested in Kazakh culture, can
get information about our traditions, about traditional Kazakh instruments. The aim
of the creation of this project is to help beginners practice their skills, to enable those
who can not buy a tool and to disseminate the culture and tradition of Kazakhstan.
25
List of references
1. Ekkel B. "Java philosophy". St. Petersburg, 2009, page 1-638.
2. Hardil B., Phillips B. "Programming under Android". St. Petersburg, 2014, page
1-590
3. Vinogradov D. "Google Android ... it isn't difficult". Moscow, 2012, page 1-701
4. Oracle «Tutorial for Java». 2006, page 1-1324
26
Download