├── pytabs
├── __init__.py
├── gui
│ ├── __init__.py
│ ├── tab
│ │ ├── __init__.py
│ │ └── Tab.py
│ ├── text
│ │ ├── __init__.py
│ │ ├── Text.py
│ │ └── SyntaxHighlighter.py
│ ├── statusbar
│ │ ├── __init__.py
│ │ └── StatusBar.py
│ ├── toolbar
│ │ ├── __init__.py
│ │ └── ToolBar.py
│ ├── window
│ │ ├── __init__.py
│ │ ├── MainForm.py
│ │ ├── NewDialog.py
│ │ └── AboutDialog.py
│ ├── images
│ │ ├── exit.png
│ │ ├── icon.png
│ │ ├── open.png
│ │ ├── save.png
│ │ ├── test.ico
│ │ └── about.png
│ └── startApp.py
├── chords
│ ├── __init__.py
│ ├── examples
│ │ ├── rythm2.mcx
│ │ └── rythm.mcx
│ └── guitarchords.py
├── guitar
│ ├── __init__.py
│ ├── grammar
│ │ └── guitar_tab_note.tx
│ └── guitar_tablature.py
├── keyboards
│ ├── __init__.py
│ ├── grammar
│ │ └── keyboard_tab_note.tx
│ └── keyboard_tablature.py
├── player
│ ├── __init__.py
│ └── player.py
├── tablature
│ ├── __init__.py
│ └── tablature.py
├── composition
│ ├── __init__.py
│ ├── examples
│ │ └── track.song
│ ├── compositiontest.py
│ └── composition.py
└── grammar
│ ├── chords.tx
│ ├── tablature.tx
│ └── composition.tx
├── tests
├── __init__.py
└── guitar_tab_parser_test.py
├── examples
├── __init__.py
├── songs
│ ├── instruments
│ │ └── .gitignore
│ └── smoke_on_the_water.song
└── example_player.py
├── lib
├── .gitignore
└── required_libs.txt
├── .gitignore
├── start_gui.sh
├── play_examples.sh
├── start_gui.bat
├── play_examples.bat
├── README.md
└── LICENSE.txt
/pytabs/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/chords/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/tab/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/text/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/guitar/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/keyboards/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/player/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/tablature/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/composition/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/statusbar/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/toolbar/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytabs/gui/window/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !required_libs.txt
3 | !.gitignore
--------------------------------------------------------------------------------
/examples/songs/instruments/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.project
2 | /.pydevproject
3 | /.settings
4 | *.pyc
5 | *.pyo
6 |
--------------------------------------------------------------------------------
/pytabs/gui/images/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/exit.png
--------------------------------------------------------------------------------
/pytabs/gui/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/icon.png
--------------------------------------------------------------------------------
/pytabs/gui/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/open.png
--------------------------------------------------------------------------------
/pytabs/gui/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/save.png
--------------------------------------------------------------------------------
/pytabs/gui/images/test.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/test.ico
--------------------------------------------------------------------------------
/pytabs/gui/images/about.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/E2Music/pyTabs/HEAD/pytabs/gui/images/about.png
--------------------------------------------------------------------------------
/pytabs/chords/examples/rythm2.mcx:
--------------------------------------------------------------------------------
1 | Am
2 | F(8)
3 | F#
4 | C()
5 | Gm
6 | Dmaj
7 | Cmaj7
8 | A/G
9 | C5
10 | [4]
--------------------------------------------------------------------------------
/start_gui.sh:
--------------------------------------------------------------------------------
1 | export PYTHONPATH=$(pwd):$PYTHONPATH
2 | export PATH=$(pwd)/lib:$PATH
3 | cd ./pytabs/gui/
4 | pythonw startApp.py &
--------------------------------------------------------------------------------
/play_examples.sh:
--------------------------------------------------------------------------------
1 | export PYTHONPATH=$(pwd):$PYTHONPATH
2 | export PATH=$(pwd)/lib:$PATH
3 | cd ./examples/
4 | python example_player.py
--------------------------------------------------------------------------------
/pytabs/chords/examples/rythm.mcx:
--------------------------------------------------------------------------------
1 | C
2 | C2
3 | C#
4 | Cmaj
5 | Csus
6 | Cm
7 | Cm7
8 | Cmaj7
9 | C#maj
10 | A#maj/G#maj
11 | A/G
12 | [8]
13 |
--------------------------------------------------------------------------------
/start_gui.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | set PYTHONPATH=%PYTHONPATH%;%~dp0
3 | set PATH=%PATH%;%~dp0\lib
4 | cd ./pytabs/gui/
5 | start pythonw startApp.py
6 | cd ../..
--------------------------------------------------------------------------------
/play_examples.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | set PYTHONPATH=%PYTHONPATH%;%~dp0
3 | set PATH=%PATH%;%~dp0\lib
4 | cd ./examples/
5 | python example_player.py
6 | cd ..
7 | pause
--------------------------------------------------------------------------------
/lib/required_libs.txt:
--------------------------------------------------------------------------------
1 | - FluidSynth:
2 | - for Windows:
3 | - lib name: fluidsynth.dll
4 | - project website: http://www.fluidsynth.org/
5 | - fluidsynth.dll should be placed in PATH or in this lib directory (will be added to PATH when running start scripts)
6 | - you can compile it yourself from http://sourceforge.net/projects/fluidsynth/files/fluidsynth-1.1.3/
7 | or download one from here http://svn.drdteam.org/zdoom/fluidsynth.7z (ofcourse download at your own risk, link found via stackoverflow).
--------------------------------------------------------------------------------
/pytabs/composition/examples/track.song:
--------------------------------------------------------------------------------
1 | [
2 | Name "Test"
3 | Author "Milos"
4 | Beat 4/4
5 | Tempo 120
6 | ]
7 |
8 | import
9 | saruman "thewhite"
10 | radagast "thebrown"
11 | gandalf "thegray"
12 |
13 | //ovde svira samo Monkey
14 | sequence guitar-rhythm Monkey
15 | {
16 | C(8) Dm
17 | }
18 |
19 | sequence guitar-solo Head{
20 | e|-0----10-3-||
21 | B|-0----1--1-||
22 | G|-12pm----6-||
23 | D|-2----9--0-||
24 | A|-2----3--2-||
25 | E|-----------||
26 |
27 | }
28 |
29 | sequence bass Fildey
30 | {
31 | F G
32 | }
33 |
34 | segment Chorus
35 | {
36 | Head : gandalf
37 | Fildey : radagast
38 | }
39 |
40 | segment End
41 | {
42 | Monkey : gandalf
43 | Fildey : radagast
44 | }
45 |
46 | timeline
47 | {
48 | Chorus,End
49 | }
--------------------------------------------------------------------------------
/pytabs/keyboards/grammar/keyboard_tab_note.tx:
--------------------------------------------------------------------------------
1 | /*
2 | # PyTabs - Simplified music notation DSL, interpreter and player.
3 | # Copyright (C) 2014, Bojana Sofronovic
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | */
18 |
19 | /*
20 | Keyboard tablature note grammar:
21 |
22 | example:
23 | a
24 | C
25 | -
26 |
27 | */
28 |
29 | MusicSymbol:
30 | Note|Rest
31 | ;
32 |
33 | Note:
34 | key=/^\w/
35 | ;
36 |
37 | Rest:
38 | '-'
39 | ;
--------------------------------------------------------------------------------
/pytabs/guitar/grammar/guitar_tab_note.tx:
--------------------------------------------------------------------------------
1 | /*
2 | # PyTabs - Simplified music notation DSL, interpreter and player.
3 | # Copyright (C) 2014, Zeljko Bal
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | */
18 |
19 | /*
20 | Guitar tablature note grammar:
21 |
22 | example:
23 | 1
24 | 12
25 | 5pm
26 | -
27 |
28 | */
29 |
30 | MusicSymbol:
31 | Note|Rest
32 | ;
33 |
34 | Note:
35 | fret=/^\d+/
36 | pm?='pm'
37 | ;
38 |
39 | Rest:
40 | '-'
41 | ;
--------------------------------------------------------------------------------
/pytabs/gui/startApp.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | import sys
23 |
24 | from PySide.QtGui import QApplication
25 |
26 | from pytabs.gui.window.MainForm import MainForm
27 |
28 |
29 | if __name__ == '__main__':
30 | # Create the Qt Application
31 | app = QApplication(sys.argv)
32 | # Create and show the form
33 | form = MainForm()
34 | form.show()
35 | # Run the main Qt loop
36 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/pytabs/gui/statusbar/StatusBar.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | from PySide.QtGui import QStatusBar, QLabel
23 |
24 |
25 | class StatusBar(QStatusBar):
26 | def __init__(self, parent=None):
27 | super(StatusBar,self).__init__(parent)
28 |
29 | """self.labelStatus = QLabel("Tekst Neki")
30 | self.labelSelection = QLabel("Selection Label")
31 | self.addWidget(self.labelStatus)
32 | self.addWidget(self.labelSelection)"""
33 |
34 |
--------------------------------------------------------------------------------
/pytabs/grammar/chords.tx:
--------------------------------------------------------------------------------
1 | /*
2 | # PyTabs - Simplified music notation DSL, interpreter and player.
3 | # Copyright (C) 2014, Milos Simic
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | */
18 |
19 |
20 | GuitarChords:
21 | value*=Command
22 | ;
23 |
24 | Command:
25 | ChordExtended|Pause
26 | ;
27 |
28 | Pause:
29 | "[" time=INT "]"
30 | ;
31 |
32 | ChordExtended:
33 | prefix=Chord ("/" suffix=Chord)? (duration=ChordDuration)?
34 | ;
35 |
36 | Chord:
37 | chord=BaseExtended (decor=DecorateExtended)? (prep=PrepExtended)?
38 | ;
39 |
40 | ChordDuration:
41 | "(" (time=INT)? ")"
42 | ;
43 |
44 | DecorateExtended:
45 | name=Decorate (number=INT)?
46 | ;
47 |
48 | Decorate:
49 | "#"|"b"
50 | ;
51 |
52 | PrepExtended:
53 | name=Prep (number=INT)?
54 | ;
55 |
56 | Prep:
57 | "maj"|"sus"|"div"|"m"
58 | ;
59 |
60 | BaseExtended:
61 | base=Base (number=INT)?
62 | ;
63 |
64 | Base:
65 | "C"|"D"|"E"|"F"|"G"|"A"|"B"
66 | ;
--------------------------------------------------------------------------------
/pytabs/grammar/tablature.tx:
--------------------------------------------------------------------------------
1 | /*
2 | # PyTabs - Simplified music notation DSL, interpreter and player.
3 | # Copyright (C) 2014, Zeljko Bal
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | */
18 |
19 | /*
20 | Tablature grammar:
21 |
22 | guitar example:
23 |
24 | e|-0----10-3-||
25 | B|-0----1--1-||
26 | G|-12pm----6-||
27 | D|-2----9--0-||
28 | A|-2----3--2-||
29 | E|-----------||
30 | All notes must be separated by a dash '-' and they can be of arbitrary length (with parameters),
31 | every note must be followed by additional dashes for the length of the longest note in a column,
32 | all strings must be of equal length and each one must start with '|-' and end with '-||'
33 | */
34 |
35 | Tablature:
36 | strings+=String
37 | ;
38 |
39 | // string example G|-12pm----6-||
40 | String:
41 | // a word followed by dashes
42 | mark=/(\w)+(-)*/
43 | '|-'
44 | // a string of words and dashes with '-' at the end
45 | chars=/[\w-]+-/
46 | '||'
47 | ;
48 |
--------------------------------------------------------------------------------
/examples/songs/smoke_on_the_water.song:
--------------------------------------------------------------------------------
1 | [
2 | Name "Dim na vodi"
3 | Author "Tim1"
4 | Beat 4/4
5 | Tempo 120
6 | ]
7 |
8 | import
9 | bass "instruments/Soundfont BassFing.sf2"
10 | guitar "instruments/Saber_5ths_and_3rds.sf2"
11 | piano "instruments/AJH_Piano.sf2"
12 | guitar2 "instruments/GuitarSetPasisHeavyAndClean.sf2"
13 |
14 | sequence guitar-solo guitar_tabs
15 | {
16 |
17 | R|-8-8-8-8---8-8-8-8-8-8-----8-8-8-8---8-8-8-2-||
18 | e|---------------------------------------------||
19 | B|---------------------------------------------||
20 | G|---------------------------------------------||
21 | D|---------------------------------------------||
22 | A|---------0-----------1-0-----------0---------||
23 | E|-0---3-------0---3---------0---3-------3---0-||
24 |
25 | }
26 |
27 | sequence guitar-solo bass_tabs
28 | {
29 |
30 | R|-8-8-8-8---8-8-8-8-8-8-----8-8-8-8---8-8-8-2-||
31 | G|---------------------------------------------||
32 | D|---------------------------------------------||
33 | A|---------------------------------------------||
34 | E|-0-0-0-0-0-0-0-0-0-0-3-2-1-0-0-3-3-5-5-3-3-0-||
35 |
36 | }
37 |
38 | sequence keyboards piano_tabs
39 | {
40 |
41 | R|-8-8-8-8---8-8-8-8-8-8-----8-8-8-8---8-8-8-2-||
42 | 4|-e-g-------a-g---g---------e-g-------g-e-----||
43 |
44 | }
45 |
46 | sequence guitar-rhythm guitar_chords
47 | {
48 | E5(2) [2] A5(2) [2] A#5(2) [4] A(4) E5(4)
49 | }
50 |
51 | segment Chorus
52 | {
53 | guitar_tabs : guitar
54 | bass_tabs : bass
55 | guitar_chords : guitar2
56 | piano_tabs : piano
57 | }
58 |
59 | timeline
60 | {
61 | Chorus
62 | }
--------------------------------------------------------------------------------
/pytabs/gui/text/Text.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | from PySide.QtGui import QFont, QTextEdit
23 |
24 | from pytabs.gui.text.SyntaxHighlighter import SyntaxHighlighter
25 |
26 |
27 | class Text(QTextEdit):
28 |
29 |
30 | def setmodified(self):
31 | self.setModified(True)
32 |
33 |
34 | def __init__(self, parent=None, default_text="tekx"):
35 | super(Text,self).__init__(parent)
36 |
37 | self.font = QFont()
38 | self.font.setFamily( "Courier" )
39 | self.font.setFixedPitch( True )
40 | self.font.setPointSize( 10 )
41 | self.font.setBold(True)
42 |
43 | self.setFont(self.font)
44 | self.colorer = SyntaxHighlighter(self)
45 |
46 | self.setPlainText(default_text)
47 | self.textChanged.connect(self.setmodified)
48 |
--------------------------------------------------------------------------------
/pytabs/grammar/composition.tx:
--------------------------------------------------------------------------------
1 | /*
2 | # PyTabs - Simplified music notation DSL, interpreter and player.
3 | # Copyright (C) 2014, Milos Simic
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | */
18 |
19 | import chords
20 | import tablature
21 |
22 | Program:
23 | header=SongHeader
24 | imports=SoundFontImport
25 | sequences*=SongSequence
26 | segments*=TimelineSegment
27 | timeline=Timeline
28 | ;
29 |
30 | SongHeader:
31 | "["
32 | "Name" name=STRING
33 | "Author" author=STRING
34 | "Beat" beatup=INT "/" beatdown=INT
35 | "Tempo" tempo=INT
36 | "]"
37 | ;
38 |
39 | SoundFontImport:
40 | "import" soundfonts*=SoundFont
41 | ;
42 |
43 | SoundFont:
44 | name=ID path=STRING
45 | ;
46 |
47 | SongSequence:
48 | "sequence" type=InstrumentType name=ID
49 | "{"
50 |
51 | value=SourceType
52 |
53 | "}"
54 | ;
55 |
56 | InstrumentType:
57 | "guitar-solo"|"guitar-rhythm"|"drums"|"keyboards"|"bass"|"electro"
58 | ;
59 |
60 | SourceType:
61 | Tablature|GuitarChords
62 | ;
63 |
64 | TimelineSegment:
65 | "segment" name=ID "{" segmentlist*=TimelineSegmentList "}"
66 | ;
67 |
68 | TimelineSegmentList:
69 | sequence=[SongSequence] ":" soundfont=[SoundFont]
70 | ;
71 |
72 | Timeline:
73 | "timeline" "{" tracks*=[TimelineSegment][","] "}"
74 | ;
75 |
76 | Comment:
77 | /\/\/.*$/
78 | ;
--------------------------------------------------------------------------------
/pytabs/gui/window/MainForm.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | from PySide.QtCore import QSize
23 | from PySide.QtGui import QMainWindow, QIcon, QStackedWidget, QVBoxLayout
24 |
25 | from pytabs.gui.statusbar.StatusBar import StatusBar
26 | from pytabs.gui.tab.Tab import Tab
27 | from pytabs.gui.toolbar.ToolBar import Toolbar
28 |
29 |
30 | class MainForm(QMainWindow):
31 | def __init__(self, parent = None):
32 | super(MainForm,self).__init__(parent)
33 | self.initUI()
34 |
35 | self.widget = Tab()
36 | self.setCentralWidget(self.widget)
37 |
38 | self.toolbar = Toolbar(tab=self.widget)
39 | self.addToolBar(self.toolbar)
40 |
41 | self.statusbar = StatusBar()
42 | self.setStatusBar(self.statusbar)
43 |
44 | layout = QVBoxLayout()
45 | layout.addWidget(self.central_widget)
46 | self.setLayout(layout)
47 |
48 | def initUI(self):
49 | self.setWindowTitle("Spike pyTabs")
50 | self.setMinimumSize(QSize(800,600))
51 | self.setGeometry(100,100,300,200)
52 | self.setWindowIcon(QIcon('images/test.ico'))
53 | self.central_widget = QStackedWidget()
--------------------------------------------------------------------------------
/pytabs/player/player.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: zeljko.bal
21 | '''
22 | from threading import Thread
23 |
24 | from mingus.midi import fluidsynth
25 |
26 |
27 | class PlayerThread(Thread):
28 | def __init__(self, track, tempo, instrument):
29 |
30 | self.sequencer = fluidsynth.FluidSynthSequencer()
31 | self.sequencer.start_audio_output()
32 | self.sequencer.load_sound_font(instrument)
33 | self.sequencer.fs.program_reset()
34 |
35 | def execute():
36 | self.sequencer.play_Track(track, 1, tempo)
37 |
38 | super(PlayerThread, self).__init__(target=execute)
39 |
40 | def play(composition_model):
41 |
42 | segments = []
43 |
44 | # create threads
45 | for segment_model in composition_model.timeline.tracks:
46 | segment = []
47 |
48 | for sequence_model in segment_model.segmentlist:
49 | segment.append(PlayerThread(sequence_model.sequence.value, composition_model.header.tempo, composition_model.imports[sequence_model.soundfont.name]))
50 |
51 | segments.append(segment)
52 |
53 | # play threads segment by segment
54 | for segment in segments:
55 | for t in segment:
56 | t.start()
57 |
58 | for t in segment:
59 | t.join()
60 |
--------------------------------------------------------------------------------
/pytabs/gui/tab/Tab.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | import os
23 |
24 | from PySide.QtGui import QTabWidget, QMessageBox, QFileDialog
25 |
26 | from pytabs.gui.text.Text import Text
27 |
28 |
29 | class Tab(QTabWidget):
30 | def __init__(self, parent=None):
31 | super(Tab,self).__init__(parent)
32 | self.setTabsClosable(True)
33 | self.tabCloseRequested.connect(self.closeTab)
34 | self.setMovable(True)
35 |
36 | """self.centralText = Text("Neki tekst")
37 | self.addTab(self.centralText, "Text")"""
38 |
39 | def closeTab(self, index):
40 | if self.currentWidget().document().isModified():
41 | msgBox = QMessageBox()
42 | msgBox.setDefaultButton(QMessageBox.Save)
43 | msgBox.setInformativeText("Do you want to save your changes?")
44 | msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
45 | msgBox.setText("The document has been modified.")
46 | ret = msgBox.exec_()
47 |
48 | if ret == QMessageBox.Save:
49 | fileName,_ = QFileDialog.getSaveFileName(self,"Open PyTabs song", os.getcwd(), "PyTabs song files (*.song)")
50 |
51 | if fileName != "":
52 | with open(fileName, "w") as f:
53 | f.write(self.tab.currentWidget().toPlainText())
54 | self.removeTab(index)
55 | elif ret == QMessageBox.Discard:
56 | self.removeTab(index)
57 | else:
58 | pass
59 | else:
60 | self.removeTab(index)
61 |
62 |
--------------------------------------------------------------------------------
/pytabs/gui/window/NewDialog.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Feb 25, 2015
19 |
20 | @author: Milos
21 | '''
22 | import glob
23 | import os
24 | import sys
25 |
26 | from PySide import QtGui
27 | from PySide.QtCore import *
28 | from PySide.QtGui import QDialog, QVBoxLayout, QPushButton, QLabel
29 |
30 | import examples
31 |
32 |
33 | class NewDialog(QDialog):
34 |
35 | def __init__(self, parent=None):
36 | super(NewDialog, self).__init__(parent)
37 | self.INSTRUMENTS_PATH =os.path.abspath(os.path.dirname(examples.__file__))+'/songs/'
38 | self._createUI()
39 | self._createwidgets()
40 |
41 | def getallexamples(self):
42 | return []
43 |
44 | def _createUI(self):
45 | self.setGeometry(400,400,100,100)
46 | self.setWindowTitle("New document")
47 | self.setModal(True)
48 |
49 | def _createwidgets(self):
50 | self.label = QLabel("Choose template or blank document")
51 | layout = QVBoxLayout()
52 | self.setLayout(layout)
53 |
54 | self.combo = QtGui.QComboBox()
55 |
56 | self.rezz = [each for each in os.listdir(self.INSTRUMENTS_PATH) if each.endswith('.song')]
57 | self.rezz.append("Blank page")
58 |
59 | for l in self.rezz:
60 | self.combo.addItem(l)
61 |
62 | self.button = QPushButton("Create")
63 | self.button.clicked.connect(self.getcombovalue)
64 |
65 | layout.addWidget(self.label)
66 | layout.addWidget(self.combo)
67 | layout.addWidget(self.button)
68 |
69 | def getResult(self):
70 | path = self.INSTRUMENTS_PATH+self.combo.currentText()
71 | if self.combo.currentText() != "Blank page":
72 | doc = ""
73 | with open(path) as file:
74 | for line in file.readlines():
75 | doc+=line
76 | return doc
77 | else:
78 | return "Add some magic here ;)"
79 |
80 | def getcombovalue(self):
81 | self.close()
--------------------------------------------------------------------------------
/pytabs/gui/window/AboutDialog.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Feb 25, 2015
19 |
20 | @author: Milos
21 | '''
22 | import webbrowser
23 |
24 | from PySide.QtGui import QDialog, QLabel, QVBoxLayout
25 |
26 |
27 | class AboutDialog(QDialog):
28 | def __init__(self, parent=None):
29 | super(AboutDialog, self).__init__(parent)
30 | self._createUI()
31 | self._widgets()
32 |
33 | def _createUI(self):
34 | self.setGeometry(400,200,100,100)
35 | self.setWindowTitle("About PyTabs")
36 | self.setModal(True)
37 |
38 |
39 | def first_event(self):
40 | webbrowser.open('https://www.facebook.com/milos.simo.1')
41 |
42 |
43 | def second_event(self):
44 | webbrowser.open('https://www.facebook.com/zeljko.bal?fref=hovercard')
45 |
46 |
47 | def _widgets(self):
48 | intro = QLabel("\
49 |
pyTabs is a DSL for simplified music notation and\n\
50 | composition description
\n\
51 | This language is developed for the people who are not
\n\
52 | experts in writing and/or playing music and\n\
53 | can really help with learning.
\n\
54 | pyTabs goes a little bit further, and allows
\n\
55 | playback of compositions written in this way.
\n\
56 |
")
57 |
58 | contact = QLabel("Authors
")
59 |
60 | first = QLabel("")
61 | first.linkActivated.connect(self.first_event)
62 |
63 | second = QLabel("")
64 | second.linkActivated.connect(self.second_event)
65 |
66 | state = QLabel("Novi Sad, Serbia 2014-2015
")
67 |
68 | layout = QVBoxLayout()
69 | self.setLayout(layout)
70 |
71 | layout.addWidget(intro)
72 | layout.addWidget(contact)
73 | layout.addWidget(first)
74 | layout.addWidget(second)
75 | layout.addWidget(state)
--------------------------------------------------------------------------------
/examples/example_player.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: zeljko.bal
21 | '''
22 |
23 | from os.path import isfile, os
24 |
25 | from pytabs.composition.composition import parse_composition_file
26 | from pytabs.player.player import play
27 |
28 | BASE_DIR = os.path.dirname(os.path.realpath(__file__))+'/'
29 | SONGS_DIR = BASE_DIR+'songs/'
30 | INSTRUMENTS_DIR = SONGS_DIR+'instruments/'
31 |
32 | examples = ['smoke_on_the_water.song']
33 | instrument_dependencies={'Saber_5ths_and_3rds.sf2':'http://www.hammersound.com/cgi-bin/soundlink_download2.pl/Download%20USA;Saber_5ths_and_3rds.rar;724',
34 | 'Soundfont BassFing.sf2':'http://www.hammersound.com/cgi-bin/soundlink_download2.pl/Download%20USA;BassFing.rar;740',
35 | 'AJH_Piano.sf2':'http://www.hammersound.com/cgi-bin/soundlink_download2.pl/Download%20USA;AJH_Piano.rar;696',
36 | 'GuitarSetPasisHeavyAndClean.sf2':'http://www.hammersound.com/cgi-bin/soundlink_download2.pl/Download%20USA;GuitarSetPasisHeavyAndClean.rar;520',
37 | }
38 |
39 | def play_examples():
40 |
41 | has_unresolved = False
42 | for instrument in instrument_dependencies.keys():
43 | if not isfile(INSTRUMENTS_DIR+instrument):
44 | url = instrument_dependencies[instrument]
45 | print('Please download the soundfont: "{instrument}" from {url} and place it in the instruments folder at {instruments_dir}.'.format(instrument=instrument, url=url, instruments_dir=INSTRUMENTS_DIR))
46 | has_unresolved = True
47 |
48 | if not has_unresolved:
49 | for example in examples:
50 | composition_model = parse_composition_file(SONGS_DIR+example)
51 | print("********************************************")
52 | print("Song: {song_name} by {author}".format(song_name=composition_model.header.name, author=composition_model.header.author))
53 | print("********************************************")
54 | play(composition_model)
55 |
56 | if __name__ == '__main__':
57 | play_examples()
58 |
--------------------------------------------------------------------------------
/pytabs/composition/compositiontest.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 13, 2014
19 |
20 | @author: Milos
21 | '''
22 | import os
23 |
24 | from textx.metamodel import metamodel_from_file
25 |
26 | import pytabs
27 | from pytabs.chords.guitarchords import GuitarChordProcessor, chord_command_processor, chord_interval_processor
28 | from pytabs.guitar.guitar_tablature import GuitarNoteProcessor
29 | from pytabs.tablature.tablature import TablatureProcessor
30 | from pytabs.keyboards.keyboard_tablature import KeyboardNoteProcessor
31 |
32 | class Song:
33 | def interpret(self, model):
34 | print(" {} \n {} \n {}/{} \n {}".format(model.header.name,model.header.author,
35 | model.header.beatup,model.header.beatdown,
36 | model.header.tempo))
37 | print "---------"*4
38 |
39 | for sf in model.imports.soundfonts:
40 | print "{} {}".format(sf.name, sf.path)
41 |
42 | print "---------"*4
43 |
44 | for seq in model.sequences:
45 | print("{} {}".format(seq.type,seq.name))
46 | if(seq.value.__class__.__name__=="GuitarChords" and seq.type == "guitar-rhythm"):
47 | gpc = GuitarChordProcessor(guitar_model=seq.value)
48 | akords = gpc.guitarmodel_interprete()
49 |
50 | print akords
51 | elif(seq.value.__class__.__name__=="Tablature" and seq.type == "guitar-solo"):
52 | processor = TablatureProcessor(GuitarNoteProcessor())
53 | res = processor.process_tablature_model(seq.value)
54 | print res
55 |
56 | elif(seq.value.__class__.__name__=="Tablature" and seq.type == "keyboards"):
57 | processor = TablatureProcessor(KeyboardNoteProcessor)
58 | res = processor.process_tablature_model(seq.value)
59 | print res
60 |
61 | print "---------"*4
62 |
63 | for segment in model.segments:
64 | print segment.name
65 |
66 | print "---------"*4
67 |
68 | for track in model.timeline.tracks:
69 | for part in track.segmentlist:
70 | print("{} {}".format(part.sequence.name,
71 | part.soundfont.name))
72 |
73 | print "---------"*4
74 |
75 | if __name__ == "__main__":
76 | root_dir = os.path.abspath(os.path.dirname(pytabs.__file__))
77 | robot_mm = metamodel_from_file(root_dir+'/grammar/composition.tx', debug=False)
78 | robot_mm.register_obj_processors({'BaseExtended': chord_command_processor,
79 | "PrepExtended": chord_command_processor,
80 | "DecorateExtended":chord_command_processor,
81 | "ChordDuration":chord_interval_processor})
82 |
83 | robot_model = robot_mm.model_from_file('examples/track.song')
84 |
85 | music = Song()
86 | music.interpret(robot_model)
87 |
--------------------------------------------------------------------------------
/pytabs/gui/text/SyntaxHighlighter.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Oct 27, 2014
19 |
20 | @author: Milos
21 | '''
22 | import PySide
23 | from PySide.QtCore import *
24 | from PySide.QtGui import *
25 |
26 |
27 | class HighlightingRule(object):
28 | def __init__(self, pattern, format):
29 | self.pattern = pattern
30 | self.format = format
31 |
32 | class SyntaxHighlighter(QSyntaxHighlighter):
33 |
34 | def __init__(self, parent):
35 | super(SyntaxHighlighter, self).__init__(parent)
36 | self.keyword = QTextCharFormat()
37 | self.string = QTextCharFormat()
38 | self.comment = QTextCharFormat()
39 | self.highlightingRules = []
40 |
41 | brush = QBrush(Qt.darkBlue, Qt.SolidPattern)
42 | self.keyword.setForeground(brush)
43 | self.keyword.setFontWeight(QFont.Bold)
44 | """self.keyword = [ "break", "else", "for", "if", "in",
45 | "next", "repeat", "return", "switch",
46 | "try", "while" ]"""
47 |
48 | self.keyword = ["import", "sequence", "segment", "timeline", "guitar-rhythm",
49 | "guitar-solo", "bass", "drums", "keyboards", "electro", "Name","Author","Beat","Tempo"]
50 |
51 | for word in self.keyword:
52 | pattern = QRegExp("\\b" + word + "\\b")
53 | rule = HighlightingRule(pattern, Qt.darkBlue)
54 | self.highlightingRules.append(rule)
55 |
56 | # string
57 | brush = QBrush( Qt.darkGreen, Qt.SolidPattern )
58 | pattern = QRegExp( "\".*\"" )
59 | pattern.setMinimal( True )
60 | self.string.setForeground( brush )
61 | rule = HighlightingRule( pattern, Qt.darkGreen )
62 | self.highlightingRules.append( rule )
63 |
64 | # comment
65 | brush = QBrush( Qt.darkGray, Qt.SolidPattern )
66 | pattern = QRegExp( "//.*$" )
67 | self.comment.setForeground( brush )
68 | rule = HighlightingRule( pattern, Qt.darkGray )
69 | self.highlightingRules.append( rule )
70 |
71 | def highlightBlock(self, text):
72 | for rule in self.highlightingRules:
73 | expression = QRegExp(rule.pattern)
74 | index = expression.indexIn(text)
75 |
76 | """try:
77 | while index >= 0:
78 | length = expression.matchedLength()
79 | self.setFormat(index, length, Qt.darkBlue)
80 | index = text.index(expression.__str__(), index + length)
81 | except ValueError:
82 | pass"""
83 | while index >= 0:
84 | length = expression.matchedLength()
85 | self.setFormat(index, length, rule.format)
86 | index = text.find(expression.pattern(), index + length)
87 |
88 | self.setCurrentBlockState(0)
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/pytabs/keyboards/keyboard_tablature.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Bojana Sofronovic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Feb 10, 2015
19 |
20 | @author: Bojana
21 | '''
22 | from os.path import os
23 | from textx.metamodel import metamodel_from_file
24 |
25 | from mingus.containers import Note
26 | from mingus.containers import NoteContainer
27 | from mingus.containers import Track
28 | from pytabs.tablature.tablature import TablatureProcessor
29 |
30 | GRAMMAR_PATH = os.path.dirname(os.path.realpath(__file__)) + "/grammar/"
31 |
32 | class KeyboardNoteProcessor:
33 | """Processor for a single keyboard note."""
34 | def __init__(self, tab_note_grammar_file=None, default_duration=4):
35 | """Initializes note metamodel, if file is not specified initialize with default file."""
36 | if not tab_note_grammar_file:
37 | tab_note_grammar_file = GRAMMAR_PATH + "keyboard_tab_note.tx"
38 |
39 | self.tab_note_metamodel = metamodel_from_file(tab_note_grammar_file)
40 | self.default_duration = default_duration
41 |
42 | def _note_num_from_key(self, key, note_height):
43 | """Calculates a note number."""
44 | octave = int(key) * 12
45 |
46 | note = { "c":0, "C":1, "d":2, "D":3, "e":4, "f":5, "F":6, "g":7, "G":8, "a":9, "A":10, "b":11}[note_height]
47 |
48 | return note + octave
49 |
50 | def __call__(self, note_symbol, mark_symbol):
51 | """Processes a note based on note_symbol and string mark_symbol, returns a Note instance."""
52 | note_model = self.tab_note_metamodel.model_from_str(note_symbol)
53 |
54 | # skip rests
55 | if note_model == '-':
56 | if mark_symbol == 'R':
57 | return self.default_duration
58 | else:
59 | return None
60 |
61 | # just return the number if rythm string
62 | if mark_symbol == 'R':
63 | return int(note_symbol)
64 |
65 | note_num = self._note_num_from_key(mark_symbol,note_model.key)
66 | note = Note()
67 | note.from_int(note_num)
68 |
69 | return note
70 |
71 | class KeyboardTabProcessor:
72 | """Processor for a keyboard tab textx model."""
73 | def __init__(self, default_duration=4, additional_dashes=0):
74 | self.processor = TablatureProcessor(process_note=KeyboardNoteProcessor(default_duration=default_duration),
75 | additional_dashes=additional_dashes,
76 | container_type=list)
77 | self.default_duration = default_duration
78 |
79 | def process(self, tabs_model):
80 | """Processes the model and returns a mingus Track."""
81 | beats = self.processor.process_tablature_model(tabs_model)
82 | track = Track()
83 |
84 | for beat in beats:
85 | if tabs_model.strings[0].mark == 'R':
86 | track.add_notes(NoteContainer(beat[1:]), beat[0])
87 | else:
88 | track.add_notes(NoteContainer(beat), self.default_duration)
89 |
90 | return track
91 |
--------------------------------------------------------------------------------
/pytabs/guitar/guitar_tablature.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 12, 2014
19 |
20 | @author: zeljko.bal
21 | '''
22 | from os.path import os
23 | from textx.metamodel import metamodel_from_file
24 |
25 | from mingus.containers import Note
26 | from mingus.containers import NoteContainer
27 | from mingus.containers import Track
28 |
29 | from pytabs.tablature.tablature import TablatureProcessor
30 |
31 |
32 | GRAMMAR_PATH = os.path.dirname(os.path.realpath(__file__)) + "/grammar/"
33 |
34 | class TabNote(Note, object):
35 | """Mingus Note with additional parameters."""
36 | def __init__(self, name= 'C', octave = 4, dynamics = {}, pm = False):
37 | super(TabNote, self).__init__(name, octave, dynamics)
38 | self.pm = pm
39 |
40 | class GuitarNoteProcessor:
41 | """Processor for a single guitar note."""
42 | def __init__(self, tab_note_grammar_file=None, default_duration=4):
43 | """Initializes note metamodel, if file is not specified initialize with default file."""
44 | if not tab_note_grammar_file:
45 | tab_note_grammar_file = GRAMMAR_PATH + "guitar_tab_note.tx"
46 |
47 | self.tab_note_metamodel = metamodel_from_file(tab_note_grammar_file)
48 | self.default_duration = default_duration
49 |
50 | def _note_num_from_fret(self, fret, string_height):
51 | """Calculates a note number."""
52 | # base is the lowest E-0
53 | base = 3 * 12
54 | # frets from base to empty string
55 | string = {"e":28,
56 | "B":23,
57 | "G":19,
58 | "D":14,
59 | "A":9,
60 | "E":4,
61 | }[string_height]
62 | return base + string + int(fret)
63 |
64 | def __call__(self, note_symbol, mark_symbol):
65 | """Processes a note based on note_symbol and string mark_symbol, returns a Note instance."""
66 | note_model = self.tab_note_metamodel.model_from_str(note_symbol)
67 |
68 | # skip rests
69 | if note_model == '-':
70 | if mark_symbol == 'R':
71 | return self.default_duration
72 | else:
73 | return None
74 |
75 | # just return the number if rythm string
76 | if mark_symbol == 'R':
77 | return int(note_symbol)
78 |
79 | note_num = self._note_num_from_fret(note_model.fret, mark_symbol)
80 | note = TabNote(pm=note_model.pm)
81 | note.from_int(note_num)
82 |
83 | return note
84 |
85 | class GuitarTabProcessor:
86 | """Processor for a guitar tab textx model."""
87 | def __init__(self, default_duration=4, additional_dashes=0):
88 | self.processor = TablatureProcessor(process_note=GuitarNoteProcessor(default_duration=default_duration),
89 | additional_dashes=additional_dashes,
90 | container_type=list)
91 | self.default_duration = default_duration
92 |
93 | def process(self, tabs_model):
94 | """Processes the model and returns a mingus Track."""
95 | beats = self.processor.process_tablature_model(tabs_model)
96 | track = Track()
97 |
98 | for beat in beats:
99 | if tabs_model.strings[0].mark == 'R':
100 | track.add_notes(NoteContainer(beat[1:]), beat[0])
101 | else:
102 | track.add_notes(NoteContainer(beat), self.default_duration)
103 |
104 | return track
105 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #
PyTabs
2 |
3 | PyTabs is a DSL (Domain Specific Language) for simplified music notation and composition description. The projet includes an interpreter that creates an object model of a composition based on the provided description and a player that renders music based on that model, all of which is accessable through a simple GUI.
4 |
5 | In PyTabs language you can describe a composition which is composed of several segments played sequentially. Each segment consists of one or more sequences that are played together. Each sequence is played by a specified instrument and described in one of supported notations. Currently PyTabs supports guitar and keyboard tablatures and guitar chords and it can easily be extended to support other notations.
6 |
7 | An example of a composition in PyTabs language can be found in examples/songs/smoke_on_the_water.song . Here is the example with marked composition sections:
8 |
9 | 
10 |
11 | ## Technical description
12 |
13 | PyTabs is implemented in python programming language, it uses [textX] python library to define the language grammar and interpret compositions creating a python object model. The model obtained from textX is then interpreted for each notation and transformed into a composition model that uses [mingus] note container objects for note representation. This model can then be played using the [FluidSynth] library wrapper provided in mingus. FluidSynth uses [SoundFont] samples to play the music, so different soundfonts can be used to play different instrument in the same composition.
14 |
15 | ## Installation
16 |
17 | ####Requirements:
18 | - python v2.7
19 | - [textX] v0.3.1
20 | ```sh
21 | $ pip install textX
22 | ```
23 | - [mingus] v0.5.0
24 | ```sh
25 | $ pip install mingus
26 | ```
27 | - [PySide] (for GUI) v1.2.2
28 | ```sh
29 | $ pip install PySide
30 | ```
31 | - [FluidSynth]
32 | - Windows: fluidsynth.dll should be placed in PATH or in PyTabs lib directory (will be added to PATH when running start scripts), you can compile it yourself from [FluidSynth source] or download one from here http://svn.drdteam.org/zdoom/fluidsynth.7z (ofcourse download at your own risk, link found via stackoverflow).
33 | - Linux (not tested): for package installation see [FluidSynth downloads] or compile it yourself from [FluidSynth source]
34 |
35 | After installing all the requirements you can download or clone and start using the PyTabs project.
36 |
37 | ## Getting started
38 |
39 | To run the example song you can simply run the play_examples script in the root directory of the project.
40 | The first time you run it, it will tell you to download the necessary soundfont files and where to place them. After that you can run it again and you should be able to hear the music. The example can be found at examples/songs/smoke_on_the_water.song .
41 |
42 | You can also start the GUI by running the start_gui script in the root directory. Enter a valid composition description in PyTabs language such as the one provided in the example (you can click the 'new' button and choose to open the example file) and click the 'play' button to play the composition.
43 |
44 | 
45 |
46 | You can also check out the grammar definitions in pytabs/grammar. They are easy to understand and can help you write your own compositions.
47 |
48 | In order to import your own soundfonts just place the .sf2 files into examples/songs/instruments and add an import statement in the import section of your composition. It should look like:
49 | ```
50 | my_instrument_name "instruments/myInstrument.sf2"
51 | ```
52 |
53 | License
54 | ----
55 | PyTabs is a free and opensource project licensed under [GPLv3].
56 |
57 | [textX]:https://github.com/igordejanovic/textX
58 | [mingus]:https://code.google.com/p/mingus/
59 | [PySide]:http://qt-project.org/wiki/PySide
60 | [FluidSynth]:http://www.fluidsynth.org/
61 | [FluidSynth source]:http://sourceforge.net/projects/fluidsynth/files/fluidsynth-1.1.3/
62 | [FluidSynth downloads]:http://sourceforge.net/p/fluidsynth/wiki/Download/
63 | [SoundFont]:http://en.wikipedia.org/wiki/SoundFont
64 | [GPLv3]:http://www.gnu.org/licenses/
65 |
--------------------------------------------------------------------------------
/pytabs/composition/composition.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 | from mingus.containers import NoteContainer
17 |
18 | '''
19 | Created on Dec 25, 2014
20 |
21 | @author: zeljko.bal
22 | '''
23 | from os.path import os
24 |
25 | from mingus.containers import Track
26 | from textx.metamodel import metamodel_from_file
27 |
28 | import pytabs
29 | from pytabs.chords.guitarchords import chord_command_processor, \
30 | chord_interval_processor, GuitarChordProcessor, PauseChord
31 | from pytabs.guitar.guitar_tablature import GuitarTabProcessor
32 | from pytabs.keyboards.keyboard_tablature import KeyboardTabProcessor
33 |
34 |
35 | GRAMMAR_PATH = os.path.abspath(os.path.dirname(pytabs.__file__))+'/grammar/'
36 |
37 | def get_composition_metamodel(script_dir):
38 | composition_mm = metamodel_from_file(GRAMMAR_PATH + 'composition.tx', debug=False)
39 | composition_mm.register_obj_processors({'BaseExtended': chord_command_processor,
40 | "PrepExtended": chord_command_processor,
41 | "DecorateExtended":chord_command_processor,
42 | "ChordDuration":chord_interval_processor,
43 | "SongSequence":process_sequence,
44 | "Program":lambda program: process_instruments(program, script_dir),
45 | })
46 | return composition_mm
47 |
48 | def parse_composition_file(composition_file_path):
49 | composition_mm = get_composition_metamodel(script_dir=os.path.dirname(composition_file_path))
50 | return composition_mm.model_from_file(composition_file_path)
51 |
52 | def parse_composition_string(composition_string, script_dir):
53 | composition_mm = get_composition_metamodel(script_dir=script_dir)
54 | return composition_mm.model_from_str(composition_string)
55 |
56 | def process_sequence(sequence):
57 | processor = {
58 | "guitar-solo":process_guitar_tabs,
59 | "guitar-rhythm":process_chords,
60 | "keyboards":process_keyboard_tabs,
61 | }[sequence.type]
62 |
63 | sequence.value = processor(sequence.value)
64 |
65 | def process_keyboard_tabs(tabs_model):
66 | return KeyboardTabProcessor().process(tabs_model)
67 |
68 | def process_guitar_tabs(tabs_model):
69 | return GuitarTabProcessor().process(tabs_model)
70 |
71 | def process_chords(chords_model):
72 | processor = GuitarChordProcessor(guitar_model=chords_model)
73 | chords = processor.guitarmodel_interprete()
74 |
75 | track = Track()
76 |
77 | for chord,duration in chords:
78 | if isinstance(chord, PauseChord):
79 | track.add_notes(NoteContainer(), duration)
80 | else:
81 | track.add_notes(chord, duration)
82 |
83 | _change_track_octave(track, -1)
84 |
85 | return track
86 |
87 | def process_instruments(program, composition_file_path_dir):
88 | imports = {}
89 | for instrument in program.imports.soundfonts:
90 | path_prefix = ''
91 | if not os.path.isabs(instrument.path):
92 | path_prefix = composition_file_path_dir
93 | imports[instrument.name] = path_prefix+'/'+instrument.path
94 |
95 | program.imports = imports
96 |
97 | def _change_track_octave(track, n):
98 | if n == 0:
99 | return
100 | for _ in range(abs(n)):
101 | for bar in track.bars:
102 | for note in bar.bar[0][2]:
103 | if n > 0:
104 | note.octave_up()
105 | else:
106 | note.octave_down()
107 |
108 |
--------------------------------------------------------------------------------
/pytabs/gui/toolbar/ToolBar.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 25, 2014
19 |
20 | @author: Milos
21 | '''
22 | import os
23 |
24 | from PySide import QtGui
25 | from PySide.QtGui import QToolBar, QIcon, QFileDialog, QMessageBox
26 |
27 | import examples
28 | from pytabs.composition.composition import parse_composition_string
29 | from pytabs.gui.text.Text import Text
30 | from pytabs.gui.window.AboutDialog import AboutDialog
31 | from pytabs.gui.window.NewDialog import NewDialog
32 | from pytabs.player.player import play
33 |
34 |
35 | DEFAULT_INIT_TEXT="OVO JE IDEALNO MESTO DA SE DODA NEKI OSNOVNI TEKST"
36 |
37 | class Toolbar(QToolBar):
38 | def __init__(self, parent=None,tab=None):
39 | super(Toolbar,self).__init__(parent)
40 |
41 | self.createbuttons()
42 | self.wirebuttons()
43 |
44 | self.tab = tab
45 |
46 | def start_event(self):
47 | #index = self.tab.currentIndex()
48 | #print self.tab.currentWidget().toPlainText()
49 | INSTRUMENTS_PATH =os.path.abspath(os.path.dirname(examples.__file__))+'/songs'
50 |
51 | path = self.tab.currentWidget().toPlainText()
52 | rezz = parse_composition_string(composition_string=path,
53 | script_dir=INSTRUMENTS_PATH)
54 | play(rezz)
55 |
56 |
57 | def new_event(self):
58 | dialog = NewDialog(self)
59 | dialog.exec_()
60 | centralText = Text(default_text=dialog.getResult())
61 | self.tab.addTab(centralText, "New tab")
62 |
63 | def save_event(self):
64 | fileName,_ = QFileDialog.getSaveFileName(self,"Open PyTabs song", os.getcwd(), "PyTabs song files (*.song)")
65 |
66 | if fileName != "":
67 | with open(fileName, "w") as f:
68 | f.write(self.tab.currentWidget().toPlainText())
69 | msgBox = QMessageBox()
70 | msgBox.setText("The document has been saved.")
71 | msgBox.exec_()
72 |
73 |
74 | def open_event(self):
75 | fileName,_ = QFileDialog.getOpenFileName(self,"Open PyTabs song", os.getcwd(), "PyTabs song files (*.song)")
76 |
77 | if fileName != "":
78 | with open(fileName) as file:
79 | doc = ""
80 | for line in file.readlines():
81 | doc += line
82 |
83 | centralText = Text(default_text=doc)
84 | self.tab.addTab(centralText, "New Tab")
85 |
86 |
87 | def about_event(self):
88 | about = AboutDialog(self)
89 | about.exec_()
90 |
91 |
92 | def createbuttons(self):
93 | self.newcomposition = QtGui.QAction(QIcon('images/icon.png'), 'New composition', self)
94 | self.newcomposition.triggered.connect(self.new_event)
95 | self.newcomposition.setToolTip("Create tab for new composition")
96 |
97 | self.startcomposition = QtGui.QAction(QIcon('images/test.ico'), 'Start composition', self)
98 | self.startcomposition.triggered.connect(self.start_event)
99 | self.startcomposition.setToolTip("Start current composition")
100 |
101 | self.savecomposition = QtGui.QAction(QIcon('images/save.png'), 'Save composition', self)
102 | self.savecomposition.triggered.connect(self.save_event)
103 | self.savecomposition.setToolTip("Save current composition")
104 |
105 | self.opencomposition = QtGui.QAction(QIcon('images/open.png'), 'Open composition', self)
106 | self.opencomposition.triggered.connect(self.open_event)
107 | self.opencomposition.setToolTip("Open saved composition")
108 |
109 | self.about = QtGui.QAction(QIcon('images/about.png'), 'About PyTabs', self)
110 | self.about.triggered.connect(self.about_event)
111 | self.about.setToolTip("About PyTabs")
112 |
113 | self.exit = QtGui.QAction(QIcon('images/exit.png'), 'Exit', self)
114 | #self.exit.triggered.connect(self)
115 | self.exit.setToolTip("Exit")
116 |
117 | def wirebuttons(self):
118 | self.addAction(self.newcomposition)
119 | self.addAction(self.startcomposition)
120 |
121 | self.addSeparator()
122 |
123 | self.addAction(self.savecomposition)
124 | self.addAction(self.opencomposition)
125 |
126 | self.addSeparator()
127 |
128 | self.addAction(self.about)
129 | self.addAction(self.exit)
130 |
131 |
--------------------------------------------------------------------------------
/tests/guitar_tab_parser_test.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 12, 2014
19 |
20 | @author: zeljko.bal
21 | '''
22 | from textx.exceptions import TextXSyntaxError
23 | import unittest
24 |
25 | from mingus.containers import Note
26 |
27 | from pytabs.guitar.guitar_tablature import GuitarNoteProcessor
28 | from pytabs.tablature.tablature import TablatureParser, ParsingException
29 |
30 |
31 | class Test(unittest.TestCase):
32 |
33 | def setUp(self):
34 |
35 | self.parser = TablatureParser(GuitarNoteProcessor())
36 |
37 | self.test_tab_empty = """
38 | e|-0-||
39 | B|-0-||
40 | G|-0-||
41 | D|-0-||
42 | A|-0-||
43 | E|-0-||
44 | """
45 |
46 | self.test_tab_frets = """
47 | e|-1-||
48 | B|-2-||
49 | G|-3-||
50 | D|-4-||
51 | A|-5-||
52 | E|-6-||
53 | """
54 |
55 | self.test_tab_pm = """
56 | e|-0pm-||
57 | B|-0---||
58 | G|-0pm-||
59 | D|-0---||
60 | A|-0pm-||
61 | E|-0---||
62 | """
63 |
64 | self.test_tab_rests = """
65 | e|-0-||
66 | B|---||
67 | G|-0-||
68 | D|---||
69 | A|-0-||
70 | E|---||
71 | """
72 |
73 | self.test_tab_end_with_dash = """
74 | e|-0-||
75 | B|-10||
76 | G|-0-||
77 | D|-0-||
78 | A|-0-||
79 | E|-0-||
80 | """
81 |
82 | self.test_tab_equal_length = """
83 | e|-0-||
84 | B|-1-||
85 | G|-0-5-||
86 | D|-0-||
87 | A|-0-6-||
88 | E|-0-||
89 | """
90 |
91 | self.test_tab_missplaced_note = """
92 | e|-0-7--4-||
93 | B|-1--5-5-||
94 | G|-0-53-6-||
95 | D|-0-6--7-||
96 | A|-0-6--4-||
97 | E|-0---7--||
98 | """
99 |
100 | self.test_tab_multiple_columns = """
101 | e|-0-7--4-||
102 | B|-5-5--5-||
103 | G|-0-53-6-||
104 | D|-0-6--7-||
105 | A|-0-6--4-||
106 | E|-0----7-||
107 | """
108 |
109 | self.test_tab_additional_dashes = """
110 | e|-0---7----4---||
111 | B|-5---5----5---||
112 | G|-0---53---6---||
113 | D|-0---6----7---||
114 | A|-0---6----4---||
115 | E|-0--------7---||
116 | """
117 |
118 | def test_empty(self):
119 | note_container = self.parser.parse_tablature_string(self.test_tab_empty)[0]
120 | self.assertEquals(note_container[0], Note('E-3'))
121 | self.assertEquals(note_container[1], Note('A-3'))
122 | self.assertEquals(note_container[2], Note('D-4'))
123 | self.assertEquals(note_container[3], Note('G-4'))
124 | self.assertEquals(note_container[4], Note('B-4'))
125 | self.assertEquals(note_container[5], Note('E-5'))
126 |
127 | def test_frets(self):
128 | note_container = self.parser.parse_tablature_string(self.test_tab_frets)[0]
129 | self.assertEquals(note_container[0], Note('A#-3'))
130 | self.assertEquals(note_container[1], Note('D-4'))
131 | self.assertEquals(note_container[2], Note('F#-4'))
132 | self.assertEquals(note_container[3], Note('A#-4'))
133 | self.assertEquals(note_container[4], Note('C#-5'))
134 | self.assertEquals(note_container[5], Note('F-5'))
135 |
136 | def test_pm(self):
137 | note_container = self.parser.parse_tablature_string(self.test_tab_pm)[0]
138 | self.assertFalse(note_container[0].pm)
139 | self.assertTrue(note_container[1].pm)
140 | self.assertFalse(note_container[2].pm)
141 | self.assertTrue(note_container[3].pm)
142 | self.assertFalse(note_container[4].pm)
143 | self.assertTrue(note_container[5].pm)
144 |
145 | def test_equal_length(self):
146 | with self.assertRaises(ParsingException):
147 | self.parser.parse_tablature_string(self.test_tab_equal_length)
148 |
149 | def test_missplaced_note(self):
150 | with self.assertRaises(ParsingException):
151 | self.parser.parse_tablature_string(self.test_tab_missplaced_note)
152 |
153 | def test_end_with_dash(self):
154 | with self.assertRaises(TextXSyntaxError):
155 | self.parser.parse_tablature_string(self.test_tab_end_with_dash)
156 |
157 | def test_rests(self):
158 | note_container = self.parser.parse_tablature_string(self.test_tab_rests)[0]
159 | self.assertEquals(note_container[0], Note('A-3'))
160 | self.assertEquals(note_container[1], Note('G-4'))
161 | self.assertEquals(note_container[2], Note('E-5'))
162 | self.assertEquals(len(note_container), 3)
163 |
164 | def test_multiple_columns(self):
165 | self.assertEquals(len(self.parser.parse_tablature_string(self.test_tab_multiple_columns)), 3)
166 |
167 | def test_additional_dashes(self):
168 | self.parser.processor.additional_dashes = 2
169 | self.assertEquals(len(self.parser.parse_tablature_string(self.test_tab_additional_dashes)), 3)
170 |
171 | if __name__ == "__main__":
172 | #import sys;sys.argv = ['', 'Test.testName']
173 | unittest.main()
--------------------------------------------------------------------------------
/pytabs/tablature/tablature.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Zeljko Bal
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Dec 13, 2014
19 |
20 | @author: zeljko.bal
21 | '''
22 | from os.path import os
23 |
24 | from mingus.containers import NoteContainer
25 | from textx.metamodel import metamodel_from_file
26 | import pytabs
27 |
28 |
29 | GRAMMAR_PATH = os.path.abspath(os.path.dirname(pytabs.__file__))+'/grammar/'
30 |
31 | class TablatureProcessor:
32 | """
33 | Processes tablature model.
34 | """
35 |
36 | def __init__(self, process_note, additional_dashes=0, container_type=NoteContainer):
37 | """
38 | Accepts a process_note(note_symbol, mark_symbol) callable
39 | that returns a recognised object that can be stored in a container_type (NoteContainer by default).
40 | A number of additional dashes can be ignored following each note, specified by additional_dashes parameter.
41 | """
42 | assert process_note is not None
43 | self.process_note = process_note
44 | self.additional_dashes = additional_dashes
45 | self.container_type = container_type
46 |
47 | def extract_note_symbols(self, tab_strings_model, additional_dashes=0):
48 | """Extracts note characters from tab_strings_model and place them in a list of beat columns."""
49 | if len(tab_strings_model.strings) == 0:
50 | raise ParsingException("string list empty")
51 |
52 | if any(len(string.chars) == 0 for string in tab_strings_model.strings):
53 | raise ParsingException("there are empty strings")
54 |
55 | if not all(len(string.chars) == len(tab_strings_model.strings[0].chars) for string in tab_strings_model.strings):
56 | raise ParsingException("not all strings are of the same length")
57 |
58 | if not all(string.chars[-1] == '-' for string in tab_strings_model.strings):
59 | raise ParsingException("not all strings end with '-'")
60 |
61 | columns = []
62 |
63 | while True:
64 |
65 | # if nothing left to parse it's the end
66 | if len(tab_strings_model.strings[0].chars) == 0:
67 | return columns
68 |
69 | note_chars_column = []
70 |
71 | for string in tab_strings_model.strings:
72 | # characters before the first '-' go to note_chars, others go to string.chars
73 | note_chars, string.chars = string.chars.split('-', 1)
74 |
75 | # if it is a pause set note_chars to '-' and eat another '-' because split() didn't
76 | if note_chars == '':
77 | note_chars = '-'
78 | string.chars = self._eat_leading_dashes(string.chars, 1)
79 |
80 | note_chars_column.append(note_chars)
81 |
82 | columns.append(note_chars_column)
83 |
84 | # find maximum note character length
85 | max_length = len(max(note_chars_column, key=len))
86 |
87 | # eat max_length number of dashes from all other strings
88 | for string, chars in zip(tab_strings_model.strings, note_chars_column):
89 | # if all chars to eat are '-' eat, else error
90 | string.chars = self._eat_leading_dashes(string.chars, (max_length - len(chars)) + additional_dashes)
91 |
92 | def extract_string_marks(self, tab_strings_model):
93 | """Extracts the string mark symbol (at the beginning of the string)."""
94 | if len(tab_strings_model.strings) == 0:
95 | raise ParsingException("string list empty")
96 |
97 | mark_column = [string.mark for string in tab_strings_model.strings]
98 |
99 | if not all(len(mark) == len(mark_column[0]) for mark in mark_column):
100 | raise ParsingException("not all marks are of the same length")
101 |
102 | # extract everything up to the first '-'
103 | return [mark.split('-', 1)[0] for mark in mark_column]
104 |
105 | def _eat_leading_dashes(self, string, n):
106 | """Remove n number of leading dashes, if non dash character is encountered ParsingException is thrown."""
107 | if n == 0:
108 | return string
109 | elif len(string) == 0:
110 | raise ParsingException("expected '-' at: "+string)
111 | elif not all(c == '-' for c in string[:n]):
112 | raise ParsingException("expected '-' at: "+string)
113 | else:
114 | return string[n:]
115 |
116 | def process_tablature_model(self, tab_model):
117 | """Processes the tablature model (using note_processor) and returns a list of mingus NoteContainers that represent beats (columns in the tablature) filled with mingus Notes."""
118 |
119 | beats = self.extract_note_symbols(tab_model, self.additional_dashes)
120 | mark_symbols = self.extract_string_marks(tab_model)
121 |
122 | # list of container_type instances
123 | container_list = []
124 |
125 | # for every beat add a container
126 | for beat in beats:
127 |
128 | container = self.container_type()
129 |
130 | for note_symbol, mark_symbol in zip(beat, mark_symbols):
131 |
132 | # process the note_symbol and mark_symbol and get a Note instance
133 | note = self.process_note(note_symbol, mark_symbol)
134 |
135 | # add every note that is not None to container
136 | if note:
137 | container += [note]
138 |
139 | container_list.append(container)
140 |
141 | return container_list
142 |
143 | class TablatureParser:
144 | """
145 | Parses tablatures in form of:
146 | e|-0-----10-3-||
147 | B|-------1--1-||
148 | G|-12pm-----6-||
149 | D|-2-----9--0-||
150 | A|-2-----3--2-||
151 | E|------------||
152 |
153 | All notes must be separated by a dash '-' and they can be of arbitrary length (with parameters),
154 | every note must be followed by additional dashes for the length of the longest note in a column,
155 | all strings must be of equal length and each one must start with '|-' and end with '-||'
156 | """
157 |
158 | def __init__(self, note_processor, tab_grammar_file=None, additional_dashes=0):
159 | """Initializes metamodel and processor, if metamodel file is not specified initialize with default file."""
160 | self.processor = TablatureProcessor(note_processor, additional_dashes)
161 |
162 | if not tab_grammar_file:
163 | tab_grammar_file = GRAMMAR_PATH + "tablature.tx"
164 |
165 | self.tab_metamodel = metamodel_from_file(tab_grammar_file)
166 |
167 | def parse_tablature_string(self, tab_string):
168 | """Extracts tablature string model (textx) and then parses it."""
169 | tab_strings_model = self.tab_metamodel.model_from_str(tab_string)
170 | return self.processor.process_tablature_model(tab_strings_model)
171 |
172 | class ParsingException(Exception):
173 | def __init__(self, args):
174 | super(ParsingException, self).__init__(args)
175 |
--------------------------------------------------------------------------------
/pytabs/chords/guitarchords.py:
--------------------------------------------------------------------------------
1 | # PyTabs - Simplified music notation DSL, interpreter and player.
2 | # Copyright (C) 2014, Milos Simic
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License
15 | # along with this program. If not, see .
16 |
17 | '''
18 | Created on Nov 27, 2014
19 |
20 | @author: Milos
21 | '''
22 | import os
23 | from mingus.containers import NoteContainer
24 | from mingus.core.chords import from_shorthand
25 | from textx.metamodel import metamodel_from_file
26 | import pytabs
27 | from types import NoneType
28 |
29 |
30 | GRAMMAR_PATH = os.path.abspath(os.path.dirname(pytabs.__file__))+'/grammar/'
31 |
32 | DEFAULT_CHORD_DURATION = 4
33 | DEFAULT_EMPTY_NUMBER = ""
34 |
35 | class Music:
36 |
37 | def _prefix_decor_prep(self, c):
38 | prefixret = "".join([c.prefix.chord.base,str(c.prefix.chord.number),
39 | c.prefix.decor.name,str(c.prefix.decor.number),
40 | c.prefix.prep.name,str(c.prefix.prep.number)])
41 | return prefixret
42 |
43 | def _suffix_decor_prep(self, c):
44 | suffixret = "".join([c.suffix.chord.base,str(c.suffix.chord.number),
45 | c.suffix.decor.name,str(c.suffix.decor.number),
46 | c.suffix.prep.name,str(c.suffix.prep.number)])
47 | return suffixret
48 |
49 | def _prefix_decor_no_prep(self, c):
50 | prefixret = "".join([c.prefix.chord.base,str(c.prefix.chord.number),
51 | c.prefix.decor.name,str(c.prefix.decor.number)])
52 | return prefixret
53 |
54 | def _suffix_decor_no_prep(self, c):
55 | suffixret = "".join([c.suffix.chord.base,str(c.suffix.chord.number),
56 | c.suffix.decor.name,str(c.suffix.decor.number)])
57 | return suffixret
58 |
59 | def _prefix_no_decor_prep(self, c):
60 | prefixret = "".join([c.prefix.chord.base,str(c.prefix.chord.number),
61 | c.prefix.prep.name,str(c.prefix.prep.number)])
62 | return prefixret
63 |
64 | def _suffix_no_decor_prep(self, c):
65 | suffixret = "".join([c.suffix.chord.base,str(c.suffix.chord.number),
66 | c.suffix.prep.name,str(c.suffix.prep.number)])
67 | return suffixret
68 |
69 | def _prefix_no_decor_no_prep(self, c):
70 | prefixret = "".join([c.prefix.chord.base,str(c.prefix.chord.number)])
71 |
72 | return prefixret
73 |
74 | def _suffix_no_decor_no_prep(self, c):
75 | suffixret = "".join([c.suffix.chord.base,str(c.suffix.chord.number)])
76 |
77 | return suffixret
78 |
79 | def _add_note(self, note_name):
80 | """
81 | Metoda koja na osnovu imena akorda vraca NoteContainer iz imena. Ova
82 | metoda je direktno zavisna od pogloge tj mingusa u ovoj verziji!
83 | """
84 |
85 | n = NoteContainer()
86 | n.add_notes(from_shorthand(note_name))
87 |
88 | return n
89 |
90 | def _interval_time(self, chord):
91 | """
92 | Metoda koja proverava da li je zadat interval za duzinu trajanja akorda.
93 | Ako je zadata vrednost uzima je, ako nije vraca neku default vrednost
94 | """
95 |
96 | return chord.duration.time if type(chord.duration) is not NoneType else DEFAULT_CHORD_DURATION
97 |
98 | def interpret(self, model):
99 | chords = []
100 |
101 | for c in model.value:
102 | if(c.__class__.__name__=="ChordExtended"):
103 | if(c.suffix):
104 | #ima povisilicu ili snizilicu
105 | if(c.prefix.decor):
106 | #ima molove majeve susove divove itd
107 | if(c.prefix.prep):
108 | prefixchord = self._prefix_decor_prep(c)
109 | suffixchord = self._suffix_decor_prep(c)
110 | container = (self._add_note("{}/{}".format(prefixchord, suffixchord)),self._interval_time(c))
111 | chords.append(container)
112 | #nena nista od toga
113 | else:
114 | prefixchord = self._prefix_decor_no_prep(c)
115 | suffixchord = self._suffix_decor_no_prep(c)
116 | container = (self._add_note("{}/{}".format(prefixchord, suffixchord)),self._interval_time(c))
117 | chords.append(container)
118 | #nema povislicu ili snizilicu
119 | else:
120 | pass
121 | if(c.prefix.prep):
122 | prefixchord = self._prefix_no_decor_prep(c)
123 | suffixchord = self._suffix_no_decor_prep(c)
124 | container = (self._add_note("{}/{}".format(prefixchord, suffixchord)),self._interval_time(c))
125 | chords.append(container)
126 | else:
127 | prefixchord = self._prefix_no_decor_no_prep(c)
128 | suffixchord = self._suffix_no_decor_no_prep(c)
129 | container = (self._add_note("{}/{}".format(prefixchord, suffixchord)),self._interval_time(c))
130 | chords.append(container)
131 | else:
132 | #ima povisilicu ili snizilicu
133 | if(c.prefix.decor):
134 | #ima molove majeve susove divove itd
135 | if(c.prefix.prep):
136 | prefixchord = self._prefix_decor_prep(c)
137 | container = (self._add_note("{}".format(prefixchord)), self._interval_time(c))
138 | chords.append(container)
139 | #nena nista od toga
140 | else:
141 | prefixchord = self._prefix_decor_no_prep(c)
142 | container = (self._add_note("{}".format(prefixchord)), self._interval_time(c))
143 | chords.append(container)
144 | #nema povislicu ili snizilicu
145 | else:
146 | if(c.prefix.prep):
147 | prefixchord = self._prefix_no_decor_prep(c)
148 | container = (self._add_note("{}".format(prefixchord)), self._interval_time(c))
149 | chords.append(container)
150 | else:
151 | prefixchord = self._prefix_no_decor_no_prep(c)
152 | container = (self._add_note("{}".format(prefixchord)), self._interval_time(c))
153 | chords.append(container)
154 | else:
155 | pause = PauseChord(duration=c.time)
156 | container = (pause, pause.duration)
157 | chords.append(container)
158 |
159 | self.akordi = [x for x in chords]
160 |
161 | class PauseChord(object):
162 | """
163 | Class that represent a pose Chord.
164 | Args (int) duration :duration of time how long pause will last
165 | """
166 |
167 | def __init__(self,duration):
168 | self.value = None
169 | self.duration = duration
170 | self.name = "Pause"
171 |
172 | def __str__(self, *args, **kwargs):
173 | return "{}".format(self.name)
174 |
175 | def __repr__(self, *args, **kwargs):
176 | return self.__str__()
177 |
178 | def chord_command_processor(move_cmd):
179 | """
180 | Procesor koji ce u slucaju da se pojavi akord bez pridruzene INT vrednosti,
181 | prebaciti 0 u prazan string. Na ovaj nacin mingus moze da svira samo akord.
182 |
183 | Args:move_cmd model koji se proverava
184 |
185 | """
186 | if move_cmd.number == 0:
187 | move_cmd.number = DEFAULT_EMPTY_NUMBER
188 |
189 | def chord_interval_processor(move_cmd):
190 | """
191 | Procesor koji ce u slucaju da je interval trajanja akorda ostavljen na 0
192 | prebaciti na 4, Razlog tome je posto mingus ocekuje neku vrednost koliko
193 | traje akord ceo ton, pola,osminu,cetrtinu,....
194 |
195 | Args:move_cmd model koji se proverava
196 |
197 | """
198 | if move_cmd.time == 0:
199 | move_cmd.time = DEFAULT_CHORD_DURATION
200 |
201 | class GuitarChordProcessor(object):
202 | """
203 | Class that will take file where chords are and/or take model of chords
204 | Args:
205 | (string):guitar_chords_grammar_file where grammer that
206 | represent chords is
207 | guitar_model (textx model):model to process
208 | """
209 |
210 | def __init__(self, guitar_chords_grammar_file=None, guitar_model = None):
211 |
212 | if not guitar_chords_grammar_file:
213 | guitar_chords_grammar_file = GRAMMAR_PATH +'chords.tx'
214 |
215 | self.guitar_chords_mm = metamodel_from_file(guitar_chords_grammar_file, debug=False)
216 | self.guitar_chords_mm.register_obj_processors({'BaseExtended': chord_command_processor,
217 | "PrepExtended":chord_command_processor,
218 | "DecorateExtended":chord_command_processor,
219 | "ChordDuration":chord_interval_processor})
220 | self.guitar_chords_model = guitar_model
221 | #guitar_chords_model = guitar_chords_mm.model_from_file('examples/rythm.mcx')
222 |
223 | def guitarchords_model_from_file(self, file_path):
224 | """
225 | Read sample from file and trasport it to metamodel in text
226 | Args:
227 | file_path (string):path where sample is
228 | """
229 |
230 | self.guitar_chords_model = self.guitar_chords_mm.model_from_file(file_path)
231 |
232 | def guitarchords_model_from_str(self, model_str):
233 | """
234 | Read sample from string and trasport it to metamodel in text
235 | Args:
236 | file_path (string):string of sample
237 | """
238 |
239 | self.guitar_chords_model = self.guitar_chords_mm.model_from_str(model_str)
240 |
241 | def guitarmodel_interprete(self):
242 | """
243 | For a givem metamodel prepare model by iterate trough metamodel
244 | """
245 |
246 | music = Music()
247 | music.interpret(self.guitar_chords_model)
248 |
249 | return music.akordi
250 |
251 |
252 |
253 | if __name__ == "__main__":
254 |
255 | root_dir = os.path.abspath(os.path.dirname(pytabs.__file__))
256 | gpc = GuitarChordProcessor()
257 | gpc.guitarchords_model_from_file('examples/rythm2.mcx')
258 | akords = gpc.guitarmodel_interprete()
259 |
260 | for b in akords:
261 | print b
262 |
263 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------