From 76bdc225976a4fa82526911381007e100bd3c8cd Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 14 Nov 2018 19:46:45 +0200 Subject: [PATCH] 05 --- res/lang/instr_en.loc | 2 - res/lang/instr_ru.loc | 8 +- res/lang/strings_en.loc | 4 +- res/lang/strings_ru.loc | 10 +- res/test.mid | Bin 0 -> 148 bytes src/main/L.java | 4 +- src/main/Rms.java | 2 + src/main/text.txt | 13 +- src/midedit/CompositionForm.java | 344 +++++++++++++-------------- src/midedit/DrumsCanvas.java | 186 +++++++-------- src/midedit/MidiFile.java | 26 +- src/midedit/MixerCanvas.java | 80 ++++--- src/midedit/MixerModel.java | 43 +--- src/midedit/Note.java | 19 +- src/midedit/NoteList.java | 54 ++--- src/midedit/NoteListUtils.java | 54 ++--- src/midedit/NoteLong.java | 30 +-- src/midedit/NotesCanvas.java | 4 +- src/midedit/TempoList.java | 8 +- src/midedit/UndoableAction.java | 38 +-- src/midedit/VolumeForm.java | 6 +- src/midedit/WaitForm.java | 88 ------- src/midedit/Waitable.java | 10 +- src/midedit/media/Composition.java | 17 +- src/midedit/media/JSR135Player.java | 63 +++-- src/midedit/media/PreviewPlayer.java | 3 +- src/ui/FileManager.java | 27 ++- src/ui/Menu.java | 2 +- src/ui/SettingsForm.java | 4 +- src/ui/UI.java | 26 +- src/ui/WaitCanvas.java | 107 +++++++++ 31 files changed, 664 insertions(+), 618 deletions(-) create mode 100644 res/test.mid delete mode 100644 src/midedit/WaitForm.java create mode 100644 src/ui/WaitCanvas.java diff --git a/res/lang/instr_en.loc b/res/lang/instr_en.loc index 925ed76..a20aab2 100644 --- a/res/lang/instr_en.loc +++ b/res/lang/instr_en.loc @@ -127,7 +127,6 @@ Telephone ring Helicopter Applause Gunshot - Piano Chromatic percussion Organ @@ -144,7 +143,6 @@ Synth sfx Ethnic misc Percussive Sfx - Highq Slap Scratch push diff --git a/res/lang/instr_ru.loc b/res/lang/instr_ru.loc index 82bb745..45d3fee 100644 --- a/res/lang/instr_ru.loc +++ b/res/lang/instr_ru.loc @@ -9,7 +9,7 @@ Клавинет (клавесин 2) Челеста Колокольчики (бутылки) -'Музыкальная шкатулка' +Музыкальная шкатулка Вибрафон Маримба Ксилофон @@ -54,7 +54,7 @@ Хор на слог 'а' Голос на слог 'о' Синтетический голос -'Удар' (весь оркестр) +Удар (весь оркестр) Труба Тромбон Туба @@ -90,7 +90,7 @@ Charang-гитара Синтезаторный звук нью-эйдж Теплый синт-звук Полисинтезатор -Синт-'хор' +Синт-хор Воздушный (смычковый синт-звук) Металлический синт Ореол @@ -127,7 +127,6 @@ Charang-гитара Вертолет Алодисменты Выстрел - Фортепиано Хроматиккаа и Перкуссия Орган @@ -144,7 +143,6 @@ Charang-гитара Народные Перкуссия Звуковые эффекты - Высокое Q Слэп Царапанье (от себя) diff --git a/res/lang/strings_en.loc b/res/lang/strings_en.loc index e14e1c4..031cba6 100644 --- a/res/lang/strings_en.loc +++ b/res/lang/strings_en.loc @@ -93,4 +93,6 @@ Navigation Nums, otherwise keypad, when edit notes Name Temp directory -New folder \ No newline at end of file +New folder +Memory +MidEdit \ No newline at end of file diff --git a/res/lang/strings_ru.loc b/res/lang/strings_ru.loc index ef5f88b..536de44 100644 --- a/res/lang/strings_ru.loc +++ b/res/lang/strings_ru.loc @@ -66,8 +66,8 @@ Ok Вставить Темп Удалить Темп Темп -Время(Мера) -Поиск +Время (мера) +Позиция числитель знаменатель(2 в степени) Метр = числитель/ (2^знаменатель). Например, используйте 4/4 (numerator=4; denominator=2) или 6/8 (numerator=6; denominator=3) @@ -86,11 +86,13 @@ Ok Заменить Наложить Очистить буфер -Подсказка +Помощь Клавиши Быстрые команды Навигация Цифрами, иначе джойстиком, при редактировании нот Имя Временная папка -Новая папка \ No newline at end of file +Новая папка +Память +MidEdit \ No newline at end of file diff --git a/res/test.mid b/res/test.mid new file mode 100644 index 0000000000000000000000000000000000000000..d808445cdab910889abf2583f18c17af5aa65fd4 GIT binary patch literal 148 zcmeYb$w*;fU|?fl1i}x#Aw}6hULC^$Muz`^% Constants.DRUMS_LENGTH) { + nH = Constants.DRUMS_LENGTH; + } + hStep = 4; + hMin = drumsShift; + hMax = (drumsShift + Constants.DRUMS_LENGTH - 1); + hBase = hMin; + curY = 0; + } - byte[] b = new byte[Constants.NCHANNEL]; - for(int i=0; i Constants.DRUMS_LENGTH) - nH = Constants.DRUMS_LENGTH; - hStep = 4; - hMin = drumsShift; - hMax = (drumsShift + Constants.DRUMS_LENGTH-1); - hBase = hMin; - curY = 0; - } - /** - * - * @return - */ - protected boolean doKEY_NUM5() - { - if(super.doKEY_NUM5() == false) - composition.addNoteOn(getCurTime(),(byte)channel, - (byte)getNoteFromLine(curY), (byte)getCurVol(),0,true); - return true; - } -protected void doSmallDown (){ - if(hBase+curY < hMax) - super.doSmallDown(); - }; + /** + * + * @return + */ + protected boolean doKEY_NUM5() { + if (super.doKEY_NUM5() == false) { + composition.addNoteOn(getCurTime(), (byte) channel, + (byte) getNoteFromLine(curY), getCurVol(), 0, true); + } + return true; + } + protected void doSmallDown() { + if (hBase + curY < hMax) { + super.doSmallDown(); + } + } - /** - * - * @param val - public void setCurInstrument(int val) - { - int n = val + DrumsTable.SHIFT; - for(int i=0; i*/0x21,0xf2,0xf3,/*<-*/ ///*37>*/0x00,0xc0,0x1a, /*40>*/0x00,0x90,0x2e,0x01, //0x08,0x99,0x2e,0x7f, 0x7f,0x90,0x2e,0x01, @@ -42,8 +42,8 @@ public class MidiFile implements Waitable { private static int intTmp; private static byte[] bMidi = new byte[sizeMax]; - //public static void setTemp(int t) - //{ temp = t; } + //public static void setTemp(int noteTime) + //{ temp = noteTime; } //public static int getTemp() //{ return temp; } public MidiFile(AbstractFile aFile) { @@ -295,11 +295,11 @@ public class MidiFile implements Waitable { } /// calc maxTime for set end Note - if (note.t > maxTime) { - maxTime = note.t; + if (note.noteTime > maxTime) { + maxTime = note.noteTime; } - tnote = getVarLenRepr(note.t - tPrev); // Delta-Time + tnote = getVarLenRepr(note.noteTime - tPrev); // Delta-Time if (tnote.length == 0) { throw new Exception("len==0"); } @@ -335,7 +335,7 @@ public class MidiFile implements Waitable { /////////// ind += 3; } - tPrev = note.t; + tPrev = note.noteTime; seekPos++; Thread.yield(); } @@ -378,7 +378,7 @@ public class MidiFile implements Waitable { { // outStr = ""+nn+".mid"; //outStr = "note.mid"; - // mod.msg("len dat ."+dat.length+" "); + // mod.msg("length dat ."+dat.length+" "); //byte[] b = new byte[dat4PlayNote.length]; //for(int i=0; i 0) { + if (curNote.length > 0) { Note noteTmp; for (noteTmp = curNote.next; noteTmp != null && (noteTmp.c != curNote.c || noteTmp.n != curNote.n || noteTmp.v != 0); @@ -367,7 +367,7 @@ public abstract class MixerCanvas extends Canvas implements Runnable { } if (curNote != null) { - composition.delNote(curNote.t, curNote.c, curNote.n, curNote.v); + composition.delNote(curNote.noteTime, curNote.c, curNote.n, curNote.v); } else { composition.delNote(getCurTime(), (byte) channel, (byte) getNoteFromLine(curY), (byte) 127); } @@ -430,11 +430,7 @@ public abstract class MixerCanvas extends Canvas implements Runnable { keyPressedCount++; } else { - int gameAction = 0; - try { - gameAction = getGameAction(keyCodePressed); - } catch (IllegalArgumentException illegArg) { - } + int gameAction = getGameAction(keyCodePressed); if (keyCodePressed == KEY_NUM4 || keyCodePressed == KEY_NUM6 || gameAction == LEFT || gameAction == RIGHT || gameAction == UP || gameAction == DOWN || keyCodePressed == KEY_NUM2 || keyCodePressed == KEY_NUM8 @@ -529,10 +525,10 @@ public abstract class MixerCanvas extends Canvas implements Runnable { curNote = null; g.setGrayScale(0); for (note = composition.getFirstNote(tBeg, channel); - note != null && note.t <= tMax; note = note.next) { + note != null && note.noteTime <= tMax; note = note.next) { if (note.c == channel && note.v != 0) { - if (note.t <= curTimePlus && note.n == curN - && (curTime < note.t + (note.len == 0 ? 1 : note.len))) { + if (note.noteTime <= curTimePlus && note.n == curN + && (curTime < note.noteTime + (note.length == 0 ? 1 : note.length))) { curNote = note; if (!isMarkMode) { g.setColor(150, 0, 0); @@ -631,7 +627,7 @@ public abstract class MixerCanvas extends Canvas implements Runnable { * @param shiftNote */ protected void paintNote(Graphics g, Note note, int shiftTime, int shiftNote) { - xt = getXInPixel(note.t + shiftTime); + xt = getXInPixel(note.noteTime + shiftTime); yt = getLineFromNote(note.n + shiftNote); if (xt >= 0 && xt < rollWidth) { if (yt < 0) { @@ -744,7 +740,7 @@ public abstract class MixerCanvas extends Canvas implements Runnable { /** * - * @param t + * @param noteTime * @return */ private int getX(int t) { @@ -753,7 +749,7 @@ public abstract class MixerCanvas extends Canvas implements Runnable { /** * - * @param t + * @param noteTime * @return */ protected int getXInPixel(int t) { @@ -1179,8 +1175,8 @@ public abstract class MixerCanvas extends Canvas implements Runnable { m2 = 50; m3 = 75; m4 = 100; - PrintSmallFont.print(g, note.t * 100 / tick, 2, m1 - xIndent, yIndent, color); - PrintSmallFont.print(g, note.len * 1000 / tick, 3, m2 - xIndent, yIndent, color); + PrintSmallFont.print(g, note.noteTime * 100 / tick, 2, m1 - xIndent, yIndent, color); + PrintSmallFont.print(g, note.length * 1000 / tick, 3, m2 - xIndent, yIndent, color); if (MixerCanvas.this instanceof NotesCanvas) { PrintSmallFont.printNote(g, note.n % 12, m3 - xIndent, yIndent, color); @@ -1198,13 +1194,13 @@ public abstract class MixerCanvas extends Canvas implements Runnable { m3 = 55; m4 = 70; - PrintSmallFont.print(g, note.t / tick, 0, m1, yIndent, color); + PrintSmallFont.print(g, note.noteTime / tick, 0, m1, yIndent, color); g.drawLine(m1 + 1, yIndent - 4, m1 + 1, yIndent - 4); g.drawLine(m1 + 1, yIndent - 2, m1 + 1, yIndent - 2); - PrintSmallFont.print(g, (note.t * meterNom / tick) % meterNom, 0, m2, yIndent, color); + PrintSmallFont.print(g, (note.noteTime * meterNom / tick) % meterNom, 0, m2, yIndent, color); g.drawLine(m2 + 1, yIndent - 4, m2 + 1, yIndent - 4); g.drawLine(m2 + 1, yIndent - 2, m2 + 1, yIndent - 2); - PrintSmallFont.print(g, note.t % mod, 0, m3, yIndent, color); + PrintSmallFont.print(g, note.noteTime % mod, 0, m3, yIndent, color); PrintSmallFont.print(g, mod, 0, m4, yIndent, color); break; @@ -1234,10 +1230,10 @@ public abstract class MixerCanvas extends Canvas implements Runnable { } } - PrintSmallFont.print(g, note.len * meterNom / tick, 0, m2, yIndent, color); + PrintSmallFont.print(g, note.length * meterNom / tick, 0, m2, yIndent, color); g.drawLine(m2 + 1, yIndent - 4, m2 + 1, yIndent - 4); g.drawLine(m2 + 1, yIndent - 2, m2 + 1, yIndent - 2); - PrintSmallFont.print(g, note.len % mod, 0, m3, yIndent, color); + PrintSmallFont.print(g, note.length % mod, 0, m3, yIndent, color); PrintSmallFont.print(g, mod, 0, m4, yIndent, color); break; @@ -1463,14 +1459,13 @@ public abstract class MixerCanvas extends Canvas implements Runnable { MenuItem exitItem = new MenuItem(L.str[L.back], 0) { public boolean actionPerformed() { - CompositionForm.curForm.setComposForm(); + Main.midlet.compositionForm.setComposForm(); return true; } }; mainMenu.addItem(exitItem); menu = mainMenu; - } private String createString(String[] strings) { @@ -1492,10 +1487,6 @@ public abstract class MixerCanvas extends Canvas implements Runnable { protected void paint(Graphics g) { menu.paint(g); - - } - - public void run() { } private boolean processCommand(int keyCode) { @@ -1603,6 +1594,9 @@ public abstract class MixerCanvas extends Canvas implements Runnable { // private int optWidth = (screenWidth - 2 * optXbeg); // private int optHeight = (screenHeight - 2 * optYbeg); + /** + * + */ private class Menu extends MenuItem { private Vector items = null; @@ -1636,6 +1630,10 @@ public abstract class MixerCanvas extends Canvas implements Runnable { private void addItem(MenuItem item) { items.addElement(item); + // + int itemWidth = P.medBold.stringWidth(item.getName())+2; + if(itemWidth > w) w = itemWidth; + numLines = hMax / LINE_HEIGHT; if (numLines >= items.size()) { numLines = items.size(); @@ -1651,7 +1649,8 @@ public abstract class MixerCanvas extends Canvas implements Runnable { g.translate(x, y); g.setColor(P.colup); - g.fillRect(0, 1, w, LINE_HEIGHT - 1); + ui.UI.drawRect(g, P.colup, P.coldn, 0, 1, w, LINE_HEIGHT - 1); + // g.fillRect(0, 1, w, LINE_HEIGHT - 1); g.setColor(0); g.drawRect(0, 1, w - 1, LINE_HEIGHT - 1); g.setClip(0, 1, w - 1, LINE_HEIGHT - 1); @@ -1759,22 +1758,39 @@ public abstract class MixerCanvas extends Canvas implements Runnable { } } + /** + * + */ class MenuItem { + /** */ private String name; + + /** */ private int keyCode; -// public MenuItem() { -// } - private MenuItem(String str, int key) { - name = str; + /** + * + * @param name + * @param key + */ + private MenuItem(String name, int key) { + this.name = name; keyCode = key; } + /** + * + * @return + */ protected String getName() { return name; } + /** + * + * @return + */ public boolean actionPerformed() { return processCommand(keyCode); } diff --git a/src/midedit/MixerModel.java b/src/midedit/MixerModel.java index 7ff9e67..afde83c 100644 --- a/src/midedit/MixerModel.java +++ b/src/midedit/MixerModel.java @@ -23,10 +23,6 @@ public class MixerModel extends Thread { * */ public final Display display = Main.dsp; - /** - * - */ - //public final MixerModel thisModel; private NoteListUtils buffer; static AbstractFile rmsFile = new RMSFile(), //localFile,//=rmsFile, @@ -35,15 +31,12 @@ public class MixerModel extends Thread { public MixerModel() { try { - - //System.out.println("microedition.io.file.FileConnection.version="+System.getProperty("microedition.io.file.FileConnection.version")); if (System.getProperty("microedition.io.file.FileConnection.version") != null) { jsr75File = new JSR75File(); } else { jsr75File = rmsFile; } if (crossPlayer == null) { - try { Class.forName("javax.microedition.media.Player"); crossPlayer = new JSR135Player(); @@ -53,11 +46,7 @@ public class MixerModel extends Thread { } catch (Exception e) { Alert a = new Alert(L.str[L.apiError], L.str[L.apiError] + ":\n" + e.getMessage(), null, null); display.setCurrent(a); - } - - - mfile = new MidiFile(getLocalFile()); buffer = new NoteListUtils(); } @@ -70,24 +59,13 @@ public class MixerModel extends Thread { return buffer; } -// /** -// * -// * @param c -// * @param count -// * @throws Exception -// */ -// public void playMix(Composition c, int count) throws Exception { -// playMix(c, 0, 0); -// } /** * * @param c - * @param count * @param t * @throws Exception */ public void playMix(Composition c, int t) throws Exception { - crossPlayer.close(); getLocalFile().close(0); setLocalFile(); @@ -100,23 +78,17 @@ public class MixerModel extends Thread { * * @param instrum * @param nn - * @param vv */ public void playNote(byte instrum, byte nn) { - try { - crossPlayer.close(); - crossPlayer.playTest(mfile.writeNote(instrum, nn)); } catch (Exception e) { - CompositionForm.msg("MixerModel: 134: playNote " + e.getMessage()); + CompositionForm.msg("MixerModel: 91: playNote " + e.getMessage()); } } public void playTest(byte instrum) { - - crossPlayer.close(); mfile.writeTest(instrum); crossPlayer.playTest(mfile.writeTest(instrum)); @@ -125,7 +97,6 @@ public class MixerModel extends Thread { /** * * @param c - * @param count * @param t * @param channel * @param instrument @@ -143,7 +114,6 @@ public class MixerModel extends Thread { /** * * @param c - * @param count * @param t * @param channel * @throws Exception @@ -156,14 +126,10 @@ public class MixerModel extends Thread { * */ public void stopPlay() { - crossPlayer.close(); + if(crossPlayer != null) + crossPlayer.close(); } - /** - * - */ - public void run() { - } /** * @@ -192,8 +158,7 @@ public class MixerModel extends Thread { public Composition openMix(String name) throws Exception { Composition c; if (name != null) { - c = mfile.readMix( - name); + c = mfile.readMix(name); c.setName(name); } else { c = new Composition(); diff --git a/src/midedit/Note.java b/src/midedit/Note.java index f9a357d..c0b05b0 100644 --- a/src/midedit/Note.java +++ b/src/midedit/Note.java @@ -1,29 +1,30 @@ package midedit; /** - * + * * @author user */ public class Note { + + public byte c, n, v, mark; + public int noteTime, length; + public Note next = null, prev = null; + /** * - * @param tt + * @param time * @param ch * @param nn * @param vv * @param ll */ - public byte c, n, v, mark; - public int t, len; - public Note next = null, prev = null; - - public Note(int tt, byte ch, byte nn, byte vv, int ll) { - t = tt; + public Note(int time, byte ch, byte nn, byte vv, int ll) { + this.noteTime = time; c = ch; n = nn; v = vv; - len = ll; + length = ll; mark = NoteListUtils.NOTE_NOT_MARKED; } } diff --git a/src/midedit/NoteList.java b/src/midedit/NoteList.java index c865fa0..db64849 100644 --- a/src/midedit/NoteList.java +++ b/src/midedit/NoteList.java @@ -35,7 +35,7 @@ public class NoteList { if(noteExist==null) return null; - t = noteExist.t; + t = noteExist.noteTime; len++; if(noteBeg == null) noteBeg = note = noteExist; @@ -44,11 +44,11 @@ public class NoteList noteNew = noteExist; if(note == null) note = noteBeg; - if(note.t != t) - { if(t < note.t) + if(note.noteTime != t) + { if(t < note.noteTime) { for(noteTmp = note; - noteTmp != null && t < noteTmp.t; + noteTmp != null && t < noteTmp.noteTime; noteTmp = noteTmp.prev) ; if(noteTmp == null) @@ -60,7 +60,7 @@ public class NoteList } else { for(noteTmp = note; - noteTmp.next != null && (noteTmp.next.t < t ) ; + noteTmp.next != null && (noteTmp.next.noteTime < t ) ; noteTmp = noteTmp.next) ; note = noteTmp; @@ -68,12 +68,12 @@ public class NoteList } if(noteExist.v!=0) { - for( ; note.next != null && t == note.next.t ; note = note.next ) + for( ; note.next != null && t == note.next.noteTime ; note = note.next ) ; } else { - for( ; note.prev != null && t == note.t ; note = note.prev ) + for( ; note.prev != null && t == note.noteTime ; note = note.prev ) ; } @@ -96,15 +96,15 @@ public class NoteList /** * - * @param t + * @param noteTime * @param c * @param n * @param v */ public void delOne(int t, byte c, byte n, byte v) { - for(note = searchNoteByTime(t); note != null && note.t <= t; note = note.next) - if(t==note.t && c == note.c && n == note.n && (v!=0 ^ note.v==0)) + for(note = searchNoteByTime(t); note != null && note.noteTime <= t; note = note.next) + if(t==note.noteTime && c == note.c && n == note.n && (v!=0 ^ note.v==0)) { if (note.next != null) note.next.prev = note.prev; @@ -124,7 +124,7 @@ public class NoteList */ public void delOne(Note delNote) { - for(note = getFirst(); note != null && note.t <= t; note = note.next) + for(note = getFirst(); note != null && note.noteTime <= t; note = note.next) if(note == delNote) { if (note.next != null) @@ -157,7 +157,7 @@ public class NoteList if(undo!=null && note.v!=0) { - undo.log2DelNoteList(note.t,note.c,note.n,note.v,note.len); + undo.log2DelNoteList(note.noteTime,note.c,note.n,note.v,note.length); } len--; @@ -165,7 +165,7 @@ public class NoteList } /** * - * @param t + * @param noteTime * @param tMax * @param c * @param n @@ -181,13 +181,13 @@ public class NoteList boolean isdel=false; timeNoteOff = -1; - for(note = searchNoteByTime(t); note != null && note.t <= tMax; note = note.next) + for(note = searchNoteByTime(t); note != null && note.noteTime <= tMax; note = note.next) if ( (note.c == c || c == (byte)-1) && - (note.t > t || v!=0 && note.t == t) && - (note.t < tMax || v==0 && note.t == tMax) && + (note.noteTime > t || v!=0 && note.noteTime == t) && + (note.noteTime < tMax || v==0 && note.noteTime == tMax) && (note.n == n || n == (byte)-1) && - ( (v != 0 && (note.v != 0 || note.t - note.len >= t)) || - (v == 0 && (note.v == 0 && timeLastDelOn <= note.t-note.len && note.t-note.len < t )))) + ( (v != 0 && (note.v != 0 || note.noteTime - note.length >= t)) || + (v == 0 && (note.v == 0 && timeLastDelOn <= note.noteTime-note.length && note.noteTime-note.length < t )))) { if(note.next != null) note.next.prev = note.prev; @@ -199,15 +199,15 @@ public class NoteList len--; if( v != 0) { - if(tOffMax < note.t+note.len) - tOffMax = note.t+note.len; + if(tOffMax < note.noteTime+note.length) + tOffMax = note.noteTime+note.length; if(undo!=null && note.v!=0) { - undo.log2DelNoteList(note.t,note.c,note.n,note.v,note.len); + undo.log2DelNoteList(note.noteTime,note.c,note.n,note.v,note.length); } } if(note.v==0) - timeNoteOff = note.t; + timeNoteOff = note.noteTime; isdel = true; } @@ -242,7 +242,7 @@ public class NoteList } /** * - * @param t + * @param noteTime * @return */ public Note searchNoteByTime(int t) @@ -254,20 +254,20 @@ public class NoteList else return null; } - if(t <= note.t) + if(t <= note.noteTime) { for(noteTmp = note; - noteTmp.prev != null && t <= noteTmp.t; + noteTmp.prev != null && t <= noteTmp.noteTime; noteTmp = noteTmp.prev) ; - if(noteTmp.t= tSrcBeg - || srcNote.v != 0 && srcNote.t + srcNote.len <= tSrcEnd) + srcNote != null && srcNote.noteTime <= tSrcEnd; srcNote = srcNote.next) { + if (srcNote.c == chSrc && (srcNote.v == 0 && srcNote.noteTime - srcNote.length >= tSrcBeg + || srcNote.v != 0 && srcNote.noteTime + srcNote.length <= tSrcEnd) && (srcNote.v != 0 || onlyMarkSrc)) { if (onlyMarkSrc) { srcNote.mark = NOTE_MARKED; } else { t = tDestBeg - + ((srcNote.t - tSrcBeg) * destTicksPer4) / srcTicksPer4; + + ((srcNote.noteTime - tSrcBeg) * destTicksPer4) / srcTicksPer4; n = srcNote.n; - len = (srcNote.len * destTicksPer4) / srcTicksPer4; + len = (srcNote.length * destTicksPer4) / srcTicksPer4; dest.add(new Note(t, chDest, n, srcNote.v, len)); if (len > 0) { @@ -181,8 +181,8 @@ public class NoteListUtils { */ public static void shift(NoteList list, int tBeg, int shiftLen, UndoableAction undo) { Note note = list.searchNoteByTime(0x7fffffff); - for (; note != null && note.t >= tBeg; note = note.prev) { - if (note.v == 0 && note.t - note.len < tBeg) { + for (; note != null && note.noteTime >= tBeg; note = note.prev) { + if (note.v == 0 && note.noteTime - note.length < tBeg) { Note noteTmp; for (noteTmp = note.prev; noteTmp != null && (noteTmp.c != note.c || noteTmp.n != note.n); @@ -191,30 +191,30 @@ public class NoteListUtils { if (noteTmp != null && noteTmp.c == note.c && noteTmp.n == note.n) { if (undo != null) { - undo.log2DelNoteList(noteTmp.t, noteTmp.c, noteTmp.n, noteTmp.v, noteTmp.len); + undo.log2DelNoteList(noteTmp.noteTime, noteTmp.c, noteTmp.n, noteTmp.v, noteTmp.length); } - noteTmp.len = note.t - noteTmp.t + shiftLen; + noteTmp.length = note.noteTime - noteTmp.noteTime + shiftLen; - if (noteTmp.t + noteTmp.len < tBeg) { - noteTmp.len = tBeg - noteTmp.t; + if (noteTmp.noteTime + noteTmp.length < tBeg) { + noteTmp.length = tBeg - noteTmp.noteTime; } - note.len = noteTmp.len; + note.length = noteTmp.length; if (undo != null) { - undo.log2AddNoteList(noteTmp.t, noteTmp.c, noteTmp.n, noteTmp.v, noteTmp.len); + undo.log2AddNoteList(noteTmp.noteTime, noteTmp.c, noteTmp.n, noteTmp.v, noteTmp.length); } } } - note.t += shiftLen; - if (note.t < tBeg) { + note.noteTime += shiftLen; + if (note.noteTime < tBeg) { if (undo != null && note.v != 0) { - undo.log2DelNoteList(note.t - shiftLen, note.c, note.n, note.v, note.len); - undo.log2AddNoteList(tBeg, note.c, note.n, note.v, note.len); + undo.log2DelNoteList(note.noteTime - shiftLen, note.c, note.n, note.v, note.length); + undo.log2AddNoteList(tBeg, note.c, note.n, note.v, note.length); } - note.t = tBeg; + note.noteTime = tBeg; } } if (undo != null) { @@ -286,7 +286,7 @@ public class NoteListUtils { for (Note note = undo.getDeletedList().getFirst(); note != null; note = note.next) { if (note.c == channel && note.v != 0) { - newTime = note.t + shiftTime; + newTime = note.noteTime + shiftTime; if (newTime < 0) { newTime = 0; } @@ -300,13 +300,13 @@ public class NoteListUtils { } newVol = (byte) tmp; - dest.add(new Note(newTime, channel, newN, newVol, note.len)); + dest.add(new Note(newTime, channel, newN, newVol, note.length)); - if (note.len > 0) { - dest.add(new Note(newTime + note.len, channel, newN, (byte) 0, note.len)); + if (note.length > 0) { + dest.add(new Note(newTime + note.length, channel, newN, (byte) 0, note.length)); } if (undo != null && note.v != 0) { - undo.log2AddNoteList(newTime, channel, newN, newVol, note.len); + undo.log2AddNoteList(newTime, channel, newN, newVol, note.length); } } diff --git a/src/midedit/NoteLong.java b/src/midedit/NoteLong.java index 53730db..d6ceb01 100644 --- a/src/midedit/NoteLong.java +++ b/src/midedit/NoteLong.java @@ -1,26 +1,22 @@ package midedit; - - - /** - * + * * @author user */ -public class NoteLong extends Note -{ +public class NoteLong extends Note { + + /** + * + * @param time + * @param data + */ + public NoteLong(int time, byte[] data) { + super(time, (byte) NoteList.CHANNEL_LONG_NOTE, (byte) 0, (byte) 0, 0); + dat = data; + } /** * - * @param t - * @param d */ - public NoteLong(int t,byte[] d) - { - super(t,(byte)NoteList.CHANNEL_LONG_NOTE,(byte)0,(byte)0,0); - dat = d; - } - /** - * - */ - public byte[] dat; + public byte[] dat; } diff --git a/src/midedit/NotesCanvas.java b/src/midedit/NotesCanvas.java index 265f90a..ee17a27 100644 --- a/src/midedit/NotesCanvas.java +++ b/src/midedit/NotesCanvas.java @@ -57,9 +57,9 @@ public class NotesCanvas extends MixerCanvas { protected void paintNote(Graphics g, Note note, int shiftTime, int shiftNote) { int x, h; int dx, t = 1; - x = getXInPixel(note.t + shiftTime); + x = getXInPixel(note.noteTime + shiftTime); h = getLineFromNote(note.n + shiftNote); - dx = (note.len * wOne) / Constants.timeConst; + dx = (note.length * wOne) / Constants.timeConst; if (dx == 0) { dx = 2; } diff --git a/src/midedit/TempoList.java b/src/midedit/TempoList.java index f9cb303..0d22ca9 100644 --- a/src/midedit/TempoList.java +++ b/src/midedit/TempoList.java @@ -66,8 +66,8 @@ public class TempoList extends List implements CommandListener { int tempBPM; int mod = (composition.getTicksPer4() << 2) >> (composition.getDenomE()); tempBPM = Composition.getTempBeatPerMin(tempMsPer4); - return "" + note.t / tick + ":" + (note.t * meterNom / tick) % meterNom + ":" - + note.t % mod + " - " + tempBPM; + return "" + note.noteTime / tick + ":" + (note.noteTime * meterNom / tick) % meterNom + ":" + + note.noteTime % mod + " - " + tempBPM; } @@ -96,7 +96,7 @@ public class TempoList extends List implements CommandListener { int ind; for (ind = 0; ind < tempNotes.size(); ++ind) { note = (NoteLong) tempNotes.elementAt(ind); - if (note.t > time) { + if (note.noteTime > time) { break; } } @@ -145,7 +145,7 @@ public class TempoList extends List implements CommandListener { int mod = (composition.getTicksPer4() << 2) >> (composition.getDenomE()); int tempBPM = Composition.getTempBeatPerMin(tmp); - int time = notelong.t / tick; + int time = notelong.noteTime / tick; editNum = ind; diff --git a/src/midedit/UndoableAction.java b/src/midedit/UndoableAction.java index 1624375..3553ea7 100644 --- a/src/midedit/UndoableAction.java +++ b/src/midedit/UndoableAction.java @@ -120,11 +120,11 @@ public class UndoableAction /** * - * @param t + * @param noteTime * @param ch * @param n * @param v - * @param len + * @param length */ public void log2AddNoteList(int t, byte ch, byte n, byte v,int len) { @@ -132,11 +132,11 @@ public class UndoableAction } /** * - * @param t + * @param noteTime * @param ch * @param n * @param v - * @param len + * @param length */ public void log2DelNoteList(int t, byte ch, byte n, byte v,int len) { @@ -145,7 +145,7 @@ public class UndoableAction /** * * @param timeBeg - * @param len + * @param length * @param ch */ public void logShift(int timeBeg,int len,byte ch) @@ -161,18 +161,18 @@ public class UndoableAction switch(order[i]) { case ADD_NOTE: - composition.getNoteListByChannel(channel).delOne(noteAddDel.t, noteAddDel.c, + composition.getNoteListByChannel(channel).delOne(noteAddDel.noteTime, noteAddDel.c, noteAddDel.n, noteAddDel.v); - if(noteAddDel.len != 0) - composition.getNoteListByChannel(channel).delOne(noteAddDel.t+noteAddDel.len, + if(noteAddDel.length != 0) + composition.getNoteListByChannel(channel).delOne(noteAddDel.noteTime+noteAddDel.length, noteAddDel.c,noteAddDel.n,(byte)0); break; case DEL_NOTE: - composition.getNoteListByChannel(channel).add(new Note(noteAddDel.t,noteAddDel.c, - noteAddDel.n,noteAddDel.v,noteAddDel.len)); - if(noteAddDel.len != 0) - composition.getNoteListByChannel(channel).add(new Note(noteAddDel.t+noteAddDel.len, - noteAddDel.c,noteAddDel.n, (byte)0,noteAddDel.len)); + composition.getNoteListByChannel(channel).add(new Note(noteAddDel.noteTime,noteAddDel.c, + noteAddDel.n,noteAddDel.v,noteAddDel.length)); + if(noteAddDel.length != 0) + composition.getNoteListByChannel(channel).add(new Note(noteAddDel.noteTime+noteAddDel.length, + noteAddDel.c,noteAddDel.n, (byte)0,noteAddDel.length)); break; case DELETE_LIST: Note noteLocal = dellist.getFirst(); @@ -181,9 +181,9 @@ public class UndoableAction list = composition.getNoteListByChannel(channel); for(noteLocal = dellist.getFirst(); noteLocal!=null; noteLocal = noteLocal.next) { - list.add(new Note(noteLocal.t,noteLocal.c,noteLocal.n,noteLocal.v,noteLocal.len)); - if(noteLocal.len != 0) - list.add(new Note(noteLocal.t+noteLocal.len,noteLocal.c,noteLocal.n,(byte)0,noteLocal.len)); + list.add(new Note(noteLocal.noteTime,noteLocal.c,noteLocal.n,noteLocal.v,noteLocal.length)); + if(noteLocal.length != 0) + list.add(new Note(noteLocal.noteTime+noteLocal.length,noteLocal.c,noteLocal.n,(byte)0,noteLocal.length)); } break; case ADD_LIST: @@ -194,9 +194,9 @@ public class UndoableAction list = composition.getNoteListByChannel(channel); for(noteLocal = addlist.getFirst(); noteLocal!=null; noteLocal = noteLocal.next) { - list.delOne(noteLocal.t,noteLocal.c,noteLocal.n,noteLocal.v); - if(noteLocal.len != 0) - list.delOne(noteLocal.t+noteLocal.len,noteLocal.c,noteLocal.n,(byte)0); + list.delOne(noteLocal.noteTime,noteLocal.c,noteLocal.n,noteLocal.v); + if(noteLocal.length != 0) + list.delOne(noteLocal.noteTime+noteLocal.length,noteLocal.c,noteLocal.n,(byte)0); } break; case SHIFT_LIST: diff --git a/src/midedit/VolumeForm.java b/src/midedit/VolumeForm.java index cf1c104..423b2fb 100644 --- a/src/midedit/VolumeForm.java +++ b/src/midedit/VolumeForm.java @@ -4,6 +4,7 @@ package midedit; import midedit.media.Composition; import java.util.*; import javax.microedition.lcdui.*; +import main.L; import main.Main; import main.P; @@ -13,6 +14,7 @@ import main.P; */ public class VolumeForm extends Form implements CommandListener { + private Command playOrig = new Command(L.str[L.playOrigin], Command.ITEM, 1); private Gauge[] volumeGauges; private ChoiceGroup[] soloChecks; private Vector channels = null; @@ -61,7 +63,7 @@ public class VolumeForm extends Form implements CommandListener { this.append(" "); } this.addCommand(CompositionForm.play); - this.addCommand(CompositionForm.playOrig); + this.addCommand(playOrig); this.addCommand(CompositionForm.ok); this.addCommand(P.comCancel); this.setCommandListener(this); @@ -87,7 +89,7 @@ public class VolumeForm extends Form implements CommandListener { } catch (Exception ex) { } - } else if (command == CompositionForm.playOrig) { + } else if (command == playOrig) { restoreVolumesArr(); try { model.playMix(composition, MixerCanvas.xBase * Constants.timeConst); diff --git a/src/midedit/WaitForm.java b/src/midedit/WaitForm.java deleted file mode 100644 index 97a1703..0000000 --- a/src/midedit/WaitForm.java +++ /dev/null @@ -1,88 +0,0 @@ -package midedit; - - - -import javax.microedition.lcdui.*; -import javax.microedition.lcdui.Command; -import javax.microedition.lcdui.Displayable; -import main.P; - - -/** - * - * @author user - */ -public class WaitForm extends Form implements Runnable, CommandListener -{ - private Gauge percentBar; - private Gauge memoryBar; - Runtime r; - int total; - int curPercent; - Waitable activity; - Displayable next; - MixerModel model; - - /** - * - * @param title - * @param act - * @param n - * @param mod - */ - public WaitForm(String title,Waitable act, Displayable n,MixerModel mod) - { - super("MidEdit"); - activity = act; - next = n; - model = mod; - r = Runtime.getRuntime(); - total = (int)r.totalMemory(); - percentBar = new Gauge(title,false,100,0); - memoryBar = new Gauge("Memory",false,100,(total-(int)r.freeMemory())*100/total); - append(percentBar); - append(memoryBar); - this.addCommand(P.comCancel); - this.setCommandListener(this); - } - private void setPercent(int percent) - { - percentBar.setValue(percent); - memoryBar.setValue((total-(int)r.freeMemory())*100/total); - } - /** - * - */ - public void run() - { - try { - Thread.sleep(1000); - curPercent = 0; - while(curPercent<100) - { - setPercent(activity.getCurPercent()); - Thread.sleep(1000); - } - } - catch (Exception ex) { - } - } - /** - * - * @param command - * @param displayable - */ - public void commandAction(Command command, Displayable displayable) - { - cancel(); - model.display.setCurrent(next); - } - /** - * - */ - public void cancel() - { - activity.cancel(); - curPercent = 100; - } -} diff --git a/src/midedit/Waitable.java b/src/midedit/Waitable.java index c32f855..86b71c8 100644 --- a/src/midedit/Waitable.java +++ b/src/midedit/Waitable.java @@ -1,24 +1,24 @@ package midedit; /** - * + * * @author user */ public interface Waitable { /** - * - * @return + * + * @return */ public int getCurPercent(); /** - * + * */ public void cancel(); /** - * + * */ public void reset(); } diff --git a/src/midedit/media/Composition.java b/src/midedit/media/Composition.java index 42f57f9..0591c27 100644 --- a/src/midedit/media/Composition.java +++ b/src/midedit/media/Composition.java @@ -86,16 +86,15 @@ public class Composition { * @return */ public String[] getInstrumentsStrings() { - // String[] allInstrums = Constants.instruments; int size = 0; - for (int i = 0; i < Constants.NCHANNEL; ++i) { + for (int i = 0; i < Constants.NCHANNEL; i++) { if (instruments[i] != NOTHING) { size++; } } String[] ss = new String[size]; int j = 0; - for (int i = 0; i < Constants.NCHANNEL; ++i) { + for (int i = 0; i < Constants.NCHANNEL; i++) { if (instruments[i] != NOTHING) { ss[j++] = Constants.getInstrName(instruments[i] + 1); } @@ -270,8 +269,8 @@ public class Composition { public void addNoteOff(int tt, byte ch, byte nn) { Note noteTmp = tracks[ch].searchBack(ch, nn); if (noteTmp != null) { - noteTmp.len = tt - noteTmp.t; - tracks[ch].add(new Note(tt, ch, nn, (byte) 0, noteTmp.len)); + noteTmp.length = tt - noteTmp.noteTime; + tracks[ch].add(new Note(tt, ch, nn, (byte) 0, noteTmp.length)); } else { tracks[ch].add(new Note(tt, ch, nn, (byte) 0, 0)); } @@ -329,7 +328,7 @@ public class Composition { /** * - * @param t + * @param noteTime * @param ch * @return */ @@ -383,7 +382,7 @@ public class Composition { /** * - * @param t + * @param noteTime */ public void setTicksPer4(int t) { ticksPer4 = t; @@ -441,7 +440,7 @@ public class Composition { if (percent == 0) { timeNew = 0; } else { - timeNew = this.getFirstNote(this.getLastTime() * percent / 100, ch).t; + timeNew = this.getFirstNote(this.getLastTime() * percent / 100, ch).noteTime; MixerCanvas.curX = 0; } MixerCanvas.xBase = (short) (timeNew / Constants.timeConst); @@ -466,7 +465,7 @@ public class Composition { for (int i = 0; i < Constants.NCHANNEL; ++i) { Note noteTimeMax = this.getFirstNote(0x7fffffff, i); if (noteTimeMax != null) { - tCur = noteTimeMax.t + noteTimeMax.len; + tCur = noteTimeMax.noteTime + noteTimeMax.length; if (tCur > tMax) { tMax = tCur; } diff --git a/src/midedit/media/JSR135Player.java b/src/midedit/media/JSR135Player.java index 1d4d86e..9b3268b 100644 --- a/src/midedit/media/JSR135Player.java +++ b/src/midedit/media/JSR135Player.java @@ -5,14 +5,20 @@ import javax.microedition.media.*; import java.io.*; /** - * + * * @author user */ public class JSR135Player extends AbstractPlayer implements PlayerListener { private Player player; - public void playerUpdate(Player player, java.lang.String event, java.lang.Object eventData) { + /** + * + * @param player + * @param event + * @param eventData + */ + public void playerUpdate(Player player, String event, Object eventData) { if (event.equals(STARTED)) { setIsPlaying(true); return; @@ -23,6 +29,11 @@ public class JSR135Player extends AbstractPlayer implements PlayerListener { return; } + /** + * + * @param path + * @throws Exception + */ public void play(String path) throws Exception { if (player != null) { player.close(); @@ -30,23 +41,14 @@ public class JSR135Player extends AbstractPlayer implements PlayerListener { InputStream is = MixerModel.getLocalFile().getInputStreambyURL(path); player = Manager.createPlayer(is, "audio/midi"); player.addPlayerListener(this); + player.realize(); player.start(); } - - protected void stop() throws Exception { - if (player != null) { - player.stop(); - } - } - - public void close() { - if (player != null) { - player.close(); - } - player = null; - - } - + + /** + * + * @param writeTest midi- + */ public void playTest(byte[] writeTest) { ByteArrayInputStream is = new ByteArrayInputStream(writeTest); if (player != null) { @@ -56,11 +58,34 @@ public class JSR135Player extends AbstractPlayer implements PlayerListener { try { player = Manager.createPlayer(is, "audio/midi"); player.addPlayerListener(this); + player.realize(); player.start(); } catch (IOException ex) { - //ex.printStackTrace(); + ex.printStackTrace(); } catch (MediaException ex) { - //ex.printStackTrace(); + ex.printStackTrace(); } } + + /** + * + * @throws Exception + */ + protected void stop() throws Exception { + if (player != null) { + player.stop(); + } + } + + /** + * + */ + public void close() { + if (player != null) { + player.close(); + } + player = null; + System.gc(); + } + } diff --git a/src/midedit/media/PreviewPlayer.java b/src/midedit/media/PreviewPlayer.java index c44728a..83f199a 100644 --- a/src/midedit/media/PreviewPlayer.java +++ b/src/midedit/media/PreviewPlayer.java @@ -13,7 +13,7 @@ public class PreviewPlayer implements PlayerListener { private boolean isPlaying = false; private Player player; - public void playerUpdate(Player player, java.lang.String event, java.lang.Object eventData) { + public void playerUpdate(Player player, String event, Object eventData) { if (event.equals(STARTED)) { isPlaying = true; return; @@ -21,7 +21,6 @@ public class PreviewPlayer implements PlayerListener { if (event.equals(STOPPED) || event.equals(CLOSED) || event.equals(END_OF_MEDIA)) { isPlaying = false; } - return; } public void play(String path) throws Exception { diff --git a/src/ui/FileManager.java b/src/ui/FileManager.java index 0486692..d58ecf2 100644 --- a/src/ui/FileManager.java +++ b/src/ui/FileManager.java @@ -70,6 +70,9 @@ public class FileManager extends Canvas { /** */ private boolean showMenu; + /** */ + private boolean isDelete; + /** * * @param s @@ -87,6 +90,7 @@ public class FileManager extends Canvas { fontCashe = FWCashe.getCache(P.smBold); CursorY = startPrintFile = curFiles = numFiles = 0; showMenu = false; + isDelete = false; loadImages(); // @@ -132,7 +136,7 @@ public class FileManager extends Canvas { if (menu[0].equals(L.str[L.saveInThisFolder])) { // vt.addElement(L.str[L.saveInThisFolder]); - if(!P.isRMSMode) vt.addElement(L.str[L.newFolder]); + if(!P.isRMSMode && (!P.path.equals("/"))) vt.addElement(L.str[L.newFolder]); } else { if (numFiles > 0) { // @@ -254,7 +258,7 @@ public class FileManager extends Canvas { // final String cur = menu[selected]; // - final String fileSelected = data[curFiles]; + final String fileSelected = (numFiles > 0) ? data[curFiles] : ""; curMenu = 0; showMenu = false; @@ -286,7 +290,8 @@ public class FileManager extends Canvas { } } } - else if (cur.equals(L.str[L.delete])) { + else if (cur.equals(L.str[L.ok])) { + System.out.println(fileSelected); if(!fileSelected.endsWith("/")) { String fileToDelete = fileSelected; if(!P.isRMSMode) fileToDelete = pathFile + fileSelected; @@ -297,9 +302,22 @@ public class FileManager extends Canvas { ex.printStackTrace(); } } + isDelete = false; + } + else if (cur.equals(L.str[L.delete])) { + menu = new String[] {L.str[L.cancel], L.str[L.ok]}; + showMenu = true; + isDelete = true; } else if (cur.equals( L.str[L.cancel])) { // + if(isDelete) { + // + isDelete = false; + setMenu(); + return; + } + // P.path = pathFile; if(menu[0].equals(L.str[L.saveInThisFolder])) Main.dsp.setCurrent(previousDisplayable); else Main.dsp.setCurrent(Main.midlet.menu); @@ -425,7 +443,8 @@ public class FileManager extends Canvas { case UP: cursorUp(); break; case FIRE: case RIGHT: - nextDir(data[curFiles]); + if (numFiles > 0) + nextDir(data[curFiles]); break; } switch (i) { diff --git a/src/ui/Menu.java b/src/ui/Menu.java index 9fbb65d..9b07d8f 100644 --- a/src/ui/Menu.java +++ b/src/ui/Menu.java @@ -100,7 +100,7 @@ public class Menu extends Canvas { g.setColor(P.backgrnd); g.fillRect(0, 0, w, h); - String title = "MidEdit. "+Key.Platform; + String title = L.str[L.midedit] + ". "+Key.Platform; UI.drawTitle(g, title); UI.drawSoftBar(g, L.str[L.ok], L.str[L.exit]); diff --git a/src/ui/SettingsForm.java b/src/ui/SettingsForm.java index 668e62e..3830979 100644 --- a/src/ui/SettingsForm.java +++ b/src/ui/SettingsForm.java @@ -80,8 +80,8 @@ public class SettingsForm extends Form implements CommandListener { // Rms.languageApp = langChars[langChoice.getSelectedIndex()]; Rms.languageInstr = langChars[langInstr.getSelectedIndex()]; - L.readLang(Rms.languageApp, true); - L.readLang(Rms.languageInstr, false); + //L.readLang(Rms.languageApp, true); + //L.readLang(Rms.languageInstr, false); Rms.tempDir = tempDirField.getString(); diff --git a/src/ui/UI.java b/src/ui/UI.java index 3604313..65344d2 100644 --- a/src/ui/UI.java +++ b/src/ui/UI.java @@ -57,20 +57,30 @@ public class UI { } /** - * ( ) + * * @param g * @param cur * @param all + * @param str */ - public static void drawStatusBar(Graphics g, int cur, int all) { + public static void drawProgressBar(Graphics g, int cur, int all, String str) { int w = g.getClipWidth(); int h = g.getClipHeight(); - int sw = w / 20; - int sh = h - h / 20; - g.setColor(0x00); - g.drawRect(w - 2 * sw - 1, h/25 - 1, sw + 1, sh + 1); - int curr = (cur * sh) / all; - drawRect(g, P.colup, P.coldn, w - 2 * sw, (h/25 + (sh - curr)), sw, sh - (sh - curr)); + final int w2 = w / 2; + if (all != 0) { + final int barWidth = (cur * w) / all; + final int barY = h / 2 + h / 16; + drawRect(g, P.colup, P.coldn, 0, barY, barWidth, h / 16); + String value = String.valueOf((cur * 100) / all) + "%"; + g.setColor(P.fmtextnc); + g.drawString(value, w2, barY, Graphics.TOP | Graphics.HCENTER); + g.setColor(P.fmtextcur); + g.drawString(value, w2 + 1, barY + 1, Graphics.TOP | Graphics.HCENTER); + } + if (str != null || str.length() != 0) { + g.setColor(P.fmtextcur); + g.drawString(str, w2 + 1, h / 2 + 1, Graphics.BOTTOM | Graphics.HCENTER); + } } /** diff --git a/src/ui/WaitCanvas.java b/src/ui/WaitCanvas.java new file mode 100644 index 0000000..c3bce03 --- /dev/null +++ b/src/ui/WaitCanvas.java @@ -0,0 +1,107 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ +package ui; + +import javax.microedition.lcdui.*; +import main.Key; +import main.L; +import main.P; +import midedit.Waitable; + +/** + * + * @author aNNiMON + */ +public class WaitCanvas extends Canvas implements Runnable { + + /** - */ + private static final int MAX_PERCENT = 100; + + + /** */ + private Runtime runtime; + + /** , */ + private Waitable activity; + + /** , */ + private Displayable nextDisplayable; + + /** */ + private String title; + + /** */ + private int w, h; + + /** */ + private int totalMemory; + /** ( ) */ + private int curPercent; + + + /** + * + * @param title + * @param act + * @param displayable , + */ + public WaitCanvas(String title, Waitable act, Displayable displayable) { + setFullScreenMode(true); + w = getWidth(); + h = getHeight(); + this.title = title; + activity = act; + nextDisplayable = displayable; + runtime = Runtime.getRuntime(); + totalMemory = (int) runtime.totalMemory(); + } + + public void paint(Graphics g) { + g.setColor(P.backgrnd); + g.fillRect(0, 0, w, h); + UI.drawTitle(g, title); + UI.drawSoftBar(g, "", L.str[L.cancel]); + + // + final int memoryPercent = (totalMemory - (int) runtime.freeMemory()) * MAX_PERCENT / totalMemory; + String memory = L.str[L.memory] + " " + String.valueOf(memoryPercent) + "%"; + UI.drawProgressBar(g, curPercent, MAX_PERCENT, memory); + } + + public void run() { + try { + Thread.sleep(500); + curPercent = 0; + while (curPercent < MAX_PERCENT) { + curPercent = activity.getCurPercent(); + repaint(); + Thread.sleep(500); + } + } catch (Exception ex) { + } + } + + /** + * + */ + public void cancel() { + activity.cancel(); + curPercent = MAX_PERCENT; + } + + protected void sizeChanged(int w, int h) { + this.w = getWidth(); + this.h = getHeight(); + super.sizeChanged(w, h); + } + + protected void keyPressed(int key) { + if(key == Key.rightSoftKey) { + cancel(); + main.Main.dsp.setCurrent(nextDisplayable); + } + } + +}